1.0.0 • Published 12 months ago
@envelop/response-cache-cloudflare-kv v1.0.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
1 year ago
1.0.0-rc-20240530090315-3f53c9ae
1 year ago
2.0.0-alpha-20240710083620-c72a7363
12 months ago
1.0.0-alpha-20240528123234-3c46a732
1 year ago
1.0.0-alpha-20240528125003-40868c0a
1 year ago
1.0.0-alpha-20240521101342-eee91c9e
1 year ago
1.0.0-alpha-20240520005426-b564cd8c
1 year ago
1.0.0-alpha-20240520005117-b223e41e
1 year ago
1.0.0-alpha-20240520012656-b65698be
1 year ago
1.0.0-alpha-20240520012535-958154ca
1 year ago
1.0.0-alpha-20240520012914-ec8b800d
1 year ago
0.3.0-rc-20231211142933-7c78406c
2 years ago
0.3.0
2 years ago
0.3.0-rc-20231205134927-52c0c7aa
2 years ago
0.2.0
2 years ago
0.2.0-rc-20231129135023-c1061216
2 years ago
0.2.0-rc-20231129122801-9ed76821
2 years ago
0.2.0-rc-20231128131945-833698cd
2 years ago
0.2.0-rc-20231128112619-1404511c
2 years ago
0.2.0-alpha-20231128112402-67e67d27
2 years ago
0.2.0-alpha-20231128065430-b797a636
2 years ago
0.2.0-rc-20231127224731-0e06125a
2 years ago
0.2.0-alpha-20231127183231-755a9263
2 years ago
0.2.0-rc-20231123223914-59d39f0c
2 years ago
0.2.0-alpha-20231123205054-9ec62b45
2 years ago
0.2.0-alpha-20231123204051-31c02e29
2 years ago
0.2.0-rc-20231123190818-f8c5d745
2 years ago
0.2.0-alpha-20231123160442-fe0c16d2
2 years ago
0.2.0-alpha-20231123153631-1b5c7a3a
2 years ago
0.2.0-alpha-20231123145702-0da4fcd7
2 years ago
0.2.0-alpha-20231123130839-6a4e30b3
2 years ago
0.2.0-alpha-20231123130339-1ece3a04
2 years ago
0.2.0-rc-20231123043420-229b0ff3
2 years ago
0.2.0-alpha-20231123022747-9f743dd6
2 years ago
0.2.0-alpha-20231121075802-ad62fcc6
2 years ago
0.2.0-rc-20231120231418-680b215d
2 years ago
0.2.0-alpha-20231120195704-b6fb8dd7
2 years ago
0.2.0-alpha-20231120110035-d6b9d686
2 years ago
0.2.0-rc-20231120105936-223732b8
2 years ago
0.2.0-alpha-20231106140646-27776100
2 years ago