Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys #6655

Merged
merged 11 commits into from Jul 11, 2022

Conversation

kschrade
Copy link
Contributor

@kschrade kschrade commented Jul 8, 2022

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

Landing in favor of:
#6649
#6428

@changeset-bot
Copy link

changeset-bot bot commented Jul 8, 2022

⚠️ No Changeset found

Latest commit: 1c84a40

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link

netlify bot commented Jul 8, 2022

Deploy Preview for apollo-server-docs canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 1c84a40
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/62cc6c6708e25e0009981662

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 8, 2022

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:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration

Copy link
Member

@glasser glasser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kschrade kschrade requested a review from glasser July 8, 2022 18:59
@kschrade kschrade requested a review from glasser July 11, 2022 17:06
…luginResponseCache.ts

Co-authored-by: Trevor Scheer <trevor.scheer@gmail.com>
Copy link
Member

@trevor-scheer trevor-scheer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Would you please make an addition to CHANGELOG.md?

@trevor-scheer trevor-scheer changed the base branch from main to release-3.10.0 July 11, 2022 18:32
@kschrade kschrade changed the title ✨ Adding new hook for changing the cachekey for the response cache ✨ Adding generateCacheKey to ApolloServerPluginResponseCache to allow for custom cache keys Jul 11, 2022
@trevor-scheer trevor-scheer merged commit 7d6d3ce into apollographql:release-3.10.0 Jul 11, 2022
glasser added a commit that referenced this pull request Jul 11, 2022
- 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.
@glasser glasser mentioned this pull request Jul 11, 2022
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
- 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.
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
…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`
trevor-scheer pushed a commit that referenced this pull request Jul 11, 2022
- 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.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants