Basics

Each type in your GraphQL type definitions can be mapped to an entity in your Neo4j database.

Nodes

The most basic mapping is of GraphQL types to Neo4j nodes, where the GraphQL type name maps to the Neo4j node label.

For example, to represent a node with label "Movie" and a single property "title" of type string:

type Movie {
    title: String
}

Relationships

Relationships are represented by marking particular fields with a directive. This directive, @relationship, defines the relationship type in the database, as well as which direction that relationship goes in.

Add a second node type, "Actor", and connect the two together:

type Movie {
    title: String
    actors: [Actor] @relationship(type: "ACTED_IN", direction: IN)
}

type Actor {
    name: String
    movies: [Movie] @relationship(type: "ACTED_IN", direction: OUT)
}

Note there is a directive on each "end" of the relationship in this case, but it is not essential.

Relationship properties

In order to add relationship properties to a relationship, you need to add a new type to your type definitions, but this time it will be of type interface. For example, for your "ACTED_IN" relationship, add a property "roles":

type Movie {
    title: String
    actors: [Actor] @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
}

type Actor {
    name: String
    movies: [Movie] @relationship(type: "ACTED_IN", direction: OUT, properties: "ActedIn")
}

interface ActedIn @relationshipProperties {
    roles: [String]
}

Note that in addition to this new interface type, there is an added a key properties in the existing @relationship directives.