3.1.3 • Published 9 months ago

@envelop/response-cache-cloudflare-kv v3.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@envelop/response-cache-cloudflare-kv

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 the useResponseCache 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
}

const graphqlServer = createYoga<Env & ExecutionContext>({
  schema: createSchema({ typeDefs, resolvers }),
  plugins: [
    useResponseCache({
      cache: createKvCache({
        KVName: 'GRAPHQL_RESPONSE_CACHE',
        keyPrefix: 'graphql' // optional
      }),
      session: () => null,
      includeExtensionMetadata: true,
      ttl: 1000 * 10 // 10 seconds
    })
  ]
})

export default {
  fetch: graphqlServer
}
2.0.0

11 months ago

3.1.3

9 months ago

3.1.2

9 months ago

3.1.1

9 months ago

3.1.0

9 months ago

3.0.0

10 months ago

1.0.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago