graphql-hive / graphql-hive/envelop
`@envelop/response-cache-cloudflare-kv` has mismatched types with `useResponseCache` plugin
- Dominant language
- No language data
- Stars
- 827
- Forks
- 132
- PR merge metrics
- No merged PRs in 30d
Description
### Issue workflow progress
_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_
- [X] 1. The issue provides a
[minimal reproduction](https://en.wikipedia.org/wiki/Minimal_reproducible_example) available on
[Stackblitz](https://stackblitz.com/fork/node).
- _Please install the latest `@envelop/*` packages that you are using._
- _Please make sure the reproduction is as small as possible._
- [ ] 2. A failing test has been provided
- [ ] 3. A local solution has been provided
- [ ] 4. A pull request is pending review
---
**Describe the bug**
The response cache plugin for Cloudflare KV Store(`@envelop/response-cache-cloudflare-kv`). Is not working as expected. There seems to be an internal type mismatch which leads to the following error messages below:
Typescript error during development
```ts
Type '(ctx: { MY_KV_STORE: KVNamespace; } & { waitUntil(promise: Promise): void; }) => Cache' is not assignable to type 'Cache'.ts(2322)
index.d.ts(9, 5): The expected type comes from property 'cache' which is declared here on type 'UseResponseCacheParameter'
```
Runtime error
```bash
✘ [ERROR] ERR TypeError: cache2.get is not a function
at responseWithSymbol
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:59)
at _handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:6:24)
at handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:19:16)
at null.
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:28)
ERR TypeError: cache2.get is not a function
at responseWithSymbol
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:59)
at _handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:6:24)
at handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:19:16)
at null.
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:28)
[wrangler:inf] POST /graphql 500 Internal Server Error (104ms)
✘ [ERROR] ERR TypeError: cache2.get is not a function
at responseWithSymbol
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:59)
at _handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:6:24)
at handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:19:16)
at null.
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:28)
✘ [ERROR] ERR TypeError: cache2.get is not a function
at responseWithSymbol
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:59)
at _handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:6:24)
at handleMaybePromise
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@whatwg-node+promise-helpers@1.2.4/node_modules/@whatwg-node/promise-helpers/esm/index.js:19:16)
at null.
(file:///workspaces/response-cache-repoduction/node_modules/.pnpm/@graphql-yoga+plugin-response-cache@3.15.2_graphql-yoga@5.13.1_graphql@16.10.0__graphql@16.10.0/node_modules/@graphql-yoga/plugin-response-cache/esm/index.js:101:28)
```
**To Reproduce** Steps to reproduce the behavior:
1. Set up a project following the details [here](https://github.com/n1ru4l/envelop/tree/main/packages/plugins/response-cache-cloudflare-kv#usage-example)
**Expected behavior**
Expected the types to match
**Environment:**
- OS: Debian GNU/Linux 12 (bookworm) via Docker(WSL)
- NodeJS: v22.14.10
- `@envelop/*` versions:
- `"@envelop/response-cache-cloudflare-kv": "^3.1.3"`
**Additional context**
- Stackblitz reproduction can be found [here](https://stackblitz.com/edit/stackblitz-starters-xzbuyjcw?file=src%2Findex.ts)
- Possible relation to issue #2104
- Tried solutions in issue above. Such as removing the global definition of cloudflare types from tsconfig.json
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the usage example in packages/plugins/response-cache-cloudflare-kv and the reproduction in src/index.ts. Compare the cache type reported at index.d.ts:9 with the useResponseCache parameter and trace the runtime failure at responseWithSymbol, where cache2.get is called. Done means the Cloudflare KV integration has matching types and the reproduction no longer raises the cache2.get runtime error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, node.js, typescript
- Domain
- api, backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100