6.7 KiB
6.7 KiB
@suaveplan/api-graphql-yoga — GraphQL Yoga engine adapter for @suaveplan/api-graphql. Default GraphQL engine per design doc §10.5. Implements the abstract GraphqlEngine contract from @suaveplan/api-graphql via createYogaGraphqlEngine(opts) — Zod-validated YogaGraphqlOptions, federation through @graphql-tools/schema makeExecutableSchema, schema-collision detection delegated to the canonical GRAPHQL.SCHEMA_COLLISION code, per-request DataLoader scoping bound to RequestContext, depth + complexity guards, masked errors / introspection toggles, graphql-ws subscription transport over an injected api-ws broker, OTel instruments (requests counter, request duration histogram, resolver duration histogram, subscriptions_active gauge, schema_rebuilds counter), 10 GRAPHQL_YOGA_* error codes, and a ./testing subpath re-exporting runGraphqlEngineConformance bound to the Yoga factory.
Stage-7 GraphQL Yoga engine adapter. Default GraphQL engine for the
Suaveplan API plugin system per design doc §10.5 — Bun-friendly,
fastest for our usage pattern, and simpler to operate than Apollo
Server. Implements the abstract GraphqlEngine contract from
@suaveplan/api-graphql so the same conformance suite
(runGraphqlEngineConformance) passes against this adapter and any
future engine; swapping engines is host-config-only.
Documentation tree
- execute-helpers — Houses the smaller execution helpers the Yoga engine uses on every request, kept out of
yoga-engine.tsso the orchest… - yoga-engine — Implements the abstract
GraphqlEnginecontract from@suaveplan/api-graphqlover the Yoga /graphql-jsstack. The… - error-codes — Defines the frozen
GRAPHQL_YOGA.*error-code registry and theGraphqlYogaErrorsubclass ofSuaveplanErrorused th…- error-codes — Defines the frozen
GRAPHQL_YOGA.*error-code registry and theGraphqlYogaErrorsubclass ofSuaveplanErrorused th…
- error-codes — Defines the frozen
- federation — Aggregates plugin-side
GraphqlRegistrycontributions into a single(MergedSchema, ResolverMap)pair that the Yoga e…- federation — Aggregates plugin-side
GraphqlRegistrycontributions into a single(MergedSchema, ResolverMap)pair that the Yoga e…
- federation — Aggregates plugin-side
- guards — Implements the static depth + complexity guard that the Yoga engine runs after parsing each query and before execution.…
- depth-and-complexity — Implements the static depth + complexity guard that the Yoga engine runs after parsing each query and before execution.…
- instruments — Builds and caches the OpenTelemetry instrument bundle the Yoga GraphQL engine emits per request. The bundle covers a co…
- instruments — Builds and caches the OpenTelemetry instrument bundle the Yoga GraphQL engine emits per request. The bundle covers a co…
- loaders — Defines the per-request loader bag the Yoga engine constructs at pipeline step 7 and disposes at step 11. Two concurren…
- loaders — Defines the per-request loader bag the Yoga engine constructs at pipeline step 7 and disposes at step 11. Two concurren…
- options — Defines
YogaGraphqlOptions, the Zod-validated configuration boundary that hosts use to wirecreateYogaGraphqlEngine…- options — Defines
YogaGraphqlOptions, the Zod-validated configuration boundary that hosts use to wirecreateYogaGraphqlEngine…
- options — Defines
- subscriptions — Bridges the
WsBrokercontract from@suaveplan/api-wsto GraphQLSubscriptionresolvers via `AsyncIterable<Payload…- subscriptions — Bridges the
WsBrokercontract from@suaveplan/api-wsto GraphQLSubscriptionresolvers via `AsyncIterable<Payload…
- subscriptions — Bridges the
- testing — Binds the abstract
runGraphqlEngineConformancefrom@suaveplan/api-graphql/testingto the Yoga engine factory so co…- testing — Binds the abstract
runGraphqlEngineConformancefrom@suaveplan/api-graphql/testingto the Yoga engine factory so co…
- testing — Binds the abstract
Modules
- engine —
createYogaGraphqlEngine(config)+ helpers (maskOrPassthrough,withTimeout,assertIntrospectionAllowed,wrapSubscription). - federation —
federatePlugins(entries)aggregating multiple plugin contributions into one(MergedSchema, ResolverMap)pair viamergeSdlfrom@suaveplan/api-graphql. - options — Zod-validated
YogaGraphqlOptions+resolveYogaGraphqlOptionswith safe defaults (endpoint: "/graphql",maxQueryDepth: 10,maxQueryComplexity: 1000,timeoutMs: 30000,maskedErrors: true). - guards —
enforceGuards(doc, { maxDepth, maxComplexity })static depth + complexity rejection. - loaders —
buildRequestLoaders(factories)per-request DataLoader bag bound toRequestContext. - subscriptions —
subscribeBrokerTopic(broker, topic, tenant)bridgesapi-wsto GraphQLAsyncIterable. - instruments —
getYogaInstruments()OTel counter / histogram / gauge bundle. - error-codes — 10
GRAPHQL_YOGA.*codes +GraphqlYogaError. - testing —
runYogaConformance(label?, config?)bound conformance harness.
Quick start
import { createGraphqlRegistry } from "@suaveplan/api-graphql";
import { createYogaGraphqlEngine } from "@suaveplan/api-graphql-yoga";
const engine = createYogaGraphqlEngine();
const reg = createGraphqlRegistry();
reg.addTypes("type Query { ping: String! }");
reg.addResolvers({ Query: { ping: () => "pong" } });
engine.buildSchema(reg);
const result = await engine.executeQuery({ query: "{ ping }" }, ctx);
Why this engine?
- Bun runtime parity — graphql-yoga is a thin layer over
graphql-jsand runs natively under Bun without polyfills. - WebSocket subscriptions over
api-ws—graphql-wsprotocol bridged to the WS broker viasubscribeBrokerTopic. - Per-request DataLoader scoping — design doc §10.3 mandates
per-request DataLoader instances; the
buildRequestLoadershelper enforces this at the engine boundary. - Depth + complexity guards — denial-of-service rejection before resolvers run.
- Masked error mode — flips production error messages to
"Unexpected error."while preserving thepathfor log-side debugging.
License
MIT — Suaveplan Team.