querying graphs with graphql
TRANSCRIPT
neo4j.com/developer
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 WITHPERSON PERSON
Whiteboard Model Is the Physical Model
Cypher: Powerful & Expressive Graph Query Language
MATCH (:Person { name:“Dan”} ) -[:LOVES]-> (:Person { name:“Ann”} )
LOVES
Dan Ann
LABEL PROPERTY
NODE NODE
LABEL PROPERTY
Use Neo4j like a regularbacking database
https://launchpad.graphql.com/3wzp7qnjv
Or ... turn Neo4j intoa native GraphQL backend
1. take GraphQL query2. transform to Cypher3. execute against graph4. return results
Based on ... what?Schema!
Which schema?
Neo4j is schema-free, so:
[x] Use GraphQL Schema
Neo4j isopen source& extensible
Let‘s build an extension
How hard can it be?
Transform + projectQuery / Results
Thank you!
Introducing:
neo4j-graphql
What‘s in the box?
Basics
Endpoint with basic authhost:port/graphqlPOST schema file
run queries with paramsproject results
Cool Features
generate & run single graph queryauto generated mutations for types
first, offset, orderBy, @relationlookup by any field
fragments, unlimited nesting
Power Up: @cypher
computed fieldscustom mutations & queries
parameter support
Cool! How can I use it?
npm install -g neo4j-graphql-cli
neo4j-graphql [my.schema]
movies.schema
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 scoreORDER BY score DESC LIMIT 10")
github.com/neo4j-graphql
graphql.communitygraph.org