So you Want to Distribute your GraphQL Schema?

So you Want to Distribute your GraphQL Schema?

F34d97ba1bfea0ff5e35a9c198562402?s=128

Marc-Andre Giroux

June 20, 2019
Tweet

Transcript

  1. @__xuorig__ GraphQL Conf 2019 So You Want To Distribute Your

    GraphQL Schema?
  2. GraphQL Conf 2019 @__xuorig__ Marc-André Giroux Montréal, Canada @__xuorig__

  3. None
  4. GraphQL Conf 2019 @__xuorig__ Distributed GraphQL?

  5. GraphQL Conf 2019 @__xuorig__ Distributed GraphQL The Basic Case GraphQL

    API query GetRepositories { viewer { repositories(first: 10) { name owner { name } } } }
  6. GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories

    { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service
  7. GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories

    { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service ?
  8. GraphQL Conf 2019 @__xuorig__ Distributed GraphQL Distributed Case query GetRepositories

    { viewer { repositories(first: 10) { name owner { name } } } } Search Service Monolith User Service
  9. GraphQL Conf 2019 @__xuorig__ Schema Stitching

  10. GraphQL Conf 2019 @__xuorig__ Schema Federation

  11. GraphQL Conf 2019 @__xuorig__ GraphQL Gateway

  12. GraphQL Conf 2019 @__xuorig__ GraphQL Modules

  13. GraphQL Conf 2019 @__xuorig__ Namespaces

  14. GraphQL Conf 2019 @__xuorig__ Schema Delegation

  15. GraphQL Conf 2019 @__xuorig__ Schema Composition

  16. GraphQL Conf 2019 @__xuorig__

  17. "Though there is only one graph, the implementation of that

    graph should be federated" - https://principledgraphql.com/ GraphQL Conf 2019 @__xuorig__
  18. GraphQL Conf 2019 @__xuorig__

  19. GraphQL Conf 2019 @__xuorig__

  20. GraphQL Conf 2019 @__xuorig__ The API Gateway pattern is far

    from new...
  21. GraphQL Conf 2019 @__xuorig__ So what's different this time?

  22. GraphQL Conf 2019 @__xuorig__ API Gateways Endpoint Based GET /users/1

    Search Service Monolith User Service
  23. GraphQL Conf 2019 @__xuorig__ API Gateways Endpoint Based GET /search?q=stuff

    Search Service Monolith User Service
  24. GraphQL Conf 2019 @__xuorig__ In some ways, not so different...

  25. GraphQL Conf 2019 @__xuorig__ Schema "Stitching"

  26. GraphQL Conf 2019 @__xuorig__ query { search(query: "stuff") {} issue(id:

    "abc") {}
 user(id: "def") {} } Search Service Monolith User Service
  27. GraphQL Conf 2019 @__xuorig__ Search Service Monolith User Service type

    Query { search(query: String!): [SearchResult!] } type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue }
  28. GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

  29. GraphQL Conf 2019 @__xuorig__ Gateway type Query { search(query: String!):

    [SearchResult!] user(id: ID!): User issue(id: ID!): Issue }
  30. GraphQL Conf 2019 @__xuorig__ In other ways, much more complex.

  31. GraphQL Conf 2019 @__xuorig__ API Gateways •Types, and even singular

    fields, can possibly be resolved by `n` services •Nested fields may need to be resolved outside the current service •Resolution logic is extremely complex (Avoiding N+1's, handling failure scenarios within resolution of a query, etc) GraphQL
  32. GraphQL Conf 2019 @__xuorig__ Search Service Monolith User Service type

    Query { search(query: String!): [SearchResult!] } union SearchResult = User | Issue type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue } type Issue { owner: User! } Schema Stitching The Harder Parts
  33. GraphQL Conf 2019 @__xuorig__ Schema Stitching The Harder Parts Search

    Service Monolith User Service type Query { search(query: String!): [SearchResult!] } union SearchResult = User | Issue type Query { user(id: ID!): User } type Query { issue(id: ID!): Issue } type Issue { owner: User! }
  34. GraphQL Conf 2019 @__xuorig__ •Individual Schemas are invalid on their

    own, only the final merged schema is valid. •The Gateway is now much more complex than just simple "proxying" Schema Stitching The Harder Parts
  35. GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

  36. GraphQL Conf 2019 @__xuorig__ finalSchema = merge(user_schema, search_schema, monolith_schema)

  37. GraphQL Conf 2019 @__xuorig__ finalSchema = merge(...schemas, links)

  38. GraphQL Conf 2019 @__xuorig__ Schema Stitching Developer Experience Search Service

    Monolith User Service Gateway Add the "User.pullRequests" field Add the "User.pullRequests" link
  39. GraphQL Conf 2019 @__xuorig__ •Brittle Gateway Code •Business logic often

    creeping into the Gateway •What we wanted to decentralize often ends up being centralized Schema Stitching Developer Experience
  40. GraphQL Conf 2019 @__xuorig__

  41. https://www.apollographql.com/docs/graphql-tools/schema-stitching/

  42. GraphQL Conf 2019 @__xuorig__ If not schema stitching, then what?

  43. None
  44. None
  45. GraphQL Conf 2019 @__xuorig__ Hard Mode: The Magic Gateway

  46. GraphQL Conf 2019 @__xuorig__ Schema Federation: Don't miss tomorrow's talk!

  47. None
  48. GraphQL Conf 2019 @__xuorig__ Let's take a step back

  49. GraphQL Conf 2019 @__xuorig__ Is there a more pragmatic approach

    to a GraphQL Gateway?
  50. GraphQL Conf 2019 @__xuorig__ Why are we here today? Why

    GraphQL?
  51. GraphQL Conf 2019 @__xuorig__ One Size Fits All APIs

  52. GraphQL Conf 2019 @__xuorig__ Netflix's Server Side Adapters https://medium.com/netflix-techblog/embracing-the-differences-inside-the-netflix-api-redesign

  53. GraphQL Conf 2019 @__xuorig__ Netflix's Server Side Adapters - Daniel

    Jacobson The better approach for handling API design [...] is to create true separation of concerns, rather than have all server-side decisions made by the API provider.
  54. GraphQL Conf 2019 @__xuorig__ SoundCloud's BFF Pattern

  55. GraphQL Conf 2019 @__xuorig__ GraphQL can be our BFF

  56. GraphQL Conf 2019 @__xuorig__ GraphQL can be our server side

    client adapter engine
  57. GraphQL Conf 2019 @__xuorig__ https://medium.com/netflix-techblog/embracing-the-differences-inside-the-netflix-api-redesign-15fd8b3dc49d

  58. GraphQL Conf 2019 @__xuorig__ GraphQL queries are kind of on-

    demand resource representations
  59. GraphQL Conf 2019 @__xuorig__ GraphQL API query { viewer {

    repositories(first: 10) { name owner { name } } } } "I want this resource in this shape pls"
  60. GraphQL Conf 2019 @__xuorig__ GraphQL API query { viewer {

    repositories(first: 10) { name owner { name } } } } "K, it's accessible at /api/abc"
  61. GraphQL Conf 2019 @__xuorig__ GraphQL API GET /api/abc

  62. GraphQL Conf 2019 @__xuorig__ We're basically all using REST at

    this point
  63. GraphQL Conf 2019 @__xuorig__ This actually sounds like a great

    feature for an API gateway!
  64. GraphQL Conf 2019 @__xuorig__ What are we looking for in

    an API Gateway?
  65. GraphQL Conf 2019 @__xuorig__ Decouple the clients from the services

    involved in the consumed use cases
  66. GraphQL Conf 2019 @__xuorig__ Avoid domain logic #

  67. We remain concerned about business logic and process orchestration implemented

    in middleware [...] Vendors in the highly competitive API gateway market are continuing this trend by adding features through which they attempt to differentiate their products. This results in OVERAMBITIOUS API GATEWAY products whose functionality — on top of what is essentially a reverse proxy — encourages designs that continue to be difficult to test and deploy. https://www.thoughtworks.com/radar/platforms/overambitious-api-gateways GraphQL Conf 2019 @__xuorig__
  68. GraphQL Conf 2019 @__xuorig__ Do we really want to commit

    to GraphQL for inter-service communication?
  69. GraphQL Conf 2019 @__xuorig__ Not all of us are starting

    from scratch!
  70. GraphQL Conf 2019 @__xuorig__ Use Case Based, Curated API

  71. GraphQL Conf 2019 @__xuorig__ Really need a distributed schema?

  72. GraphQL Conf 2019 @__xuorig__ •Make sure you're not designing your

    API according to how your services are split up. •Dynamic / runtime "stitching" is scary, proceed with care. •Consider statically building a gateway from a distributed schema using tooling as a middle of the road approach.
  73. GraphQL Conf 2019 @__xuorig__ The GraphQL Gateway of my dreams

  74. GraphQL Conf 2019 @__xuorig__ •Configuration based / make it hard

    to do the wrong thing. •Thinest layer achievable •The API Gateway is "just" another service. •If distributed schemas are necessary, make it easy to "import" them into the gateway. •However, the gateway schema is its own thing that represents the source of truth for our exposed API. It requires •Resolution is done through your service communication of choice.
  75. GraphQL Conf 2019 @__xuorig__ Often a tradeoff between development &

    operational complexity
  76. GraphQL Conf 2019 @__xuorig__ Alternative: Make developer experience great by

    building tooling and best practices
  77. GraphQL Conf 2019 @__xuorig__ 300+ Contributors to GitHub's GraphQL Schema

  78. GraphQL Conf 2019 @__xuorig__ Megabytes of schema definitions

  79. GraphQL Conf 2019 @__xuorig__ Multiple teams working on one schema

    has not been the hard part
  80. GraphQL Conf 2019 @__xuorig__ It is very hard to operate

    a large GraphQL schema at scale, even as a single schema
  81. GraphQL Conf 2019 @__xuorig__ GraphQL has all we need to

    build a great aggregator or gateway!
  82. GraphQL Conf 2019 @__xuorig__ Before choosing a solution, ask yourself

    if the schema itself needs to be distributed
  83. Thank you Come see me after the talk! 
 or


    @__xuorig__ on Twitter