Skip to content

the-guild-org/yoga-cloudflare-workers-template

Repository files navigation

GraphQL Yoga for Cloudflare Workers (Wrangler template)

Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience:

  • Easiest way to run a GraphQL server: Sensible defaults & includes everything you need with minimal setup (we also export a platform/env-agnostic handler so you can build your own wrappers easily).
  • Includes Subscriptions: Built-in support for GraphQL subscriptions using Server-Sent Events.
  • Compatible: Works with all GraphQL clients (Apollo, Relay...) and fits seamless in your GraphQL workflow.
  • WHATWG Fetch API: the core package depends on WHATWG Fetch API so it can run and deploy on any environment (Serverless, Workers, Deno, Node).
  • Easily Extendable: New GraphQL-Yoga support all envelop plugins.

See it in action!


Read the 2.0 announcement blog post

Read the docs

Deploy to Cloudflare Workers

 


 

Getting started

  1. Install and configure wrangler
npm i @cloudflare/wrangler -g

wrangler login
  1. Create a new project with the GraphQL Yoga template
 wrangler generate graphql-yoga-worker https://github.com/the-guild-org/yoga-cloudflare-workers-template
  1. Build and deploy your CF Worker GraphQL API
cd graphql-yoga-worker
wrangler build
wrangler publish

 


 

Project overview

Yoga configuration

GraphQL Yoga comes with defaults for CORS and error handling:

  • CORS are enabled by default
  • Automatically masking unexpected errors and preventing sensitive information leaking to clients.

Yoga also brings support (with no additional dependency) for subscriptions, file uploads and your favourite schema building library (GraphQL Tools, Pothos, Nexus, TypeGraphQL, SDL first schema-design approaches, graphql-js, Apollo Tools).

More information on all available features on the official documentation.

 

Envelop Plugins

GraphQL Yoga is built on top of Envelop. Envelop is a library that helps build GraphQL API faster and flexibly with plugin-based architecture.

Similar to Express middlewares allowing you to customize requests' behavior, Envelop applies the same idea to GraphQL requests.

By exposing hooks in all the phases of a GraphQL Request execution, Envelop enables the creation of plugins that simplify the setup of standard API features such as:

  • Security: Depth limits, Rate limiting
  • Authentication
  • Advanced caching
  • Error handling: Sentry, error masking
  • Monitoring: Hive
  • Logging
  • Tracing: NewRelic, Datadog, StatsD, Apollo Tracing

More information on Envelop documentation.

Note: Some Node.js specific plugins such as useSentry() are supported in Serverless environments

 

Caching

GraphQL Yoga is relying on fetch() WHATWG Fetch API, allowing you to leverage Cloudflare Cache when fetching data from external services.

For more advanced use-cases, please refer to the useResponseCache() Envelop plugins, with a Redis cache (memory cache is not supported on Serverless).

 

Bundle size

GraphQL Yoga bundle is 36% lighter than Apollo Cloudflare Server (Wrangler bundled script comparison), leading is a faster startup and deployment time. ⚡️

 


 

Going futher

 


 

License

This project is licensed with the MIT License.

About

CF Workers Wrangler GraphQL Yoga template 📦 🚀

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published