Introduction
This is the documentation of the GraphQL Library version 7. For the long-term support (LTS) version 5, refer to GraphQL Library version 5 LTS. |
The Neo4j GraphQL Library is a highly flexible, low-code, open source JavaScript library that enables rapid API development for cross-platform and mobile applications by tapping into the power of connected data.
How it works
The Neo4j GraphQL Library requires a set of type definitions that describes the shape of your graph data and creates an API layer to communicate with the data.
It generates an entire executable schema with all additional types needed to execute queries and mutations to interact with your Neo4j database.
For example, consider these type definitions:
type Product @node {
productName: String
category: [Category!]! @relationship(type: "PART_OF", direction: OUT)
}
type Category @node {
categoryName: String
products: [Product!]! @relationship(type: "PART_OF", direction: IN)
}
Based on these type definitions, the library generates query and mutation templates to create new instances of the types as well as query existing instances.
The following mutation creates a new product as well as a new category:
mutation {
createProducts(
input: [
{
productName: "New Product"
category: { create: [{ node: { categoryName: "New Category" } }] }
}
]
) {
products {
productName
category {
categoryName
}
}
}
}
Here is an example of how you can query existing data:
query {
products {
productName
category {
categoryName
}
}
}
The response looks like this:
{
"data": {
"products": [
{
"productName": "New Product",
"category": [
{
"categoryName": "New Category"
}
]
}
]
}
}
For every query and mutation that is executed against this generated schema, the Neo4j GraphQL Library generates a single Cypher query which is executed against the database. This eliminates the N+1 Problem, which can make GraphQL implementations slow and inefficient.
See Integrating the library to learn how to use the GraphQL Library in your technology stack. Check out Creating a new project to create a new project, either based on Neo4j Aura or self-hosted.
Library features
-
Automatic generation of Queries and Mutations for CRUD interactions.
-
Types, including temporal and spatial.
-
Support for both node and relationship properties.
-
Extensive Filtering, Sorting and Pagination options.
-
Security options and additional Schema Configuration.
-
Subscriptions to server events.
-
Extensibility through the
@cypher
directive and/or Custom Resolvers. -
A Toolbox (UI) to experiment with your Neo4j GraphQL API on Neo4j Desktop.
License
Documentation license: Creative Commons 4.0
Source: Apache 2.0
Get hands-on with the GraphQL course on GraphAcademy.