Despite the “Graph” in the name, GraphQL is mostly used to query relational databases or object models. But it is really well suited to querying graph databases too. In this talk, I’ll demonstrate how I implemented a GraphQL endpoint for the Neo4j graph database and how you would use it in your app.
3. Property Graph Model
CAR
name: “Dan”
born: May 29, 1970
twitter: “@dan”
name: “Ann”
born: Dec 5, 1975
since:
Jan 10, 2011
brand: “Volvo”
model: “V70”
LOVES
LOVES
LIVES WITH
PERSON PERSON
16. Basics
Endpoint with basic auth
host:port/graphql
POST schema file
run queries with params
project results
17. Cool Features
generate & run single graph query
auto generated mutations for types
first, offset, orderBy, @relation
lookup by any field
fragments, unlimited nesting
27. add superpower
type Actor {
totalMovies:Int @cypher(statement:
"RETURN size( (this)-[:ACTED_IN]->(:Movie) ) as total")
...
type Movie {
similar:[Movie] @cypher(statement:
"MATCH (this)-->(:Genre)<--(o:Movie) RETURN o LIMIT 10")
...
type QueryType {
topRatedMovies(score:Int) [Movie] @cypher(statement:
"MATCH (m:Movie)<-[r:RATED]-(:User) WHERE r.score > $score
RETURN m, avg(r.score) as score
ORDER BY score DESC LIMIT 10")
which has a graph as its core data model
Nodes
The objects in the graph
Can have name-value properties
Can be labeled
Relationships
Relate nodes by type and direction
Can have name-value properties
Where the database model is what is in your application and on your whiteboards
With its own powerful graph query language: Cypher
Neo4j and GraphQL, how would that work?
Actually it was not that hard, b/c the underlying data model was a great fit, as is the graph schema. And we had a bit of a head start due to Rod Johnson asking me to look into GraphQL + Neo4j some time last year.
Query transformation, language handling is easy. It runs on the JVM like Neo4j does.
computed fields e.g. for related, content,recommendations etc.
computed fields e.g. for related, content,recommendations etc.
computed fields e.g. for related, content,recommendations etc.
computed fields e.g. for related, content,recommendations etc.
computed fields e.g. for related, content,recommendations etc.
Easy
Easy
computed fields e.g. for related, content,recommendations etc.
computed fields e.g. for related, content,recommendations etc.