Neo4j GraphQL Server
A quick way to get started using neo4j-graphql-binding with Apollo Server.
Installation
Strategy
This package uses neo4j-graphql-binding with Apollo Server to make it easier to get started using a generated API or setting up multiple bindings.
The following describes the server setup process based on the default configuration:
neo4jIDL is called to update your Neo4j-GraphQL schema.
neo4jAssertConstraints is used to support a
@unique
directive by creating constraints in your Neo4j instance. It uses the APOC extension.buildNeo4jTypeDefs then augments the same typeDefs provided to your Neo4j-GraphQL schema.
neo4jGraphQLBinding is used to create a custom GraphQL Binding over the resulting augmented typeDefs. The binding is added into your server's context parameter (default key: 'neo4j' so you can access it the way you normally would access a GraphQL Binding.
buildNeo4jResolvers then generates any unprovided resolvers for query and mutation types that were generated or that use a @cypher directive. Each resolver uses a created binding to delegate all such queries and mutations to a Neo4j-GraphQL endpoint.
Finally, steps 1-5 are processed for any additional binding configurations provided in
bindings
and the resultingtypeDefs
andresolvers
are merged and provided to Apollo Server.
Quick Start
This example server setup uses only auto-generated query and mutation types.
typeDefs
Server
If you navigate to http://localhost:4000/, you should see GraphQL Playground.
Nested Mutation
This example uses nested create and connect mutations and takes advantage of the @unique directive to create the above graph with three Technology nodes.
Request
Response
Query
Now we can run the following query:
Request
Response
More Examples
Using @cypher Directives
The below typeDefs
shows the use of the @cypher
directive for a computed field, a query, and a mutation type. Any query
and mutation
types, or resolvers
, that you provide are not overwritten by the schema augmenting process.
typeDefs
The corresponding resolvers
can be provided if you want to handle the data or be explicit. Otherwise, they will be generated.
Using Multiple Bindings
See the section on using the GraphQL Community Graph for an example of configuring bindings for multiple local or remote Neo4j instances with the Neo4j-GraphQL extension available.
Prism Graph
This mutation creates a Prism Graph! 🌈
API Reference
All the same arguments as Apollo Server are supported, in addition to the following:
typeDefs
(required): Your GraphQL type definitions in SDL formatdriver
(required): Your Neo4j driver instance (More info here).calls
Configures the use ofneo4jAssertConstraints
andneo4jIDL
during setup.assert
(default:true
): A boolean control that updates the unique property constraints in your Neo4j instance.idl
(default:true
): A boolean control that updates your Neo4j-GraphQL schema.
augment
Configures the use ofbuildNeo4jTypeDefs
andbuildNeo4jResolvers
during setup.typeDefs
query
(default:true
) A boolean controlling the generation of query types.mutation
(default:true
) A boolean controlling the generation of mutation types.
resolvers
query
(default:true
) A boolean controlling the generation of resolvers for query types.mutation
(default:true
) A boolean controlling the generation of resolvers for mutation types.
indexConfig
Configures the management of generatedid
fields.use
(default/only:'cuid'
) Configures what method to use when generating id field values.
bindingKey
(default:'neo4j'
): The key used when storing the created binding into the server's context object.log
(default:false
): Logs the result of any delegated query or mutation operation,buildNeo4jTypeDefs
,neo4jAssertConstraints
, andneo4jIDL
.readOnly
(default: false): If you only have read access to a remote server, then you can use this parameter to turn off all processes that assume write access. Mutation types are not generated,idl
andassert
calls are prevented, andid
fields are not generated and managed because we would never be able to write them to the instance. So, this results in forcing the following configuration:
bindings
An object of bindings where each key is the name for a binding and each value is a configuration object containing the parameters:typeDefs
,resolvers
,driver
,calls
,augment,
log
, andreadOnly
. This can be used to network together a GraphQL binding for multiple remote Neo4j instances with the Neo4j-GraphQL extension installed.
Default Configuration
Last updated