## GraphQL federation on the edge
## GraphQL Federation: WHY? ![start](./images/start.png) - This is where all applications start - Perfect for simple application - Great to have a unified view of the data
## THE MONOLITH ![monolith](./images/monolith.png) - As the application grows, it starts to tangle more and more - Multiple teams working on it, with risk of type duplications, and moving slower
## BFF ![bff](./images/bff.png) - Good developer experience, domain separation - Duplicate effort, missing an unified view of the data
## Apollo Federation: Concepts ![federation-gateway](./images/federation-gateway.png) - The gateway is the entry point of each request and coordinates all the subgraphs - What is a subgraph? It's an instance of @apollo/subgraph. For example, In SE we got disco, se and assessment subgraphs
## Apollo Federation: Concepts ![subgraphs](./images/subgraphs.png) - In a federated architecture multiple subgraphs are federated into a single "supergraph" on the gateway - Easy to merge different types, but what about extending?
## Apollo Federation: Entities ![drilling-disco](./images/drilling-disco.png) - An entity is an object type that you define in one subgraph and you extend and reference in other subgraphs - In apollo, you can define an entity by using the `@key` directive
## Apollo Federation: Entities ![directives](./images/directives.png) - SE subgraph extends the type from Disco - SE needs also resolvers for the fields it provides
## Apollo Federation: Entities - Merged type in federation ![drilling-federated](./images/drilling-federated.png)
## Apollo Federation: Concepts ![federation](./images/federation.png)
## INNER WORKINGS ![entities](./images/entities.png) - Transforming the server to a subgraph, it will provide a _service and a _entities query ![union-entity](./images/union-entity.png)
## How data is queried ![example-query](./images/example-query.png) - We query for any type specifying the required keys and the typename - Use the `...on` sytax to query the fields of the specific type
## So are we using apollo federation? - Only on the subgraphs, the gateway is using @graphql-tools stitching - Reasons: smaller bundle size & less bloated, more powerful, runs smooths on workers - Compatible with apollo federation (not to be confused with the "old" stitching)
## How does graphql-tools stitching works? - Remote schemas that threats remote endpoints as if they were local executable schemas ![fifty](./images/remote-schemas.png)
## How does graphql-tools stitching works? - Stitching schemas together will create a single schema like on apollo federation - Some minor conversion needed for the directives ![fifty](./images/stitching.png)
## Full stitching example ![full-stitching](./images/full-stitching.png)
## Pitfalls ![fifty](./images/requires.png) - Think about the federation when designing queries and entities, you could easily trigger multiple subgraph requests
## Pitfalls - Avoid breaking changes, with federation you could break the graph for everyone - Be careful about enums, interfaces, inputs with the same names (we have some things in place to prevent this)
## Cloudflare
## Cloudflare workers: Pros - All the serverless goodies (autoscaling, easy deployments, global network) - 0ms cold start - Edge storage KV builtin - 1/10th the cost of other serverless platforms
## Cloudflare workers: Differences - Does not support lots of node builtin modules (so we had to reimplement things like apps insights) - Testing environments required some work (ie: kv mocks, call interception, cron tiggers...) - Still cutting edge, so more functionalities added, tooling changes, best practices not obvious etc.