Skip to content

@graphql-yoga/plugin-response-cache: Support more advanced use cases #3018

@klippx

Description

@klippx

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

I am trying out Yoga as an alternative to Apollo Server 4, and when it comes to response cache plugin the one in Yoga is a more crude version that doesn't have any means to support the following API:

  • extraCacheKeyData
  • calculateCacheKey
  • shouldReadFromCache and shouldWriteToCache

Describe the solution you'd like

  • extraCacheKeyData(requestContext): any - Ability to give a hook for adding an extra key with value being result of callback, which internally is passed to buildResponseCacheKey({ ...original, extra })
  • calculateCacheKey(requestContext): string - Ability to alter cache key used for reading and writing to cache, if this is passed use const key = calculateCacheKey ? ${originalKey}:${calculateCacheKey(requestContext)} : originalKey.
  • shouldReadFromCache abd shouldWriteToCache - Ability to skip response cache altogether, such as based on header (might not need a code change)*

Describe alternatives you've considered

  • calculateCacheKey might be might be more of a @envelop/response-cache-redis concern, and as such I might have been able to use buildRedisOperationResultCacheKey, but it is not yielding requestContext. Still we might want to split this feature request to that library instead.
    *) I think shouldReadFromCache abd shouldWriteToCache can be combined into simply "skip cache", since we are always using them together and set to the same value. But we might not even need support for these in the plugin itself, as we can just skip adding this plugin altogether instead.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions