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

Matt Ross
InstructorMatt Ross

Share this video with your friends

Send Tweet
Published 3 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.

Vijay
Vijay
~ 3 years ago

Hello Matt,

Thanks for the great course.

I've been working on JanusGraph which uses the TinkerPop API for handling graph queries. I really liked the idea of GraphQL because of the convenience it offers it mutating data models. To achieve a similar behavior, I had to write my own functions that would mutate the graph result and then create an JSON data object (as an intermediate step) before serving it to the front-end.

After viewing the course, I noticed how easy it would become if the Graph Db Engine could generate the mutations for us. Do you have any idea about any GraphQL drivers that can be integrated with Databases such as JanusGraph to achieve a similar result ?

Thanks Vijay

cognivore
cognivore
~ 2 months ago

Hi, Matt!

I wonder how does one typecheck GraphQL schemas to make typesafe APIs?