apollographql / apollographql/federation

RFC: Cache entities during request if keys match across services

Open
#369 0 comments 3 reactions 1 assignee Assigned to @jbaxleyiii View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

Since the idea behind `keys` in federation is that they represent a unique identity, over the course of a single request (for now), we should be able to put potential cache points into the query plan to be evaluated during a request. Take for example a request that goes to the same services at different levels in the tree:

```graphql
{
topProducts{
name
weight
reviews{
body
product {
name
weight
}
}
}
}
```

If the result of `topProducts` brings back entities `{ __typename: "Product", sku: "1234" }`, `{ __typename: "Product", sku: "4567" }` *and* the result of reviews is the *same* result, instead of refetching `name` and `weight` from the products service again, we can use the cached fields and return right away.

This may be a mirco optimization because if there are any additional fields we still need to make a fetch to that service. We could perhaps filter out cached fields in that case though to prevent potentially expensive fields from being done again.

Would this be a suprising set of behavoirs? It matches what the client would do when normalizing deeply nested entities with key matches so the data will be merged together at some point in the experience.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.