Deploying Hive Gateway to Cloudflare Workers
Hive Gateway a provides you a cross-platform GraphQL Server. So you can easily integrate it into any platform besides Node.js.
Cloudflare Workers provides a serverless execution environment that allows you to create entirely new applications or augment existing ones without configuring or maintaining infrastructure.
Before you start, make sure you read the Serverless / On the Edge page.
See Bundling Problems for more details about
how to load the supergraph and transports
option.
In the following example, we showcase how Hive Gateway can be used in a serverless environment with
Cloudflare Workers. Notice how the implementation leverages the using
sytax for
Explicit Resource Management,
this makes sure that the Hive Gateway is gracefully and properly disposed before completing the
worker.
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
import http from '@graphql-mesh/transport-http'
import supergraph from './supergraph'
export default {
fetch(request, env, ctx) {
const gateway = createGatewayRuntime({
// All options available in `gateway.config.ts` configuration can also be passed here.
supergraph,
transports: {
http // http transport is required for subgraphs using standard GraphQL over HTTP.
}
})
ctx.waitUntil(gateway[Symbol.asyncDispose]())
return gateway(request, env, ctx)
}
}
export default /* GraphQL */ `
PLACE YOUR SUPERGRAPH SDL HERE
`
If you want to use Cloudflare KV Cache as a distributed cache, see here for Hive Gateway integration