⚠️ This lesson is retired and might contain outdated information.

Build Complex Schema Relationships with the @cypher Directive in neo4j-graphql-js

Matt Ross
InstructorMatt Ross
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 2 years ago

We will use the @cypher directive provided by neo4j-graphql-js to return data about how nodes are related to each other in our schemas without writing custom resolvers.

Instructor: [00:01] Let's make sure that we have some data in our graph that we can work with. By querying our GraphQL API, we can see that there are some data points that can be inferred by the relationships going to and from a node.

[00:13] One such piece of data could be the list of species found on a given planet. The only way we can currently get that information is by going through our list of people and collecting their home world and species name properties.

[00:29] Optimistically, we can update our schema to show a list of species on a planet. Let's take a look at how we can use the Cypher directive provided by Neo4j-graphql-js to make this easy for us.

[00:42] Let's further edit our planet schema and add the @cypher directive along with its statement property, which represents a Cypher statement to run against the database.

[00:52] The this parameter represents the planet node in question. As it happens, this will return one species per person that connects back to the planet. We'll need to only return the distinct species.

[01:07] Now, we'll restart our API and write a query that includes the planet's species property.