@wyrly/yoga
v2.3.1
Published
Request-scoped dependency injection adapter for GraphQL Yoga 5 and TypeScript
Maintainers
Readme
@wyrly/yoga
Request-scoped dependency injection for GraphQL Yoga 5 without reflect-metadata — use
yogaDIPlugin() and yogaContext() for one scope per GraphQL request.
Japanese: README.ja.md
Install
npm install @wyrly/yoga @wyrly/graphql @wyrly/core graphql-yogaPeer dependency: graphql-yoga ^5.0.0.
Requirements
- Everything required by
@wyrly/coreand@wyrly/graphql - GraphQL Yoga 5.x
Quick start
import { createSchema, createYoga } from "graphql-yoga";
import { yogaContext, yogaDIPlugin, type YogaServerContext } from "@wyrly/yoga";
import { createContainer } from "@wyrly/core";
const container = createContainer();
const yoga = createYoga<YogaServerContext>({
schema: createSchema({ typeDefs, resolvers }),
plugins: [yogaDIPlugin(container, {
configureScope(scope) {
// map request → port tokens (e.g. CurrentUserToken)
},
})],
context: yogaContext,
});Resolvers use ctx.wyrly.di.resolve(...). The plugin disposes the scope on onResponse.
Documentation
Related packages
| Package | npm | Description |
| ---------------- | -------- | --------------------- |
| @wyrly/core | yes | Core DI |
| @wyrly/next | yes | Next.js App Router |
| @wyrly/express | yes | Express 5 middleware |
| @wyrly/hono | yes | Hono middleware |
| @wyrly/fastify | yes | Fastify 5 plugin |
| @wyrly/fresh | JSR only | Fresh 2.x |
| @wyrly/graphql | yes | GraphQL request scope |
| @wyrly/yoga | yes | This package |
| @wyrly/apollo | yes | Apollo Server plugin |
License
Apache-2.0 — see LICENSE.
