Skip to content

Latest commit

 

History

History
262 lines (212 loc) · 4.36 KB

cypher-directive-tests.adoc

File metadata and controls

262 lines (212 loc) · 4.36 KB

Cypher Directive Test

Schema

type Person {
  id: ID
  name: String @cypher(statement:"RETURN this.name")
  age(mult:Int=13) : [Int] @cypher(statement:"RETURN this.age * mult as age")
  friends: [Person] @cypher(statement:"MATCH (this)-[:KNOWS]-(o) RETURN o")
}
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 LIMIT 1")
}
type Mutation {
  createPerson(name:String): Person @cypher(statement:"CREATE (p:Person) SET p.name = name RETURN p")
}
schema {
  query: Query
  mutation: Mutation
}

Queries

Simple Cypher Directive on Field

GraphQL-Query
{ person { name }}
Cypher Params
{}
Cypher
MATCH (person:Person)
RETURN person { name:apoc.cypher.runFirstColumnSingle('WITH $this AS this RETURN this.name', { this:person }) } AS person

render cypher query directive params args

GraphQL-Query
query($pname:String) { p3(name:$pname) { id }}
Query variables
{"pname":"foo"}
Cypher params
{"pname":"foo"}
Cypher
UNWIND apoc.cypher.runFirstColumnSingle('WITH $name AS name MATCH (p:Person) WHERE p.name = name RETURN p LIMIT 1', { name:$pname }) AS p3 RETURN p3 { .id } AS p3

render cypher field directive with params defaults

GraphQL-Query
{ person { age }}
Query variables
{}
Cypher params
{"personMult":13}
Cypher
MATCH (person:Person) RETURN person { age:apoc.cypher.runFirstColumnMany('WITH $this AS this, $mult AS mult RETURN this.age * mult as age', { this:person, mult:$personMult }) } AS person

render cypher query directive

GraphQL-Query
{ p2 { id }}
Query variables
{}
Cypher params
{}
Cypher
UNWIND apoc.cypher.runFirstColumnMany('MATCH (p:Person) RETURN p', { }) AS p2 RETURN p2 { .id } AS p2

render cypher mutation directive

GraphQL-Query
mutation { person: createPerson(name:"Joe") { id }}
Query variables
{}
Cypher params
{"personName":"Joe"}
Cypher
CALL apoc.cypher.doIt('WITH $name AS name CREATE (p:Person) SET p.name = name RETURN p', { name:$personName }) YIELD value WITH value[head(keys(value))] AS person RETURN person { .id } AS person

render cypher field directive with params

GraphQL-Query
{ person { age(mult:25) }}
Query variables
{}
Cypher params
{"personMult":25}
Cypher
MATCH (person:Person) RETURN person { age:apoc.cypher.runFirstColumnMany('WITH $this AS this, $mult AS mult RETURN this.age * mult as age', { this:person, mult:$personMult }) } AS person

render cypher field directive nested

GraphQL-Query
{ person { friends { id } }}
Query variables
{}
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person { friends:[personFriends IN
  apoc.cypher.runFirstColumnMany('WITH $this AS this  MATCH (this)-[:KNOWS]-(o) RETURN o', { this:person }) | personFriends { .id }] } AS person

render cypher query directive params

GraphQL-Query
{ p3(name:"Jane") { id }}
Query variables
{}
Cypher params
{"p3Name":"Jane"}
Cypher
UNWIND apoc.cypher.runFirstColumnSingle('WITH $name AS name MATCH (p:Person) WHERE p.name = name RETURN p LIMIT 1', { name:$p3Name }) AS p3 RETURN p3 { .id } AS p3

render cypher field directive scalar

GraphQL-Query
{ person { name }}
Query variables
{}
Cypher params
{}
Cypher
MATCH (person:Person) RETURN person { name:apoc.cypher.runFirstColumnSingle('WITH $this AS this RETURN this.name', { this:person }) } AS person