Upgrade to Pro — share decks privately, control downloads, hide ads and more …

So you Want to Distribute your GraphQL Schema?

So you Want to Distribute your GraphQL Schema?

Marc-Andre Giroux

February 28, 2019
Tweet

More Decks by Marc-Andre Giroux

Other Decks in Technology

Transcript

  1. How people build software ! " So you Want to

    Distribute your GraphQL Schema? @__xuorig__ GraphQL Day Feb. 28th, Toronto
  2. How people build software " • Independent development • Independent

    scalability • Availability • Strong Boundaries • A ton of other good reasons
  3. How people build software " Schema 1 query { allPlanets

    { edges { node { population } } } } Schema 2 Schema 3 Schema n
  4. How people build software " 1. One Graph (One exposed

    schema) 2. Federated Implementation (Distributed schema)
  5. How people build software " But first... a bit of

    history. Why are we here today?
  6. How people build software " • Very well optimized for

    one use case • Easily cacheable • Provide links to related resources (REST)
  7. How people build software " API Web Browsers Mobile Servers

    Analytics Gaming Consoles Your fridge Internal Services
  8. How people build software " Each client usually has different

    data requirements and even slightly different use cases!
  9. How people build software " GET /planets GET /planets_for_fridge GET

    /planets?version=playstation GET /planets?partial=minimal GET /planets?fields=name,population GET /planets?fields=reinventaquerylanguage Accept Header ...
  10. How people build software " GraphQL is not the first

    time we try to solve this problem!
  11. How people build software " type Query { films: [Film!]!

    } type Film { name: String! } type Query { character(id: ID!): Character } type Character { name: String! } FILM SERVICE CHARACTER SERVICE
  12. How people build software " type Query { films: [Film!]!

    character(id: ID!): Character } type Film { name: String! } type Character { name: String! } GATEWAY
  13. How people build software " type Query { films: [Film!]!

    } type Film { name: String! characters: [Character!]! } type Query { character(id: ID!): Character } type Character { name: String! films: [Film!]! } FILM SERVICE CHARACTER SERVICE
  14. How people build software " type Query { films: [Film!]!

    } type Film { name: String! characters: [Character!]! } type Query { character(id: ID!): Character } type Character { name: String! films: [Film!]! } FILM SERVICE CHARACTER SERVICE ? ?
  15. How people build software " type Query { films: [Film!]!

    } type Film { name: String! characters: [Character!]! } type Query { character(id: ID!): Character } type Character { name: String! films: [Film!]! } FILM SERVICE CHARACTER SERVICE ? ?
  16. How people build software " type Query { films: [Film!]!

    filmsById(ids: [ID!]!: [Film!]! } type Film { name: String! characterIDs: [ID!]! } type Query { characters(ids: [ID!]): [Character!]! } type Character { name: String! filmIDs: [ID!]! } FILM SERVICE CHARACTER SERVICE
  17. How people build software " • One of GraphQL's great

    feature is how we can expand relationships within a single query, we've lost that ability because every query requires `ids` to have been fetched before. • To avoid many round trips, schemas that use this approach will try to load as many things as possible using the ID of a certain resource. • Our schema design is affected by the fact our schema is separated in multiple services. Ideally we'd like our clients not be affected by the technical decision of using a distributed architecture.
  18. How people build software " type Query { films: [Film!]!

    } type Film { name: String! characters: [Character!]! } type Query { character(id: ID!): Character } type Character { name: String! films: [Film!]! } FILM SERVICE CHARACTER SERVICE ? ?
  19. How people build software " type Query { films: [Film!]!

    } type Film { name: String! } type Query { character(id: ID!): Character } type Character { name: String! } FILM SERVICE CHARACTER SERVICE
  20. How people build software " extend Film { characters: [Character!]!

    } extend Character { films: [Film!]! } LINKS
  21. How people build software " type Query { films: [Film!]!

    character(id: ID!): Character } type Film { name: String! } type Character { name: String! } extend Film { characters: [Character!]! } extend Character { films: [Film!]! }
  22. How people build software " Gateway (Stitched Schema, Links) Film

    Service & Schema Character Service & Schema
  23. How people build software " Gateway (Stitched Schema, Links) Film

    Service & Schema Character Service & Schema Adding new functionality Add a new type to the character schema Add a link to "plug in" the new feature with the rest of the schema
  24. How people build software " • Schema modifications now often

    require a two step process (Add new functionality to the right schema, extend at gateway to allow for relationships) • We end up with something still quite centralized because of where the relationships are formed and the final schema is built • It's not very clear where new schema use cases go. We risk that a lot of domain logic will leak into the gateway, making our GraphQL gateway a monolithic API, the thing we wanted to avoid in the first place using this solution.
  25. How people build software " What should an API Gateway

    even do? What it should it not do?
  26. How people build software " The Goal: Decouple clients from

    the services involved in consumed use cases
  27. How people build software " "We remain concerned about business

    logic and process orchestration implemented in middleware, especially where it requires expert skills and tooling while creating single points of scaling and control. 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
  28. How people build software " type Query { films: [Film!]!

    } type Film { name: String! } extend Character { films: [Film!]! } type Query { character(id: ID!): Character } type Character { name: String! } extend Film { characters: [Character!]! } FILM SERVICE CHARACTER SERVICE
  29. How people build software " • Schema Stithing but without

    the "links" • Choreography vs Orchestration • The "Gateway" does almost nothing in theory
  30. How people build software " Never forget that we're trying

    to enable use cases, and don't actually care about the services involved
  31. How people build software " Splitting schemas per service may

    be leading us to designing a schema that maps too much to our internal view of things rather than focusing on use cases
  32. How people build software " GraphQL seems like a real

    great fit to expose an API and decouple clients from the services that enable use cases
  33. How people build software " But it's not clear to

    me we need to split up schemas across the network.
  34. How people build software " If it really does... consider

    splitting in larger "use case" chunks versus using a lot of small modules
  35. How people build software " Keep an eye out for

    awesome solutions that will be coming up. But... always remember what our initials goals were!