querying graphs with graphql

29

Upload: jexp

Post on 18-Mar-2018

249 views

Category:

Software


6 download

TRANSCRIPT

Page 1: Querying Graphs with GraphQL
Page 2: Querying Graphs with GraphQL

neo4j.com/developer

Page 3: Querying Graphs with GraphQL

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

Page 4: Querying Graphs with GraphQL

Whiteboard Model Is the Physical Model

Page 5: Querying Graphs with GraphQL

Cypher: Powerful & Expressive Graph Query Language

MATCH (:Person { name:“Dan”} ) -[:LOVES]-> (:Person { name:“Ann”} )

LOVES

Dan Ann

LABEL PROPERTY

NODE NODE

LABEL PROPERTY

Page 6: Querying Graphs with GraphQL
Page 7: Querying Graphs with GraphQL

Use Neo4j like a regularbacking database

https://launchpad.graphql.com/3wzp7qnjv

Page 8: Querying Graphs with GraphQL

Or ... turn Neo4j intoa native GraphQL backend

Page 9: Querying Graphs with GraphQL

1. take GraphQL query2. transform to Cypher3. execute against graph4. return results

Page 10: Querying Graphs with GraphQL

Based on ... what?Schema!

Which schema?

Page 11: Querying Graphs with GraphQL

Neo4j is schema-free, so:

[x] Use GraphQL Schema

Page 12: Querying Graphs with GraphQL

Neo4j isopen source& extensible

Let‘s build an extension

Page 13: Querying Graphs with GraphQL

How hard can it be?

Page 14: Querying Graphs with GraphQL

Transform + projectQuery / Results

Thank you!

Page 15: Querying Graphs with GraphQL

Introducing:

neo4j-graphql

What‘s in the box?

Page 16: Querying Graphs with GraphQL

Basics

Endpoint with basic authhost:port/graphqlPOST schema file

run queries with paramsproject results

Page 17: Querying Graphs with GraphQL

Cool Features

generate & run single graph queryauto generated mutations for types

first, offset, orderBy, @relationlookup by any field

fragments, unlimited nesting

Page 18: Querying Graphs with GraphQL

Power Up: @cypher

computed fieldscustom mutations & queries

parameter support

Page 19: Querying Graphs with GraphQL

Cool! How can I use it?

Page 20: Querying Graphs with GraphQL

npm install -g neo4j-graphql-cli

neo4j-graphql [my.schema]

Page 21: Querying Graphs with GraphQL
Page 22: Querying Graphs with GraphQL
Page 23: Querying Graphs with GraphQL
Page 24: Querying Graphs with GraphQL

movies.schema

Page 25: Querying Graphs with GraphQL
Page 26: Querying Graphs with GraphQL
Page 27: Querying Graphs with GraphQL

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")

Page 28: Querying Graphs with GraphQL

github.com/neo4j-graphql

Page 29: Querying Graphs with GraphQL

graphql.communitygraph.org