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.

Modular GraphQL with Schema Stitching

2,891 views

Published on

What if you could create a GraphQL API by combining many smaller APIs? That's what we're aiming for with schema stitching, the new feature in the Apollo graphql-tools package.

Published in: Technology
  • Be the first to comment

Modular GraphQL with Schema Stitching

  1. 1. Modular GraphQL Unified schema, decoupled implementation Sashko Stubailo, Open Source Lead at Apollo @stubailo
  2. 2. GraphQL is awesome ● Unifies all of your data into one schema and API ● You used to have to go to separate places, now get everything in one place ● Make fewer requests to get multiple objects
  3. 3. Unifying theme? But what about coupling? Disorganized Organized
  4. 4. Kinds of technical diversity 1. Different data sources and backends? Easy with GraphQL 2. Different teams collaborating on one API? Might cause coupling and political situations 3. Different technologies, APIs, GraphQL implementations? Might be hard. a. Frequently end up with multiple GraphQL servers
  5. 5. Making a single GraphQL API modular ● Commonly asked question: How do I avoid coupling together my types? ● Our suggested approach: ○ Schema: Definition of external interface ○ Models: Business logic ○ Connectors: Details about backend implementation ● Organize Query, Mutation, Subscription initial fields together with the relevant types in a module
  6. 6. Making a single GraphQL API modular But sometimes, modularity in the code is not enough Users Comments Posts
  7. 7. Benefits of microservices ● Core idea: Iterate on your part without blocking on others ● Write different backends and features in different technologies ● Own your own data and enable more vertically integrated teams ● Independently version the backends and avoid a monolithic release process GraphQL makes our backend feel a lot more flexible and "modular" - shouldn't we be able to get these benefits quite easily?
  8. 8. Integrating multiple GraphQL services today ● GraphQL can call any backend, so it can call GraphQL too ● We often talk about using GraphQL as a gateway to REST, GRPC, etc ● Unfortunately GraphQL to GraphQL is not any easier; no virality
  9. 9. Example: Integration with Graphcool and GitHub ● Integrate via a serverless function ● Retrieve data as if it were a REST API ● It should be way better! Link: https://github.com/graphcool-examples/functions/blob/ce1c293872284e5741fb8037c0bd64224a62c26 e/miscellaneous/github-fetch-repo/github-fetch-repo.js
  10. 10. Main benefit of GraphQL: Traverse data easily
  11. 11. What if we could traverse between schemas?
  12. 12. Introducing: Schema stitching in GraphQL Tools PR: https://github.com/apollographql/graphql-tools/pull/382
  13. 13. Demo: GraphQL Summit 2017 ● Universe ticketing API: https://developers.universe.com/page/graphql-explorer ● Dark Sky weather API on Launchpad: https://launchpad.graphql.com/5rrx10z19 ● Can we figure out the weather at the location of GraphQL Summit 2017? Spoiler alert: Yes!
  14. 14. Demo screenshot
  15. 15. summit.graphql.com @graphqlsummit
  16. 16. Things to consider ● Making it work with all of GraphQL ● More efficient batching of requests to the backend services ● Not always easy to split a schema cleanly into parts ● Overlap between schemas, duplicate types ● Not clear if this is a good architecture, but the only way to find out is to try
  17. 17. Potential benefits ● Increase virality of GraphQL: The more people use it, the easier it is to integrate ● Versioning, testing, and deploying subparts of a schema independently ● Implement different parts of your schema with different technologies ● Easily integrate with public APIs
  18. 18. Action items for you ● Tell us about your use case! ○ Join #schema-stitching on Apollo Slack ○ https://www.apollodata.com/#slack ● Try the alpha releases of GraphQL Tools 2.0 ○ https://github.com/apollographql/graphql-tools/pull/382 ● Build more GraphQL APIs apollodata.com Thank you! Follow me at @stubailo We're hiring! DM for info.

×