Code Monkey home page Code Monkey logo

yoga-cloudflare-workers-template's Introduction

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.

yoga-cloudflare-workers-template's People

Contributors

charlypoly avatar ardatan avatar

Stargazers

Tuval Simha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.