Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Create typedefs automatically by inferring GraphQL Schema from Neo4j #223

Merged
merged 33 commits into from
Apr 29, 2019
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a10a7f4
inferSchema
moxious Mar 29, 2019
f64103e
big refactor
moxious Mar 29, 2019
f7678e1
first working version
moxious Mar 29, 2019
261fa04
add auto-generated example server
moxious Mar 29, 2019
160d81f
bugfix
moxious Mar 29, 2019
84c8a77
set property update
moxious Mar 29, 2019
00dda1a
refactor server
moxious Mar 29, 2019
daa7dc1
fix bug
moxious Mar 29, 2019
af1d499
will feedback
moxious Mar 29, 2019
f6e3e45
tests for schema entities
moxious Mar 30, 2019
8e14ce6
driver fakes and schema tree tests
moxious Mar 30, 2019
05948a4
graphQLMapper basic test
moxious Mar 30, 2019
f733d7e
always report coverage when running tests
moxious Mar 31, 2019
63eaa76
improved test
moxious Mar 31, 2019
a393255
greatly expanded/improved autogen type mapping
moxious Apr 6, 2019
32167e2
getNodesByLabel in schema tree
moxious Apr 6, 2019
123aef9
multivalent/univalent tests
moxious Apr 6, 2019
73399ca
simplify schema autogeneration
moxious Apr 6, 2019
3c7b8ea
handle univalent rel mapping, and naming conflicts on rels
moxious Apr 6, 2019
3c5fa68
isUnivalent()
moxious Apr 6, 2019
90b15e8
TODOs and small type modification
moxious Apr 13, 2019
c56100f
generate _id properties on all nodes to permit propertyless labels
moxious Apr 24, 2019
408a091
cleanup
moxious Apr 24, 2019
3c0679b
docs
moxious Apr 24, 2019
a4a2144
provide for options passed to schema inference
moxious Apr 24, 2019
df37393
support config.alwaysIncludeRelationships
moxious Apr 24, 2019
2f82e81
greatly improve mapper tests
moxious Apr 24, 2019
2221965
merge upstream/master
moxious Apr 24, 2019
f0cf66c
fixed type mapping bug dealing with domination relationships
moxious Apr 26, 2019
4152b44
PR feedback: map Integer->Int, IntegerArray->[Int]
moxious Apr 27, 2019
786cb0a
PR feedback: disable always including relationships
moxious Apr 27, 2019
66062e3
permit inbound/outbound detection to work with label sets
moxious Apr 29, 2019
ab08904
PR feedback/fix bug on rel generation from multi-labeled node sets
moxious Apr 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions example/apollo-server/movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { augmentTypeDefs, augmentSchema } from '../../src/index';
import { ApolloServer, gql, makeExecutableSchema } from 'apollo-server';
import { v1 as neo4j } from 'neo4j-driver';
import { typeDefs, resolvers } from './movies-schema';
import { inferSchema } from '../../src/inferSchema';

const schema = makeExecutableSchema({
typeDefs: augmentTypeDefs(typeDefs),
Expand All @@ -22,6 +23,12 @@ const driver = neo4j.driver(
)
);

inferSchema(driver)
.then(result => {
console.log(result);
})
.catch(err => console.error(err));

const server = new ApolloServer({
schema: augmentedSchema,
// inject the request object into the context to support middleware
Expand Down
50 changes: 50 additions & 0 deletions example/autogenerated/autogen-middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { makeAugmentedSchema } from '../../src/index';
import { ApolloServer } from 'apollo-server-express';
import express from 'express';
import bodyParser from 'body-parser';
import { v1 as neo4j } from 'neo4j-driver';
import { typeDefs, resolvers } from './movies-schema';

const schema = makeAugmentedSchema({
typeDefs,
resolvers,
resolverValidationOptions: {
requireResolversForResolveType: false
}
});

// Add auto-generated mutations
//const augmentedSchema = augmentSchema(schema);

const driver = neo4j.driver(
process.env.NEO4J_URI || 'bolt://localhost:7687',
neo4j.auth.basic(
process.env.NEO4J_USER || 'neo4j',
process.env.NEO4J_PASSWORD || 'letmein'
)
);

const app = express();
app.use(bodyParser.json());

const checkErrorHeaderMiddleware = async (req, res, next) => {
req.error = req.headers['x-error'];
next();
};

app.use('*', checkErrorHeaderMiddleware);

const server = new ApolloServer({
schema,
// inject the request object into the context to support middleware
// inject the Neo4j driver instance to handle database call
context: ({ req }) => {
return {
driver,
req
};
}
});

server.applyMiddleware({ app, path: '/' });
app.listen(3000, '0.0.0.0');
50 changes: 50 additions & 0 deletions example/autogenerated/autogen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { makeAugmentedSchema } from '../../src/index';
import { ApolloServer } from 'apollo-server';
import { v1 as neo4j } from 'neo4j-driver';
import { inferSchema } from '../../src/inferSchema';

const driver = neo4j.driver(
process.env.NEO4J_URI || 'bolt://localhost:7687',
neo4j.auth.basic(
process.env.NEO4J_USER || 'neo4j',
process.env.NEO4J_PASSWORD || 'letmein'
)
);

const schemaInferenceOptions = {
alwaysIncludeRelationships: true
};

const inferAugmentedSchema = driver => {
return inferSchema(driver, schemaInferenceOptions).then(result => {
console.log('TYPEDEFS:');
console.log(result.typeDefs);

return makeAugmentedSchema({
typeDefs: result.typeDefs
});
});
};

const createServer = augmentedSchema =>
new ApolloServer({
schema: augmentedSchema,
// inject the request object into the context to support middleware
// inject the Neo4j driver instance to handle database call
context: ({ req }) => {
return {
driver,
req
};
}
});

const port = process.env.GRAPHQL_LISTEN_PORT || 3000;

inferAugmentedSchema(driver)
.then(createServer)
.then(server => server.listen(port, '0.0.0.0'))
.then(({ url }) => {
console.log(`GraphQL API ready at ${url}`);
})
.catch(err => console.error(err));
Loading