Skip to Content

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.

index.js
import { createGatewayRuntime } from '@graphql-hive/gateway-runtime' import http from '@graphql-mesh/transport-http' import supergraph from './supergraph' export default { async 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. } }) const response = await gateway(request, env, ctx) ctx.waitUntil(gateway[Symbol.asyncDispose]()) return response } }
supergraph.js
export default /* GraphQL */ ` PLACE YOUR SUPERGRAPH SDL HERE `
💡

The example above does not support streaming responses because Hive Gateway is being disposed immediatelly after assembling a response with ctx.waitUntil(gateway[Symbol.asyncDispose]()).

If you want to use Cloudflare KV Cache as a distributed cache, see here for Hive Gateway integration

Last updated on