Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Building Fullstack Graph Applications With Neo4j

82 vues

Publié le

Speaker: Will Lyon, Developer Relations Engineer, Neo4j

Publié dans : Technologie
  • Soyez le premier à commenter

Building Fullstack Graph Applications With Neo4j

  1. 1. Fullstack Graph w/ Neo4j William Lyon @lyonwj lyonwj.com bit.ly/seattlegraph Graph Tour Seattle
  2. 2. William Lyon Software Developer @Neo4j ● Neo4j Labs ■ Integrations ■ GraphQL ■ Data Visualization ■ ... @lyonwj lyonwj.com will@neo4j.com
  3. 3. Pig E. Bank
  4. 4. https://neo4j.com/graphacademy/online-training/
  5. 5. Labeled Property Graph
  6. 6. Cypher Query Language
  7. 7. https://neo4jsandbox.com
  8. 8. neo4j.com/developer/get-started/
  9. 9. r.neo4j.com/youtube
  10. 10. medium.com/neo4j
  11. 11. community.neo4j.com
  12. 12. neo4j.com/tag/twin4j
  13. 13. neo4j.com/graphacademy/neo4j-certification/
  14. 14. ● ● ●
  15. 15. ● ● ● ● ● ○ ○ ○ John Table Mary von Groff Cookie Macy Stream SSN: X-Y-Z-A Phone: 555-1234
  16. 16. 1. → 2. 3. 4. 5. Arrows for data model diagrams: www.apcjones.com/arrows/
  17. 17. youtube.com/watch?v=SSjlUoFQdos
  18. 18. ● ● ●
  19. 19. neo4j.com/labs/
  20. 20. Extending Neo4j • • •
  21. 21. About APOC • Large standard library of utility functions and procedures • Actively developed - many contributors • "scratch your itch" • Makes Cypher easier to use • Enable some specific use-cases • Plan is it migrate some of the functionality into the Neo4j product
  22. 22. Browser Guide :play apoc • Explore live examples
  23. 23. • Relational / Cassandra • MongoDB, Couchbase, ElasticSearch • JSON, XML, CSV, XLS • Cypher, GraphML • … Data integration
  24. 24. Load from a relational database
  25. 25. apoc.load.jdbc WITH "jdbc:mysql://localhost:3306/customers?user=root" AS url CALL apoc.load.jdbc(url,"parties") YIELD row MERGE (p:Party {id: row.PartyID}) SET p.name = row.name, p.ssn = row.SSN
  26. 26. 1) 2) 3) 4) neo4j.com/labs/etl-tool/
  27. 27. {event} {event}
  28. 28. • • • neo4j.com/labs/kafka/
  29. 29. {event} {event}
  30. 30. Graph Algorithms in Neo4j • Parallel Breadth First Search & DFS • Shortest Path • Single-Source Shortest Path • All Pairs Shortest Path • Minimum Spanning Tree • A* Shortest Path • Yen’s K Shortest Path • K-Spanning Tree (MST) • Random Walk • Degree Centrality • Closeness Centrality • CC Variations: Harmonic, Dangalchev, Wasserman & Faust • Betweenness Centrality • Approximate Betweenness Centrality • PageRank • Personalized PageRank • ArticleRank • Eigenvector Centrality • Triangle Count • Clustering Coefficients • Connected Components (Union Find) • Strongly Connected Components • Label Propagation • Louvain Modularity – 1 Step & Multi-Step • Balanced Triad (identification) • Euclidean Distance • Cosine Similarity • Jaccard Similarity • Overlap Similarity • Pearson Similarity Pathfinding & Search Centrality / Importance Community Detection Similarity Updated June 2019 Link Prediction • Adamic Adar • Common Neighbors • Preferential Attachment • Resource Allocations • Same Community • Total Neighbors +35
  31. 31. ● bolt+routing:// ● ● ● neo4j.com/developer/language-guides/
  32. 32. ● Fullstack framework for building applications Fullstack GraphQL with GRANDstack grandstack.io @lyonwj
  33. 33. What is GraphQL? graphql.org An API query language and runtime for building APIs @lyonwj
  34. 34. “Your Application Data Is A Graph” -- GraphQL @lyonwj
  35. 35. Movies, Genres, Directors, Actors @lyonwj
  36. 36. Movies, Genres, Directors, Actors GraphQL Type Definitions ● Defined using GraphQL Schema Definition Language (SDL) @lyonwj
  37. 37. Movies, Genres, Directors, Actors Introspection ● Schema can be queried ● Schema becomes API specification / documentation ● Tools like GraphiQL / GraphQL Playground @lyonwj
  38. 38. Movies, Genres, Directors, Actors GraphQL query @lyonwj
  39. 39. https://blog.apollographql.com/the-anatomy-of-a-graphql-query-6dffa9e9e747 Operation name and arguments @lyonwj
  40. 40. Selection set @lyonwj https://blog.apollographql.com/the-anatomy-of-a-graphql-query-6dffa9e9e747
  41. 41. GraphQL query Movies, Genres, Directors, Actors @lyonwj
  42. 42. GraphQL query GraphQL response Movies, Genres, Directors, Actors @lyonwj
  43. 43. 1) GraphQL is an API query language, not a database query language. 2) Limited expressivity (no projections, no aggregations, etc). 3) While GraphQL exposes your application data as a graph, it’s not (just) for graph databases What is GraphQL? @lyonwj
  44. 44. ● Overfetching ○ Less data over the wire ● Underfetching ○ Single round trip ● GraphQL Specification ● “Graphs All The Way Down” ○ Relationships vs Resources ○ Unify disparate systems (microservices) ● Simplify data fetching ○ Component based data interactions GraphQL Advantages @lyonwj
  45. 45. ● Some well understood practices from REST don’t apply ○ HTTP status codes ○ Errors ○ Caching ● Exposing arbitrary complexity to client ○ Performance considerations ● n+1 query problem ● Query costing / rate limiting GraphQL Challenges @lyonwj
  46. 46. Example API & How It’s Built
  47. 47. Example GraphQL API Neo4j Community Forum Trending Activity Feeds community.neo4j.com @lyonwj
  48. 48. communityapi.neo4jlabs.com@lyonwj
  49. 49. How To Build A GraphQL Service
  50. 50. hackernoon.com/building-trending-activity-feeds-using-graphql-and-neo4j-e62ee790238e@lyonwj
  51. 51. Community Graph http://138.197.15.1:7474/browser/ user: community password: community@lyonwj
  52. 52. @lyonwj
  53. 53. Start With A GraphQL Schema graphql.org/learn/schema/#type-language @lyonwj
  54. 54. Start With A GraphQL Schema Type Definitions @lyonwj
  55. 55. Start With A GraphQL Schema API Entry Point(s) Query & Mutation Types @lyonwj
  56. 56. Start With A GraphQL Schema API Entry Point(s) Query & Mutation Types graphql.org/learn/schema/#type-language @lyonwj
  57. 57. ● Functions that define how to “resolve” data for GraphQL request GraphQL Resolvers graphql.org/learn/execution/#root-fields-resolvers@lyonwj
  58. 58. Cypher Query https://hackernoon.com/building-trending-activity-feeds-using-graphql-and-neo4j-e62ee790238e @lyonwj
  59. 59. Resolvers @lyonwj
  60. 60. Apollo Server https://www.apollographql.com/docs/apollo-server/@lyonwj
  61. 61. Apollo Server @lyonwj
  62. 62. Apollo Server @lyonwj
  63. 63. Apollo Server @lyonwj
  64. 64. Apollo Server @lyonwj
  65. 65. communityapi.neo4jlabs.com@lyonwj
  66. 66. 1) Schema Duplication 2) Mapping / translation layer from graph ←→ (???) 3) Boilerplate code 4) n+1 query problem Common Problems With This Approach https://blog.grandstack.io/five-common-graphql-problems-and-how-neo4j-graphql-aims-to-solve-them-e9a8999c8d43 @lyonwj
  67. 67. GraphQL “Engines”
  68. 68. ● Tools for auto-generating GraphQL schema, generating database queries from GraphQL requests GraphQL “Engines” Overview prisma.io aws.amazon.com/appsync hasura.io graphile.org grandstack.io Neo4j-GraphQL @lyonwj
  69. 69. Neo4j-GraphQL
  70. 70. ● GraphQL First Development ○ GraphQL schema drives the database data model ● Generate Cypher from GraphQL ○ Single query / single round trip to database ● Generate GraphQL CRUD API from type definitions ● Auto-generated resolvers (no boilerplate!) ● Extend GraphQL functionality with Cypher ○ @cypher schema directive Goals for Neo4j-GraphQL Integration @lyonwj
  71. 71. GraphQL First Development @lyonwj
  72. 72. Auto-generate GraphQL CRUD API @lyonwj Query & Mutation types ○ Entry point for each type Ordering Pagination Complex Filter DateTime types https://blog.grandstack.io/complex-graphql-filtering-with-neo4j-graphql-js-aef19ad06c3e
  73. 73. Generate Cypher From GraphQL @lyonwj
  74. 74. Extend GraphQL w/ Cypher grandstack.io/docs/neo4j-graphql-js.html#cypher-directive @cypher GraphQL schema directive @lyonwj
  75. 75. www.npmjs.com/package/neo4j-graphql-js@lyonwj
  76. 76. neo4j-graphql-js neo4j-graphql-js apollo-server @lyonwj
  77. 77. Demo GRANDstack starter project grandstack.io https://github.com/grand-stack/grand-stack-starter/tree/master/api/src@lyonwj
  78. 78. GRANDstack.io @lyonwj
  79. 79. ● Declarative database integrations for GraphQL ● GraphQL type definitions define database model ● Provision CRUD GraphQL API ○ Auto-generated GraphQL API ○ Schema enrichments ● Generate database queries ○ auto-generated resolvers ○ reduce boilerplate GraphQL ”Engines” @lyonwj
  80. 80. How Do GraphQL Engines Generate Database Queries From GraphQL Requests? resolveInfo resolver argument ● GraphQL query AST ● GraphQL schema ● Selection set ● Variables ● ... @lyonwj
  81. 81. Deploying A GraphQL Service
  82. 82. GraphQL Deployment “Traditional” Approaches Serverless Options ● PaaS ○ Heroku, AWS Elastic Beanstalk ● Docker container ● VPS ● ... ● AWS Lambda, Google Cloud Functions, Azure ● Serverless Framework ○ serverless.com ● Zeit Now ○ zeit.co/now ● Netlify Functions ○ netlify.com @lyonwj
  83. 83. neo4j-graphql-js apollo-server Neo4j Cloud AWS Lambda GCP Functions Static CDN GraphQL Deployment @lyonwj
  84. 84. https://blog.apollographql.com/deploy-a-fullstack-apollo-app-with-netlify-45a7dfd51b0b @lyonwj
  85. 85. grandstack.io
  86. 86. GRANDstack https://github.com/grand-stack/grandstack.io/issues/1 @lyonwj
  87. 87. GraphQL Clients Apollo Client Alternatives ● Most popular ● Frontend integrations for: ○ React, Angular, vue.js, scala.js,iOS, Android, etc ● Relay ● urql ● graphql-request ● GraphiQL ● GraphQL Playground ● fetch ● <any http client> @lyonwj
  88. 88. Apollo Client (for React) @lyonwj
  89. 89. Apollo Client (for React) @lyonwj
  90. 90. Apollo Client (for React) @lyonwj
  91. 91. Query GraphQL endpoint Render our table @lyonwj
  92. 92. <Query> component @lyonwj
  93. 93. Handle GraphQL response and render table @lyonwj
  94. 94. @lyonwj
  95. 95. ● ●
  96. 96. ● ● ● ● ○ ○ ○
  97. 97. ● ●
  98. 98. Fraud Flagger Party Interaction Stream Fraud Suspect Stream Fraud Confirmation Stream neo4j-streams
  99. 99. Investigation Account Action Improved Insight
  100. 100. 1. a. 2. 3.
  101. 101. Graph Algorithm Categories in Neo4j neo4j.com/ graph-algorithms- book/ Pathfinding & Search Centrality / Importance Community Detection Link Prediction Finds optimal paths or evaluates route availability and quality Determines the importance of distinct nodes in the network Detects group clustering or partition options Evaluates how alike nodes are Estimates the likelihood of nodes forming a future relationship Similarity
  102. 102. Graph Algorithms in Neo4j • Parallel Breadth First Search & DFS • Shortest Path • Single-Source Shortest Path • All Pairs Shortest Path • Minimum Spanning Tree • A* Shortest Path • Yen’s K Shortest Path • K-Spanning Tree (MST) • Random Walk • Degree Centrality • Closeness Centrality • CC Variations: Harmonic, Dangalchev, Wasserman & Faust • Betweenness Centrality • Approximate Betweenness Centrality • PageRank • Personalized PageRank • ArticleRank • Eigenvector Centrality • Triangle Count • Clustering Coefficients • Connected Components (Union Find) • Strongly Connected Components • Label Propagation • Louvain Modularity – 1 Step & Multi-Step • Balanced Triad (identification) • Euclidean Distance • Cosine Similarity • Jaccard Similarity • Overlap Similarity • Pearson Similarity Pathfinding & Search Centrality / Importance Community Detection Similarity Updated June 2019 Link Prediction • Adamic Adar • Common Neighbors • Preferential Attachment • Resource Allocations • Same Community • Total Neighbors +35
  103. 103. ● ● ○ ○ ● ○ ○ ○ ○ ● ○ ○ ■ ○
  104. 104. ● ● ●
  105. 105. ● ● ● ● ●
  106. 106. ● ○ https://github.com/neo4j-contrib/neo4j-streams ○ https://www.confluent.io/hub/neo4j/kafka-connect-neo4j ● https://grandstack.io/ ● https://www.freecodecamp.org/news/how-to-leverage-neo4j-streams-and-build-a-just-in-time-data-warehouse-64adf290f093/ ● https://neo4j.com/docs/graph-algorithms/current/

×