Building A GraphQL Service Backed By Neo4j
-
Upload
neo4j-the-fastest-and-most-scalable-native-graph-database -
Category
Technology
-
view
235 -
download
0
Transcript of Building A GraphQL Service Backed By Neo4j
![Page 1: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/1.jpg)
Building a GraphQL Service Backed by Neo4j
William Lyon@lyonwj
lyonwj.comtype User { name: ID! address: String seen: [Movie] @relation(name: "RATED") recommended(first:Int = 5): [Movie] @cypher(statement:
’’’MATCH (u)-->(:Movie)<--(:User)-->(reco:Movie) WHERE NOT (u)-[:RATED]->(reco)
RETURN reco, count(*) as score’’’}
![Page 3: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/3.jpg)
GraphQL + Neo4j
● An overview of GraphQL● Building a GraphQL service● Neo4j-GraphQL integration(s)● GRANDstack
@lyonwj | lyonwj.com
![Page 4: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/4.jpg)
An Overview Of GraphQL● A new paradigm for buildings APIs● Schema definition
○ Types○ GraphQL entry points (Query & Mutation types)
● Query language for APIs○ Limited support for “queries” (aggregations, filtering, …)
● Community of tools○ GraphiQL○ Mocking○ Performance monitoring
@lyonwj | lyonwj.com
![Page 6: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/6.jpg)
Building A GraphQL Service
1) Define a schema2) Implement resolver functions
○ Fetch data from data layer
@lyonwj | lyonwj.com
![Page 7: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/7.jpg)
Building A GraphQL Service
https://dzone.com/refcardz/an-overview-of-graphql
@lyonwj | lyonwj.com
![Page 8: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/8.jpg)
GraphQL First Development
1. Design API schema2. Build UI and backend3. Deploy!
• Schema is your friend• GraphQL Schema is the API spec
• Allows for simultaneous frontend and backend development
• Enables introspection• Build other tools (graphiql)
https://dev-blog.apollodata.com/navigating-your-transition-to-graphql-28a4dfa3acfb
![Page 9: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/9.jpg)
IDL Schema Syntaxtype Movie { movieId: ID! title: String year: Int plot: String poster: String imdbRating: Float genres: [String] similar(first: Int=3, offset:Int=0): [Movie]}
type Query {moviesByTitle(subString: String!, first: Int=3, offset: Int=0): [Movie]
}
![Page 10: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/10.jpg)
GraphQL Resolver Functions
https://github.com/grand-stack/grand-stack-movies-workshop/blob/master/graphql/end/src/schema.js
![Page 11: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/11.jpg)
GraphQL Resolver Functions
https://github.com/grand-stack/grand-stack-movies-workshop/blob/master/graphql/end/src/schema.js
![Page 13: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/13.jpg)
A GraphQL - Neo4j Integration?
● Developer productivity● Translate GraphQL → Cypher?● Improve performance?● Expose Cypher through GraphQL?
@lyonwj | lyonwj.com
![Page 14: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/14.jpg)
neo4j-graphql
github.com/neo4j-graphql/neo4j-graphql-js
neo4j.com/developer/graphql/
github.com/neo4j-graphql/neo4j-graphql
![Page 15: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/15.jpg)
Use The Schema, Luke
![Page 17: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/17.jpg)
Improved Performance
● N+1 query problem○ Batching
● GraphQL → single Cypher query○ Single round trip to database
@lyonwj | lyonwj.com
![Page 18: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/18.jpg)
Expose Cypher in GraphQL● GraphQL directives● @cypher schema directive
○ Map GraphQL fields to a Cypher query
@lyonwj | lyonwj.com
![Page 19: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/19.jpg)
@cypher Schema Directives
● Still a single Cypher query / single round-trip○ @cypher annotated query becomes a sub-query
@lyonwj | lyonwj.com
![Page 20: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/20.jpg)
neo4j-graphql-js
github.com/neo4j-graphql/neo4j-graphql-jshttps://launchpad.graphql.com/7kp8l0p4j
Auto-generate Cypher queriesWorks with apollo-server, graphql-tools, graphql-js,...
![Page 23: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/23.jpg)
Looking Forward
● Active development○ Feedback driven :-)
neo4j.com/developer/graphql/
grandstack.io/
@lyonwj | lyonwj.com
![Page 24: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/24.jpg)
Resources
![Page 29: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/29.jpg)
![Page 30: Building A GraphQL Service Backed By Neo4j](https://reader033.fdocuments.us/reader033/viewer/2022051504/5a64a7117f8b9a88568b4fd3/html5/thumbnails/30.jpg)
(you)-[:HAVE]->(questions)<-[:ANSWERS]-(will)
@lyonwj | lyonwj.com