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
sh
npm i graphql graphql-yoga @gqloom/core
sh
pnpm add graphql graphql-yoga @gqloom/core
sh
yarn add graphql graphql-yoga @gqloom/core
sh
bun add graphql graphql-yoga @gqloom/core
Usage
ts
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:
ts
import { useContext } from "@gqloom/core/context"
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.