Share
Embed
So you Want to Distribute your GraphQL Schema?
Marc-Andre Giroux
February 28, 2019
Transcript
80 slides
-
How people build software ! " So you Want to
Distribute your GraphQL Schema? @__xuorig__ GraphQL Day Feb. 28th, Toronto -
How people build software " GraphQL API query { allPlanets
{ edges { node { population } } } } -
How people build software " • Independent development • Independent
scalability • Availability • Strong Boundaries • A ton of other good reasons -
How people build software " Schema 1 query { allPlanets
{ edges { node { population } } } } Schema 2 Schema 3 Schema n -
How people build software " Lots of solutions in the
past few years... -
How people build software " 1. One Graph (One exposed
schema) 2. Federated Implementation (Distributed schema) -
How people build software " Is this the only way
going forward? -
How people build software " But first... a bit of
history. Why are we here today? -
How people build software " • Very well optimized for
one use case • Easily cacheable • Provide links to related resources (REST) -
How people build software " API Web Browsers Mobile Servers
Analytics Gaming Consoles Your fridge Internal Services -
How people build software " Each client usually has different
data requirements and even slightly different use cases! -
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 ... -
How people build software " GraphQL is not the first
time we try to solve this problem! -
How people build software " What was going on at
Facebook back then? -
How people build software " GraphQL is kind of an
client-based adapter engine! -
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 -
How people build software " type Query { films: [Film!]!
character(id: ID!): Character } type Film { name: String! } type Character { name: String! } GATEWAY -
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 -
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 ? ? -
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 ? ? -
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 -
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. -
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 ? ? -
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 -
How people build software " extend Film { characters: [Character!]!
} extend Character { films: [Film!]! } LINKS -
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!]! } -
How people build software " Gateway (Stitched Schema, Links) Film
Service & Schema Character Service & Schema -
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 -
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. -
How people build software " What should an API Gateway
even do? What it should it not do? -
How people build software " The Goal: Decouple clients from
the services involved in consumed use cases -
How people build software " Avoid: Business logic leaking into
the gateway itself -
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 -
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 -
How people build software " • Schema Stithing but without
the "links" • Choreography vs Orchestration • The "Gateway" does almost nothing in theory -
How people build software " Who's in charge of the
"query plans"? -
How people build software " I worry about splitting up
schemas too early -
How people build software " Never forget that we're trying
to enable use cases, and don't actually care about the services involved -
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 -
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 -
How people build software " But it's not clear to
me we need to split up schemas across the network. -
How people build software " Use GraphQL as your special
"Backend for Frontend" -
How people build software " Ask yourself if the GraphQL
API itself needs to be split up -
How people build software " If it really does... consider
splitting in larger "use case" chunks versus using a lot of small modules -
How people build software " Keep an eye out for
awesome solutions that will be coming up. But... always remember what our initials goals were!