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

Add a way to access context headers in the cache key for caching #1771

Open
paales opened this issue Mar 10, 2021 · 1 comment
Open

Add a way to access context headers in the cache key for caching #1771

paales opened this issue Mar 10, 2021 · 1 comment

Comments

@paales
Copy link

paales commented Mar 10, 2021

Is your feature request related to a problem? Please describe.

I'm trying to add caching to one of our requests that is requested very often and I want to add a request header to the cache key. We're adding headers like { "store": "nl_NL" }

To achieve this I presume I need to access the context, but the documentatino doesn't mention anything about it. https://graphql-mesh.com/docs/transforms/cache

I've tried using the context but that doesn't work:
{typeName}-{fieldName}-{argsHash}-{fieldNamesHash}-{context.req.headers.store}

It seems it isn't used for calculating the cache key https://github.com/Urigo/graphql-mesh/blob/master/packages/transforms/cache/src/compute-cache-key.ts

Describe the solution you'd like

Pass the context to the computeCacheKey method and make it available
https://github.com/Urigo/graphql-mesh/blob/master/packages/transforms/cache/src/index.ts#L37-L42

Describe alternatives you've considered

Maybe it is already possible in some way, but would be nice if there was a mention in the docs somewhere :)

Additional context

@paales
Copy link
Author

paales commented Mar 15, 2021

Although the issue is still valid that it isn't able to use headers, we've found a workaround (do some caching at the ApolloClient)

@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant