0.3.0 • Published 23 hours ago
@envelop/response-cache-cloudflare-kv v0.3.0
@envelop/response-cache-cloudflare-kv
- Supports Cloudflare KV cache for
@envelop/response-cache
plugin - Suitable for graphql servers running on Cloudflare Workers
Check out the GraphQL Response Cache Guide for more information
Getting Started
yarn add @envelop/response-cache
yarn add @envelop/response-cache-cloudflare-kv
Usage Example
In order to use the Cloudflare KV cache, you need to:
- Create a Cloudflare KV namespace
- Add that namespace to your
wrangler.toml
in order to access it from your worker. Read the KV docs to get started. - Pass the KV namespace to the
createKvCache
function and set to theuseResponseCache
plugin options. See the example below.
import { createSchema, createYoga, YogaInitialContext } from 'graphql-yoga'
import { useResponseCache } from '@envelop/response-cache'
import { createKvCache } from '@envelop/response-cache-cloudflare-kv'
import { resolvers } from './graphql-schema/resolvers.generated'
import { typeDefs } from './graphql-schema/typeDefs.generated'
export type Env = {
GRAPHQL_RESPONSE_CACHE: KVNamespace
}
export type GraphQLContext = YogaInitialContext & Env & ExecutionContext
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const kvCache = createKvCache({
KV: env.GRAPHQL_RESPONSE_CACHE,
ctx,
keyPrefix: 'graphql' // optional
})
const graphqlServer = createYoga<GraphQLContext>({
schema: createSchema({ typeDefs, resolvers }),
plugins: [
useResponseCache({
cache: kvCache,
session: () => null,
includeExtensionMetadata: true,
ttl: 1000 * 10 // 10 seconds
})
]
})
return graphqlServer.fetch(request, env, ctx)
}
}
1.0.0-alpha-20240521101342-eee91c9e
23 hours ago
1.0.0-alpha-20240520005426-b564cd8c
2 days ago
1.0.0-alpha-20240520005117-b223e41e
2 days ago
1.0.0-alpha-20240520012656-b65698be
2 days ago
1.0.0-alpha-20240520012535-958154ca
2 days ago
1.0.0-alpha-20240520012914-ec8b800d
2 days ago
0.3.0-rc-20231211142933-7c78406c
5 months ago
0.3.0
5 months ago
0.3.0-rc-20231205134927-52c0c7aa
6 months ago
0.2.0
6 months ago
0.2.0-rc-20231129135023-c1061216
6 months ago
0.2.0-rc-20231129122801-9ed76821
6 months ago
0.2.0-rc-20231128131945-833698cd
6 months ago
0.2.0-rc-20231128112619-1404511c
6 months ago
0.2.0-alpha-20231128112402-67e67d27
6 months ago
0.2.0-alpha-20231128065430-b797a636
6 months ago
0.2.0-rc-20231127224731-0e06125a
6 months ago
0.2.0-alpha-20231127183231-755a9263
6 months ago
0.2.0-rc-20231123223914-59d39f0c
6 months ago
0.2.0-alpha-20231123205054-9ec62b45
6 months ago
0.2.0-alpha-20231123204051-31c02e29
6 months ago
0.2.0-rc-20231123190818-f8c5d745
6 months ago
0.2.0-alpha-20231123160442-fe0c16d2
6 months ago
0.2.0-alpha-20231123153631-1b5c7a3a
6 months ago
0.2.0-alpha-20231123145702-0da4fcd7
6 months ago
0.2.0-alpha-20231123130839-6a4e30b3
6 months ago
0.2.0-alpha-20231123130339-1ece3a04
6 months ago
0.2.0-rc-20231123043420-229b0ff3
6 months ago
0.2.0-alpha-20231123022747-9f743dd6
6 months ago
0.2.0-alpha-20231121075802-ad62fcc6
6 months ago
0.2.0-rc-20231120231418-680b215d
6 months ago
0.2.0-alpha-20231120195704-b6fb8dd7
6 months ago
0.2.0-alpha-20231120110035-d6b9d686
6 months ago
0.2.0-rc-20231120105936-223732b8
6 months ago
0.2.0-alpha-20231106140646-27776100
7 months ago