Integration with Cloudflare Workers
GraphQL Yoga v4 documentation (superseded by v5): GraphQL Yoga provides you a cross-platform GraphQL Server. So you can easily integrate it into any platform besides Node.js.
GraphQL Yoga 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.
You will want to use the package graphql-yoga which has an agnostic HTTP handler using
Fetch API’s
Request and
Response objects when building
GraphQL powered Cloudflare Workers.
Watch Episode #48 of
graphql.wtffor a quick introduction to using GraphQL Yoga with Cloudflare Workers, and KV:
Installation
Example with regular fetch event listener
You can also check a full example on our GitHub repository here
Example with Modules Approach
Access to environmental values (KV Namespaces etc.)
You can access your KV namespaces etc through the context.
If you need ExecutionContext as well inside your resolvers, you can extend the context type like
below;
You can also check a full example on our GitHub repository here
Enabling Subscriptions
For a library enabling topic-based subscriptions using GraphQL Yoga, graphql-ws, see
graphql-workers-subscriptions. This
library uses Durable Objects and D1 to manage the subscriptions state.
Compatibility for Server Sent Events
In order to enable Server Sent Events based subscriptions with Cloudflare Workers, make sure you
have set the compatibility date in your wrangler configuration file to a date after 2022-11-30 (if
that’s not possible, add compatibility flag streams_enable_constructors).
Debug Logging
You should expose DEBUG variable in your environment to enable more verbose logging from GraphQL
Yoga application.