Table of Contents
- Schema
- Queries
- Simple Cypher Directive on Field
- render cypher query directive params args
- render cypher field directive with params defaults
- render cypher query directive
- render cypher mutation directive
- render cypher field directive with params
- render cypher field directive nested
- render cypher query directive params
- render cypher field directive scalar
- pass through directives' result in query
- pass through directives result in field
type Person {
id: ID
name: String @cypher(statement:"RETURN this.name")
age(mult:Int=13) : [Int] @cypher(statement:"RETURN this.age * mult")
friends: [Person] @cypher(statement:"MATCH (this)-[:KNOWS]-(o) RETURN o")
data: UserData @cypher(statement: "MATCH (this)-[:CREATED_MAP]->(m:Map) WITH collect({id: m.id, name: m.name}) AS mapsCreated, this RETURN {firstName: this.firstName, lastName: this.lastName, organization: this.organization, mapsCreated: mapsCreated}", passThrough:true)
}
type Query {
person : [Person]
p2: [Person] @cypher(statement:"MATCH (p:Person) RETURN p")
p3(name:String): Person @cypher(statement:"MATCH (p:Person) WHERE p.name = name RETURN p")
getUser(userId: ID): UserData @cypher(statement: "MATCH (u:User{id: {userId}})-[:CREATED_MAP]->(m:Map) WITH collect({id: m.id, name: m.name}) AS mapsCreated, u RETURN {firstName: u.firstName, lastName: u.lastName, organization: u.organization, mapsCreated: mapsCreated}", passThrough:true)
}
type Mutation {
createPerson(name:String): Person @cypher(statement:"CREATE (p:Person) SET p.name = name RETURN p")
}
type UserData {
firstName: String
lastName: String
organization: String
mapsCreated: [MapsCreated]
}
type MapsCreated {
id: String
name: String
}
schema {
query: Query
mutation: Mutation
}
GraphQL-Query
{ person { name }}
Cypher Params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
WITH person AS this
RETURN this.name AS personName LIMIT 1
}
RETURN person {
name: personName
} AS person
GraphQL-Query
query($pname:String) { p3(name:$pname) { id }}
Query variables
{"pname":"foo"}
Cypher params
{
"p3Name" : "foo"
}
Cypher
CALL {
WITH $p3Name AS name
MATCH (p:Person) WHERE p.name = name RETURN p AS p3 LIMIT 1
}
RETURN p3 {
.id
} AS p3
GraphQL-Query
{ person { age }}
Query variables
{}
Cypher params
{
"personAgeMult" : 13
}
Cypher
MATCH (person:Person)
CALL {
WITH person
CALL {
WITH person
WITH $personAgeMult AS mult, person AS this
RETURN this.age * mult AS personAge
}
RETURN collect(personAge) AS personAge
}
RETURN person {
age: personAge
} AS person
GraphQL-Query
{ p2 { id }}
Query variables
{}
Cypher params
{}
Cypher
CALL {
MATCH (p:Person) RETURN p AS p2
}
RETURN p2 {
.id
} AS p2
GraphQL-Query
mutation { person: createPerson(name:"Joe") { id }}
Query variables
{}
Cypher params
{
"personName" : "Joe"
}
Cypher
CALL {
WITH $personName AS name
CREATE (p:Person) SET p.name = name RETURN p AS person LIMIT 1
}
RETURN person {
.id
} AS person
GraphQL-Query
{ person { age(mult:25) }}
Query variables
{}
Cypher params
{
"personAgeMult" : 25
}
Cypher
MATCH (person:Person)
CALL {
WITH person
CALL {
WITH person
WITH $personAgeMult AS mult, person AS this
RETURN this.age * mult AS personAge
}
RETURN collect(personAge) AS personAge
}
RETURN person {
age: personAge
} AS person
GraphQL-Query
{ person { friends { id } }}
Query variables
{}
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
CALL {
WITH person
WITH person AS this
MATCH (this)-[:KNOWS]-(o) RETURN o AS personFriends
}
RETURN collect(personFriends {
.id
}) AS personFriends
}
RETURN person {
friends: personFriends
} AS person
GraphQL-Query
{ p3(name:"Jane") { id }}
Query variables
{}
Cypher params
{
"p3Name" : "Jane"
}
Cypher
CALL {
WITH $p3Name AS name
MATCH (p:Person) WHERE p.name = name RETURN p AS p3 LIMIT 1
}
RETURN p3 {
.id
} AS p3
GraphQL-Query
{ person { name }}
Query variables
{}
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
WITH person AS this
RETURN this.name AS personName LIMIT 1
}
RETURN person {
name: personName
} AS person
GraphQL-Query
query queriesRootQuery {
user: getUser(userId: "123") {
firstName lastName organization
mapsCreated { id }
}
}
Query variables
{}
Cypher params
{
"userUserId" : "123"
}
Cypher
CALL {
WITH $userUserId AS userId
MATCH (u:User{id: {userId}})-[:CREATED_MAP]->(m:Map) WITH collect({id: m.id, name: m.name}) AS mapsCreated, u RETURN {firstName: u.firstName, lastName: u.lastName, organization: u.organization, mapsCreated: mapsCreated} AS user LIMIT 1
}
RETURN user AS user
GraphQL-Query
query queriesRootQuery {
person { id, data { firstName } }
}
Query variables
{}
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
WITH person AS this
MATCH (this)-[:CREATED_MAP]->(m:Map) WITH collect({id: m.id, name: m.name}) AS mapsCreated, this RETURN {firstName: this.firstName, lastName: this.lastName, organization: this.organization, mapsCreated: mapsCreated} AS personData LIMIT 1
}
RETURN person {
.id,
data: personData
} AS person