Benoit Simard (@logisima)
Please say hi to each other.
We’ll spend the afternoon together.
Graph addict
Data liberator
Web developer
Works at Neo4j
WIFI : network: SKEMA_GUEST
| login: event2018
| password : Riviera1
Working together today : Pair on the exercises | Ask relevant questions immediately, raise your hand if you have problems
1 break of 15 min exactly
Slides : https://bit.ly/2k168IY
Use hosted online demo services
Neo4j Sandbox : https://neo4jsandbox.com
Apollo Launchpad : https://launchpad.graphql.com
CodeSandbox : https://codesandbox.io
Locally
Github repo : https://bit.ly/grandstack
Requirement : Neo4j (3.2), Node & NPM
What is this Stack ?
Why a new stack?
Build a simple Movie application
A graph model with Neo4j
How to query it ?
GraphQL Schema definition
Implement GraphQl schema with Apollo
React’ing
A new paradigm for building APIs
Schema definition
Query language for APIs
Community of tools
JavaScript library for building user interfaces
Web, mobile (React Native)
Component based
Reusable
Composable
“A set of tools designed to leverage GraphQL and work together to create a great workflow”
Frontend framework integrations
Caching
Code generation
Schema creation
Mocking
Schema stitching
Performance monitoring
Is a graph database (ACID compliant)
Is a graph database (Native)
Schema less
Exists since 2010
Open-source
Nodes
The entity of your model
Can have labels
Can have properties
Relationships
Links two nodes, with a direction and a type
Can have properties
OpenCypher.org
Aims to deliver a full and open specification of the industry’s most widely adopted graph database query langage.
()
or (n)
Surrounded with parentheses
Use an alias to refer to our node later
(n:Label1:Label2)
Specify a Label, starts with a colon :
Group nodes by roles or types, think of labels as tags
(n:Label {prop: 'value'})
Nodes can have properties
-→
or -[r:TYPE]→
Wrapped with hyphens & square brackets
Like labels, a relationship type starts with a colon :
<
>
Specify the direction of the relationship -[:KNOWS {since: 2010}]→
Relationships can have properties too!
Goal: Query for Movie by title and find recommended movies
Sign in to Neo4j Sandbox: neo4jsandbox.com
Create a “Recommendations” sandbox
Explore the data in Neo4j Browser
Write two Cypher queries:
Search for a Movie by title substring
For a given movie, find recommended movies
Hint: explore the browser guide for ideas
Save these queries, we’ll use them in the next exercise
For those that want to do it locally, you can download the dataset here : https://bit.ly/2wNbhgI
And use :play https://guides.neo4j.com/sandbox/recommendations/index.html
to launch the guide
Search for a Movie by title substring
For a given movie, find recommended movies
“A query language for your API”
Developed by Facebook iOS team for iOS app
Reduce number of round trip requests in face of low latency
Declarative, state what fields you want Alternative to REST Self documenting (schema and types) Limited support for “queries” Logic is implemented in server
“A query language for your API, and a server-side runtime for executing queries by using a type system you define for your data”
“GraphQL isn’t tied to any specific database or storage engine”
“A GraphQL service is created by defining types and fields on those types, then providing resolver functions for each field on each type”
Schema is your friend, and GraphQl schema is the API spec
Design API schema
Build UI and backend
Deploy !
Type : The graph model definition
Query : What queries you can do
Mutations : What changes you can do
Define the GraphQl schema of our web application
Take a look at the Neo4j model
Think about entities
and queries
we need
How to fetch the data
Just an express.js server with some custom endpoints.
Translate your schema directly in Cypher, thanks to drirectives.
Goal: Build a GraphQL service that connects to Neo4j, allow for querying movies and recommended movies via GraphQL
Start with skeleton Launchpad: launchpad.graphql.com/3x984k8mv
Fork it, then add your Neo4j Sandbox credentials to secrets
Complete the GraphQL service implementation by adding your Cypher queries from Exercise 1
[optional] Use the JS GraphQL→ Cypher integrations instead of Cypher in resolver functions.
Note the GraphQl endpoint, we will use it later
Create an Apollo client by providing the GraphQl endpoint
Wrap your react application with ApolloProvider
====!
====!
Using React’s Higher Order Component feature : we can populate a component’s props to a GraphQL query
graphql() enhancer function
Now whenever TodoApp component is rendered, the GraphQL query is executed
Goal: Complete the skeleton React app by adding Apollo Client and fetch data from the GraphQL API you created in Exercise #2
Start with skeleton CodeSandbox: https://codesandbox.io/s/pk4219zyp0
Fork it
Complete the app by adding Apollo Client as a higher order component and connecting to your GraphQL API, using GraphQL to render movie data and recommendations
You’ll need to add react-apollo and apollo-client NPM dependencies