learning GraphQL
Federation
unified supergraph - GraphQL Super Graph
https://www.apollographql.com/docs/graphos/schema-design/federated-schemas/federation
Apollo is the biggest player. But they changed their licensing
WunderGraph pivoted in 2023 and is building an open source alternative to Apollo.
In Hearst they do GraphQL Federation.
Apollo Federation allows you to declaratively combine multiple APIs into a single federated GraphQL API. Federation serves as an API orchestration layer, where clients make a single GraphQL request and it coordinates multiple API calls to return a unified response.
caching
Apollo client has client side caching (InMemoryCache) by default out of the box with no config needed
You customize caching behavior by changing the fetch policy of queries:
cache-first: This is the default behavior. The useQuery hook checks the Apollo Client cache to see if all the data you requested is already available. If all of the data is available in the cache, useQuery returns that data and doesn't query your GraphQL server
cache-and-network:
network-only:
no-cache:
fetchPolicy is used for the query's first execution, and nextFetchPolicy is used to determine how the query responds to future cache updates. If nextFetchPolicy isn't specified it inherits the same value as fetchPolicy.
| Name | Description |
|---|---|
cache-first(default) |
Apollo Client first executes the query against the cache. If all requested data is present in the cache, that data is returned. Otherwise, Apollo Client executes the query against your GraphQL server and returns that data after caching it.Prioritizes minimizing the number of network requests sent by your application.This is the default fetch policy. |
cache-only |
Apollo Client executes the query only against the cache. It never queries your server in this case. When the cache does not contain data for all requested fields, a cache-only query returns data: undefined with dataState: "empty" and a networkStatus of NetworkStatus.ready. |
cache-and-network |
Apollo Client executes the full query against both the cache and your GraphQL server. The query automatically updates if the result of the server-side query modifies cached fields.Provides a fast response while also helping to keep cached data consistent with server data. |
network-only |
Apollo Client executes the full query against your GraphQL server, without first checking the cache. The query's result is stored in the cache. After the first result is received, external cache updates will be reflected by this query.Prioritizes consistency with server data, but can't provide a near-instantaneous response when cached data is available. |
no-cache |
Similar to network-only, except the query's result is not stored in the cache and external cache updates are completely ignored. |
standby |
Uses the same logic as cache-first, except this query does not automatically update when underlying field values change. You can still manually update this query with refetch and updateQueries.standby queries return networkStatus: NetworkStatus.ready even before subscription, providing immediate feedback to your UI. |
I assume Apollo server has some sort of caching mechanism as well. Or perhaps the caching happens at a higher level (like in the framework level - NestJS)