Table of Contents
- Setup
- Tests
- order by query single
- rich relationship
- nested query multi
- inline fragment
- simple query offset
- query offset as variable
- nested query
- simple query
- named fragment
- rich relationship custom field names
- rich relationship 2nd hop
- rich relationship 3 rd hop
- nested query parameter
- order by query two
- order by with underscore
- named fragment multi field
- simple query alias
- simple query first
- simple query where
- nested query slice offset
- nested query slice first
- nested query 2 nd hop
- inline fragment multi fields
- simple query first offset
- nested query slice first offset
- nested query slice first offset
- introspection
- inline fragments on interfaces
- fragments on interfaces
- query spatial types
- mutate spatial types
- enforce typeName on interfaces
Schema
type Person {
name: String
age: Int
livesIn : Location @relation(name:"LIVES_IN", direction: OUT)
livedIn : [Location] @relation(name:"LIVED_IN", direction: OUT)
born : Birth
died : Death
location: _Neo4jPoint
}
interface Temporal {
date: String
}
type Birth implements Temporal @relation(name:"BORN") {
from: Person
to: Location
date: String
}
type Death implements Temporal @relation(name:"DIED",from:"who",to:"where") {
who: Person
where: Location
date: String
}
interface Location {
name: String
founded: Person @relation(name:"FOUNDED", direction: IN)
sort_Arg: String
}
type City implements Location {
name: String
founded: Person @relation(name:"FOUNDED", direction: IN)
sort_Arg: String
city_Arg: String
}
type Village implements Location {
name: String
founded: Person @relation(name:"FOUNDED", direction: IN)
sort_Arg: String
villageArg: String
}
# enum _PersonOrdering { name_asc, name_desc, age_asc, age_desc }
enum E { pi, e }
type Query {
person : [Person]
personByName(name:String) : Person
}
GraphQL-Query
{ person:person(orderBy:[name_asc]) { age } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person ORDER BY person.name ASC
GraphQL-Query
{ person { name born { date to { name } } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[personBorn:BORN]->(personBornTo:Location)
RETURN personBorn {
.date,
to: personBornTo {
.name
}
} AS personBorn LIMIT 1
}
RETURN person {
.name,
born: personBorn
} AS person
GraphQL-Query
{ person { name age livedIn { name } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[:LIVED_IN]->(personLivedIn:Location)
RETURN collect(personLivedIn {
.name
}) AS personLivedIn
}
RETURN person {
.name,
.age,
livedIn: personLivedIn
} AS person
GraphQL-Query
query { person { ... on Person { name } } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.name
} AS person
GraphQL-Query
{ person:person(offset:3) { age } }
Cypher params
{
"personOffset" : 3
}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person SKIP $personOffset
GraphQL-Query
query getPersons($offset: Int){
person(offset: $offset) {
age
}
}
Query variables
{
"offset": 10
}
Cypher params
{
"personOffset" : 10
}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person SKIP $personOffset
GraphQL-Query
{ person { name age livesIn { name } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[:LIVES_IN]->(personLivesIn:Location)
RETURN personLivesIn {
.name
} AS personLivesIn LIMIT 1
}
RETURN person {
.name,
.age,
livesIn: personLivesIn
} AS person
GraphQL-Query
{ person { name age } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.name,
.age
} AS person
GraphQL-Query
query { person { ...name } } fragment name on Person { name }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.name
} AS person
GraphQL-Query
{ person { name died { date where { name } } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[personDied:DIED]->(personDiedWhere:Location)
RETURN personDied {
.date,
where: personDiedWhere {
.name
}
} AS personDied LIMIT 1
}
RETURN person {
.name,
died: personDied
} AS person
GraphQL-Query
{ person { name born { date to { name founded { name } } } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[personBorn:BORN]->(personBornTo:Location)
CALL {
WITH personBornTo
OPTIONAL MATCH (personBornTo)<-[:FOUNDED]-(personBornToFounded:Person)
RETURN personBornToFounded {
.name
} AS personBornToFounded LIMIT 1
}
RETURN personBorn {
.date,
to: personBornTo {
.name,
founded: personBornToFounded
}
} AS personBorn LIMIT 1
}
RETURN person {
.name,
born: personBorn
} AS person
GraphQL-Query
{ person { name born { date to { name founded { name born { date to { name } } } } } } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[personBorn:BORN]->(personBornTo:Location)
CALL {
WITH personBornTo
OPTIONAL MATCH (personBornTo)<-[:FOUNDED]-(personBornToFounded:Person)
CALL {
WITH personBornToFounded
OPTIONAL MATCH (personBornToFounded)-[personBornToFoundedBorn:BORN]->(personBornToFoundedBornTo:Location)
RETURN personBornToFoundedBorn {
.date,
to: personBornToFoundedBornTo {
.name
}
} AS personBornToFoundedBorn LIMIT 1
}
RETURN personBornToFounded {
.name,
born: personBornToFoundedBorn
} AS personBornToFounded LIMIT 1
}
RETURN personBorn {
.date,
to: personBornTo {
.name,
founded: personBornToFounded
}
} AS personBorn LIMIT 1
}
RETURN person {
.name,
born: personBorn
} AS person
GraphQL-Query
{ person { name age livedIn(name:"Berlin") { name } } }
Cypher params
{
"personLivedInName" : "Berlin"
}
Cypher
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[:LIVED_IN]->(personLivedIn:Location)
WHERE personLivedIn.name = $personLivedInName
RETURN collect(personLivedIn {
.name
}) AS personLivedIn
}
RETURN person {
.name,
.age,
livedIn: personLivedIn
} AS person
GraphQL-Query
{ person:person(orderBy:[age_desc, name_asc]) { age } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person ORDER BY person.age DESC, person.name ASC
GraphQL-Query
{ location(orderBy:[sort_Arg_desc]) { name } }
Cypher params
{}
Cypher
MATCH (location:Location)
RETURN location {
.name
} AS location ORDER BY location.sort_Arg DESC
GraphQL-Query
fragment details on Person { name, age } query { person { ...details } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.name,
.age
} AS person
GraphQL-Query
{ foo:person {
n:name
}
}
Cypher params
{}
Cypher
MATCH (foo:Person)
RETURN foo {
n: foo.name
} AS foo
GraphQL-Query
{ person:person(first:2) { age } }
Cypher params
{
"personFirst" : 2
}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person LIMIT $personFirst
GraphQL-Query
{ person:personByName(name:"Joe") { age } }
Cypher params
{
"personName" : "Joe"
}
Cypher
MATCH (person:Person)
WHERE person.name = $personName
RETURN person {
.age
} AS person LIMIT 1
GraphQL-Query
{ person { livedIn(offset:3) { name } } }
Cypher params
{
"personLivedInOffset" : 3
}
Cypher
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[:LIVED_IN]->(personLivedIn:Location)
WITH personLivedIn SKIP $personLivedInOffset
RETURN collect(personLivedIn {
.name
}) AS personLivedIn
}
RETURN person {
livedIn: personLivedIn
} AS person
GraphQL-Query
{ person { livedIn(first:2) { name } } }
Cypher params
{
"personLivedInFirst" : 2
}
Cypher
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[:LIVED_IN]->(personLivedIn:Location)
WITH personLivedIn LIMIT $personLivedInFirst
RETURN collect(personLivedIn {
.name
}) AS personLivedIn
}
RETURN person {
livedIn: personLivedIn
} AS person
GraphQL-Query
{ person { name age livesIn { name founded {name}} } }
Cypher params
{}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[:LIVES_IN]->(personLivesIn:Location)
CALL {
WITH personLivesIn
OPTIONAL MATCH (personLivesIn)<-[:FOUNDED]-(personLivesInFounded:Person)
RETURN personLivesInFounded {
.name
} AS personLivesInFounded LIMIT 1
}
RETURN personLivesIn {
.name,
founded: personLivesInFounded
} AS personLivesIn LIMIT 1
}
RETURN person {
.name,
.age,
livesIn: personLivesIn
} AS person
GraphQL-Query
query { person { ... on Person { name,age } } }
Cypher params
{}
Cypher
MATCH (person:Person)
RETURN person {
.name,
.age
} AS person
GraphQL-Query
{ person:person(first:2,offset:3) { age } }
Cypher params
{
"personFirst" : 2,
"personOffset" : 3
}
Cypher
MATCH (person:Person)
RETURN person {
.age
} AS person SKIP $personOffset LIMIT $personFirst
GraphQL-Query
{ person { livedIn(first:2,offset:3) { name } } }
Cypher params
{
"personLivedInFirst" : 2,
"personLivedInOffset" : 3
}
Cypher
MATCH (person:Person)
CALL {
WITH person
MATCH (person)-[:LIVED_IN]->(personLivedIn:Location)
WITH personLivedIn SKIP $personLivedInOffset LIMIT $personLivedInFirst
RETURN collect(personLivedIn {
.name
}) AS personLivedIn
}
RETURN person {
livedIn: personLivedIn
} AS person
GraphQL-Query
{ location { name __typename } }
Cypher params
{
"locationValidTypes" : [ "City", "Village" ]
}
Cypher
MATCH (location:Location)
RETURN location {
.name,
__typename: head([label IN labels(location) WHERE label IN $locationValidTypes])
} AS location
GraphQL-Query
{
person {
name
__typename
born {
__typename
}
}
}
Cypher params
{
"personValidTypes" : [ "Person" ]
}
Cypher
MATCH (person:Person)
CALL {
WITH person
OPTIONAL MATCH (person)-[personBorn:BORN]->(personBornTo:Location)
RETURN personBorn {
__typename: 'Birth'
} AS personBorn LIMIT 1
}
RETURN person {
.name,
__typename: head([label IN labels(person) WHERE label IN $personValidTypes]),
born: personBorn
} AS person
GraphQL-Query
{
location {
name
__typename
... on City {
city_Arg
}
... on Village {
villageArg
}
}
}
Cypher params
{
"locationValidTypes" : [ "City", "Village" ]
}
Cypher
MATCH (location:Location)
RETURN location {
.name,
__typename: head([label IN labels(location) WHERE label IN $locationValidTypes]),
.city_Arg,
.villageArg
} AS location
GraphQL-Query
query {
location {
...details
}
}
fragment details on Location {
name
__typename
... on City {
city_Arg
}
... on Village {
villageArg
}
}
Cypher params
{
"locationValidTypes" : [ "City", "Village" ]
}
Cypher
MATCH (location:Location)
RETURN location {
.name,
__typename: head([label IN labels(location) WHERE label IN $locationValidTypes]),
.city_Arg,
.villageArg
} AS location
GraphQL-Query
query {
person(location:{longitude: 1, latitude: 2 }){
name
location {
crs
longitude
latitude
height
}
}
}
Cypher params
{
"personLocationAnd1Longitude" : 1.0,
"personLocationAnd2Latitude" : 2.0
}
Cypher
MATCH (person:Person)
WHERE (person.location.longitude = $personLocationAnd1Longitude
AND person.location.latitude = $personLocationAnd2Latitude)
RETURN person {
.name,
location: {
crs: person.location.crs,
longitude: person.location.longitude,
latitude: person.location.latitude,
height: person.location.height
}
} AS person
GraphQL-Query
mutation{
createPerson(name:"Test2", location:{x: 1, y: 2, z: 3, crs: "wgs-84-3d"}){
name
location{
crs
srid
latitude
longitude
height
}
}
}
Cypher params
{
"createPersonLocation" : {
"x" : 1.0,
"y" : 2.0,
"z" : 3.0,
"crs" : "wgs-84-3d"
},
"createPersonName" : "Test2"
}
Cypher
CREATE (createPerson:Person {
name: $createPersonName,
location: point($createPersonLocation)
})
WITH createPerson
RETURN createPerson {
.name,
location: {
crs: createPerson.location.crs,
srid: createPerson.location.srid,
latitude: createPerson.location.latitude,
longitude: createPerson.location.longitude,
height: createPerson.location.height
}
} AS createPerson
Query configuration
{ "queryTypeOfInterfaces": true }
GraphQL-Query
{
location {
name
... on City {
city_Arg
}
... on Village {
villageArg
}
}
}
Cypher params
{
"locationValidTypes" : [ "City", "Village" ]
}
Cypher
MATCH (location:Location)
RETURN location {
.name,
.city_Arg,
.villageArg,
__typename: head([label IN labels(location) WHERE label IN $locationValidTypes])
} AS location