Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

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

    Matt RossMatt Ross
    neo4jNeo4j
    graphqlGraphQL

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 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.

    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.

    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.

    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.

    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.

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