Adding Relationships

Your challenge is to update the GraphQL type definitions from the previous lesson to include the RATED relationship between the User and Movie types.

The RATED relationship includes a rating property, of type float, that holds the user’s rating for the movie.

Run this query in the Neo4j Sandbox to explore the RATED relationship between the User and Movie nodes:

cypher
MATCH (u:User)-[r:RATED]->(m:Movie{title: "Matrix, The"}) RETURN u,r,m
  1. Update the type definitions to create a new Rated type which specifies rating property with an appropriate type.

    GraphQL
    type Rated @relationshipProperties {
      ...
    }
  2. Add the RATED relationship to the User type definition

    GraphQL
    type User @node {
      userId: ID!
      name: String!
      ...
    }
  3. Construct a GraphQL query that uses the RATED relationship to return all the ratings for the user "Gloria Nelson".

Click here to reveal the new type definitions
GraphQL
type Rated @relationshipProperties {
  rating: Float
}

type User @node {
  userId: ID!
  name: String!
  rated: [Movie!]! @relationship(type: "RATED", properties: "Rated", direction: OUT)
}
Click here to reveal the GraphQL query
GraphQL
query MyQuery {
  users(where: {name_EQ: "Gloria Nelson"}) {
    name
    ratedConnection {
      edges {
        properties {
          rating
        }
        node {
          title
        }
      }
    }
  }
}

Summary

In this challenge, you created a new relationship between the User and Movie types and specified a relationship property.

In the next module, you will learn how to create, update, and delete data using GraphQL mutations.