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.

Schema Configuration

The neo4j-graphql-js library would allow a user to configure the GraphQL schema via the makeAugmentedSchema() function.

For example, to exclude all queries and all mutations:

const schema = makeAugmentedSchema({
  typeDefs,
  config: {
    query: false, // exclude all queries
    mutation: false // exclude all mutations
  }
});

Or to exclude queries for a specific type like so:

const schema = makeAugmentedSchema({
  typeDefs,
  config: {
    query: {
      exclude: ["NameOfTypeToExclude"] // exclude query for type NameOfTypeToExclude
    },
    mutation: false // exclude all mutations
  }
});

To achieve the same behaviour with the new @neo4j/graphql library, the GraphQL schema has to be extended instead. Note, no additional configuration or parameters need to be passed to the getSchema() function.

To exclude all mutations for a specific type:

type NameOfType @exclude(operations: [CREATE, UPDATE, DELETE]) {
  name: String
}

Or to exclude all queries and all mutations for a specific type like so:

type NameOfTypeToExclude @exclude {
  name: String
}

For more information regarding the above used @exclude directive, see @exclude.

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.