✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys#6655
Conversation
|
✅ Deploy Preview for apollo-server-docs canceled.Built without sensitive environment variables
|
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1c84a40:
|
glasser
left a comment
There was a problem hiding this comment.
Please also provide at least a brief mention of this parameter in the docs (docs/source/performance/caching.md). The table in the bottom section seems reasonable. Thanks1
…luginResponseCache.ts Co-authored-by: David Glasser <glasser@apollographql.com>
Co-authored-by: David Glasser <glasser@apollographql.com>
…luginResponseCache.ts Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
trevor-scheer
left a comment
There was a problem hiding this comment.
LGTM! Would you please make an addition to CHANGELOG.md?
generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since the cache key is a string. - Reintroduce CacheKey(Data) removed in #6655; make the GenerateCacheKeyFunction type be defined in terms of it. Now calls to the `const generateCacheKey` function are type-safe (ie, the second arg is a CacheKeyData rather than unknown). - Describe generateCacheKey hook as a method rather than a field, like the other hooks in Options.
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since the cache key is a string. - Reintroduce CacheKey(Data) removed in #6655; make the GenerateCacheKeyFunction type be defined in terms of it. Now calls to the `const generateCacheKey` function are type-safe (ie, the second arg is a CacheKeyData rather than unknown). - Describe generateCacheKey hook as a method rather than a field, like the other hooks in Options.
…for custom cache keys (#6655) Create a new hook (`generateCacheKey`) on the `ApolloServerPluginResponseCache` constructor options which allows users to customize the cache key used by returning their own `string`. The hook receives two arguments: the `requestContext` and an object (`cacheKeyData`) which contains the following properties: `source` `operationName` `variables` `extra` (computed by `options.extraCacheKeyData`) `sessionId` `sessionMode`
- Rename BaseCacheKey and ContextualCacheKey with "Data" on end, since the cache key is a string. - Reintroduce CacheKey(Data) removed in #6655; make the GenerateCacheKeyFunction type be defined in terms of it. Now calls to the `const generateCacheKey` function are type-safe (ie, the second arg is a CacheKeyData rather than unknown). - Describe generateCacheKey hook as a method rather than a field, like the other hooks in Options.
Create a new hook (
generateCacheKey) on theApolloServerPluginResponseCacheconstructor options which allows users to customize the cache key used by returning
their own
string.The hook receives two arguments: the
requestContextand an object (cacheKeyData)which contains the following properties:
sourceoperationNamevariablesextra(computed byoptions.extraCacheKeyData)sessionIdsessionModeLanding in favor of:
#6649
#6428