Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Marco Liberati - Graph analytics

172 views

Published on

Machine Learning Data Science Meetup | 10.07.2018 | #AperiTech

Published in: Technology
  • Be the first to comment

Marco Liberati - Graph analytics

  1. 1. GraphQL ♥ Graph Database 15/03/2018
  2. 2. Marco Liberati @dej611 Enrico Risa @wolf4ood
  3. 3. Agenda - GraphQL Introduction - GraphQL Schema Definition (Meetup) - Why GraphQL ♥ Graph Database? - Schema Impl with a GraphDB
  4. 4. WHY GRAPHQL?
  5. 5. Let’s Talk About Rest first ● Resource Based ● HTTP Verbs ○ GET ○ PUT ○ PATCH ○ DELETE ○ POST Actions -> Verbs + Uris
  6. 6. Meetup model with REST ● https://api.meetup.com/:urlname ● https://api.meetup.com/:urlname/members ● https://api.meetup.com/:urlname/events ● https://api.meetup.com/:urlname/events/:event_id/rsvp
  7. 7. Sounds Cool, Let’s Use it
  8. 8. Multiple Round Trips Problem
  9. 9. How Do we Handle That? GET /GraphRM?fields=topics
  10. 10. …And What about Over-fetching? GET /GraphRM?only=id,name I need only those fields
  11. 11. You will probably end up with some custom endpoints
  12. 12. API Documentation ● How can i use those APIs ? ● What parameters this endpoint support? ● Is this parameter required? ● Swagger ● JSON Schema ● JSON:API ● API Blueprint Documentation should be good in order to let people use our APIs without headache
  13. 13. Potential Problems ● Multiple Round trips ● Over/Under fetching ● Documentation
  14. 14. What GraphQL IS NOT.. ● A query language for Graph Databases ● Database / Storage Engine ● A library ● It’s not language specific
  15. 15. What Is IT ? GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
  16. 16. Just a spec ● A declarative query language ● A type system ● A runtime that fetch and mutate data
  17. 17. Hello GraphQL
  18. 18. Hello GraphQL (with nesting)
  19. 19. How does it work ? ● The server describe what is possible (a type system) ● The client can asks exactly what data it requires ● The server then gives back results with the same shape as the query Power to the client
  20. 20. Powerful Type System ● Hierarchical ● Strongly-Typed ● Self Documenting ● Enable Introspection ● Client-specified queries
  21. 21. Types ● Objects ● Scalar ○ Boolean ○ Int ○ Float ○ String ○ Custom Types ● Enums ● Lists ● Unions ● Interfaces
  22. 22. GraphQL Schema Language ● GraphQL type system ● Describes what data can be queried ● Language-agnostic
  23. 23. GraphQL Schema Language Example
  24. 24. Mutation
  25. 25. Introspection
  26. 26. … Enables Tools ● GraphiQL ● Documentation ● IDE plugins ● Code generation ● Client Side Validation ● …
  27. 27. GraphQL Schema Definition (Meetup) ● Entity ○ User ○ Meetup ○ Tag ○ Event ● Query ○ meetupsByName ○ usersByName
  28. 28. GraphQL Schema Definition (Meetup) Demo time! https://github.com/GraphRM/graphql-graphdb
  29. 29. Why GraphQL ♥ Graph Database?
  30. 30. A GraphQL query represents a description of a relationship: Why GraphQL ♥ Graph Database? Person “me” :id :name Person :name Person :name
  31. 31. A GraphQL query represents a description of a relationship: Why GraphQL ♥ Graph Database? Person “me” :id :name Person :name Person :name Problem: ● For each Person the GraphQL reducer will go to the database and ask for data. ● This is known as the N+1 query problem. ● Which in turns mean poor performance
  32. 32. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database? ● This could prevent the N+1 queries problem ● A GraphDB is designed to run traversals ● Bonus: if the schema is the same for both GraphQL and DB that is a huge win!
  33. 33. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database?
  34. 34. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database?
  35. 35. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database? ● This is still a PoC but the idea is: ○ Parse the Schema and the query ○ Traverse the query and build a database query
  36. 36. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database? This is not fully compatible yet but there are some PoC: ● GraphQL -> Neo4J Cypher: https://github.com/neo4j-graphql/neo4j-graphql-js ● GraphQL -> OrientDB Gremlin + MATCH https://github.com/kensho-technologies/graphql-compiler
  37. 37. What if we could translate one GraphQL query to a single GraphDB query? Why GraphQL ♥ Graph Database? Demo time! https://github.com/GraphRM/graphql-graphdb
  38. 38. Grazie :)
  39. 39. Resources ● GraphQL: http://graphql.org/learn/ ● AST Explorer: https://astexplorer.net/ ● GRANDstack: https://grandstack.io/ ● GraphQL + OrientDB: https://blog.kensho.com/compiled-graphql-as-a-database-query-language-72e1 06844282 ● GraphQL + Neo4J: https://neo4j.com/developer/graphql/ ● Five common pitfalls with GraphQL and how Neo4J-GraphQL aims to solve them: https://blog.grandstack.io/five-common-graphql-problems-and-how-neo4j-graph ql-aims-to-solve-them-e9a8999c8d43

×