Server
Schema Generation
In your server codebase, the process of creating an executable schema has changed. For a simple application, what used to be:
const { makeAugmentedSchema } = require("neo4j-graphql-js");
const typeDefs = require("./type-definitions");
const schema = makeAugmentedSchema({ typeDefs });
Has become:
const { Neo4jGraphQL } = require("@neo4j/graphql");
const typeDefs = require("./type-definitions");
const neo4jGraphQL = new Neo4jGraphQL({ typeDefs });
const schema = await neo4jGraphQL.getSchema();
Additionally, the Neo4jGraphQL
constructor allows you to pass in a driver instance instead of passing one in the context of each request.
Database Configuration
Driver
Once a schema has been generated, it can be passed into a GraphQL server instance with the driver in the context, identical to using the old library. For example, using Apollo Server and using the schema generated above:
const { ApolloServer } = require("apollo-server");
const driver = require("./driver");
const schema = require("./schema");
const server = new ApolloServer({ schema, context: { driver } });
server.listen().then(({ url }) => {
console.log(`@neo4j/graphql API ready at ${url}`);
});
Multiple Databases
Multiple databases were supported in neo4j-graphql-js
by passing a context key neo4jDatabase
with the name of a database, for example for database called "sanmateo":
const { ApolloServer } = require("apollo-server");
const driver = require("./driver");
const schema = require("./schema");
const server = new ApolloServer({ schema, context: { driver, neo4jDatabase: "sanmateo" } });
server.listen().then(({ url }) => {
console.log(`@neo4j/graphql API ready at ${url}`);
});
In @neo4j/graphql
, this has now become:
const { ApolloServer } = require("apollo-server");
const driver = require("./driver");
const schema = require("./schema");
const server = new ApolloServer({ schema, context: { driver, driverConfig: { database: "sanmateo" } } });
server.listen().then(({ url }) => {
console.log(`@neo4j/graphql API ready at ${url}`);
});
Database bookmarks are also supported. See Driver Configuration for more information.
Was this page helpful?