This can require combining the type of the object (queried with _typename) with some type-unique identifier.ĭhaivat Pandya wrote and spoke extensively back in 2016 about how Apollo was tackling caching. Having the server derive that id simplifies the client but the client can also derive the identifier. The client needs to derive a globally unique identifier for their caching. The GraphQL API can expose the previous API in a separate field and GraphQL clients can rely on a consistent mechanism for getting a globally unique identifier. How will a client using the GraphQL API work with existing APIs? It will be tricky if our existing API accepts a type-specific id while our GraphQL API uses globally unique identifiers. In simple cases this involves appending the name of the type to the ID and using that as the identifier. But a globally unique identifier will need to be provided by the GraphQL layer if it is not provided by the backend. This is simple if the backend uses a UUID. The id field provides a globally unique key. One possible pattern for this is reserving a field ( id).Įnter fullscreen mode Exit fullscreen mode Since GraphQL lacks a URL-like primitive the API usually exposes a globally unique identifier for clients to use. A historical response can be returned if possible. ![]() Previous responses to GET requests can be cached and future requests can be routed through the cache. Only the combination of those two parameters will run a particular procedure on the server. It can be leveraged by the client to build a cache by identifying when two resources are the same. Validation is a way for clients to avoid refetching data when they’re not sure if the data is still fresh or not (through Last-Modified and Etags)Ĭlients can use HTTP caching to easily avoid refetching resources in an endpoint-based API.Freshness lets the server transmit the time a resource should be considered fresh (through Cache-Control and Expires headers) and works well for data that doesn’t change often.Gateway caches are deployed along with a server to check if the information is still up to date in the cache to avoid extra requests. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |