dotansimha / graphql-yoga

šŸ§˜ Rewrite of a fully-featured GraphQL Server with focus on easy setup, performance & great developer experience. The core of Yoga implements WHATWG Fetch API and can run/deploy on any JS environment.
https://the-guild.dev/graphql/yoga-server
MIT License
8.25k stars 574 forks source link

Incompatible Typescript Cache type when using `createRedisCache` #3048

Open AdamJHall opened 1 year ago

AdamJHall commented 1 year ago

Describe the bug

When using @graphql-yoga/plugin-response-cache plugin, and following the documented example here: https://the-guild.dev/graphql/yoga-server/docs/features/response-caching#external-cache to provide a createRedisCache cache instance causes a Typescript error:

Type 'import("node_modules/@envelop/response-cache/typings/cache").Cache' is not assignable to type 'Cache'.
  The types returned by 'get(...)' are incompatible between these types.
    Type 'PromiseOrValue<Maybe<ExecutionResult<ObjMap<unknown>, ObjMap<unknown>>>>' is not assignable to type 'Promise<ExecutionResult<Record<string, unknown>, ResponseCachePluginExtensions> | undefined>'.
      Type 'undefined' is not assignable to type 'Promise<ExecutionResult<Record<string, unknown>, ResponseCachePluginExtensions> | undefined>'.ts(2322)
index.d.ts(8, 5): The expected type comes from property 'cache' which is declared here on type 'UseResponseCacheParameter'

Your Example Website or App

https://codesandbox.io/p/sandbox/determined-carlos-7qx3nj?file=%2Fsrc%2Fmain.ts%3A32%2C31

Steps to Reproduce the Bug or Issue

Create a Typescript instance of Yoga using the useResponseCache plugin, with the cache option set to a cache instance created with createRedisCache.

Expected behavior

The server should start without any typescript compilation errors.

Screenshots or Videos

No response

Platform

Additional context

Seems to be similar to: https://github.com/dotansimha/graphql-yoga/issues/2905

sutt0n commented 1 week ago

Can confirm, this is still an issue.