Yoga

GraphQL Yoga is a batteries-included cross-platform GraphQL over HTTP spec-compliant GraphQL server powered by Envelop and GraphQL Tools that runs anywhere; focused on easy setup, performance and great developer experience.

Installation

npm
yarn
pnpm
bun
npm install graphql graphql-yoga @gqloom/core

Usage

import { weave } from "@gqloom/core" import { createServer } from "node:http" import { createYoga } from "graphql-yoga" import { HelloResolver } from "./resolvers" const schema = weave(HelloResolver) const yoga = createYoga({ schema }) createServer(yoga).listen(4000, () => { console.info("Server is running on http://localhost:4000/graphql") })

Contexts

When using GQLoom together with Yoga, you can use YogaInitialContext to label the type of context:

import { useContext } from "@gqloom/core" import { type YogaInitialContext } from "graphql-yoga" export function useAuthorization() { return useContext<YogaInitialContext>().request.headers.get("Authorization") }

You can also learn more about contexts in the Yoga documentation.