graphql-yoga
БесплатноБез исполняемых скриптовНе проверенGraphQL Yoga is a fully featured GraphQL server from The Guild that runs on any JavaScript runtime (Node.js, Bun, Deno, Cloudflare Workers, AWS Lambda). Use…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
GraphQL Yoga
Overview
GraphQL Yoga (v5) is a spec-compliant GraphQL server built on the WHATWG Fetch API, so the same yoga object works as a Node http handler, a Fetch handler (yoga.fetch) in Workers, Bun and Deno, or behind Express, Fastify and Next.js. It is extended with Envelop plugins. It ships with GraphQL over SSE subscriptions, multipart file uploads, CORS, GraphiQL and error masking; you add caching, rate limiting and depth limits as plugins. Schemas can be written with createSchema (SDL plus resolvers) or with code-first builders such as Pothos.
Instructions
- Install:
npm install graphql-yoga graphql. - Build the schema with
createSchema({ typeDefs, resolvers }), pass it tocreateYoga, and hand the result tocreateServerfromnode:http. The endpoint defaults to/graphql; change it withgraphqlEndpoint. - Per-request state (database handle, current user) goes in the
contextoption, which receives{ request }(a FetchRequest) plus runtime-specific fields such asreq/reson Node. - Subscriptions: use
createPubSub()exported bygraphql-yoga;pubSub.publish(topic, payload)andpubSub.subscribe(topic)(an async iterable). Clients connect over SSE by default; no WebSocket server is needed. For several instances, back the pub/sub with Redis using@graphql-yoga/redis-event-target. - File uploads: declare
scalar Filein the schema and acceptFile!arguments. The value is a standardFile/Blob(.text(),.arrayBuffer(),.stream()). Multipart parsing is on by default;multipart: falseturns it off. - Errors: Yoga masks unexpected errors by default. Throw
GraphQLError(fromgraphql) withextensions.codefor errors clients should see.maskedErrors: falsedisables masking (development only). WithNODE_ENV=developmentthe original error appears inextensions.originalError. - GraphiQL is enabled only in development by default; set
graphiql: falseor a function to control it. - Plugins go in
plugins: []. Packages verified to exist:@graphql-yoga/plugin-response-cacheexportsuseResponseCache({ session, ttl, invalidateViaMutation });ttlis milliseconds,sessionreturns a string per user ornullfor a global cache.@envelop/rate-limiterexportsuseRateLimiter({ identifyFn }); limits are declared in the schema with the@rateLimit(max: 10, window: "5s")directive (you must define the directive in your SDL).@envelop/depth-limitexportsuseDepthLimit({ maxDepth }).@escape.tech/graphql-armor-max-depthis an alternative.
Examples
Example 1: Users API with SSE subscription and masked errors
Request: "Build a GraphQL API on port 4000 where clients can list users and get notified when one is created."
// server.ts
import { createServer } from "node:http";
import { GraphQLError } from "graphql";
import { createPubSub, createSchema, createYoga } from "graphql-yoga";
const pubSub = createPubSub<{ userCreated: [user: { id: string; name: string }] }>();
const users = [{ id: "1", name: "Maria Lopez" }];
const yoga = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type User { id: ID! name: String! }
type Query { users: [User!]! user(id: ID!): User }
type Mutation { createUser(name: String!): User! }
type Subscription { userCreated: User! }
`,
resolvers: {
Query: {
users: () => users,
user: (_, { id }) => {
const found = users.find((u) => u.id === id);
if (!found) throw new GraphQLError(`User ${id} not found`, { extensions: { code: "NOT_FOUND" } });
return found;
},
},
Mutation: {
createUser: (_, { name }) => {
const user = { id: String(users.length + 1), name };
users.push(user);
pubSub.publish("userCreated", user);
return user;
},
},
Subscription: {
userCreated: { subscribe: () => pubSub.subscribe("userCreated"), resolve: (u) => u },
},
},
}),
cors: { origin: ["https://app.northwind.dev"], credentials: true },
});
createServer(yoga).listen(4000, () => console.log("http://localhost:4000/graphql"));
Run with npx tsx server.ts. Opening http://localhost:4000/graphql shows GraphiQL; { user(id: "9") { name } } returns the NOT_FOUND error message, while a thrown plain Error comes back as "Unexpected error.".
Example 2: Cache, depth limit and a test without a network
Request: "Cache public queries for a minute and reject queries nested deeper than 8 levels."
npm install @graphql-yoga/plugin-response-cache @envelop/depth-limit
import { createSchema, createYoga } from "graphql-yoga";
import { useResponseCache } from "@graphql-yoga/plugin-response-cache";
import { useDepthLimit } from "@envelop/depth-limit";
export const yoga = createYoga({
schema: createSchema({ typeDefs, resolvers }),
plugins: [
useResponseCache({
Установить graphql-yoga в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл graphql-yoga?
GraphQL Yoga is a fully featured GraphQL server from The Guild that runs on any JavaScript runtime (Node.js, Bun, Deno, Cloudflare Workers, AWS Lambda). Use this skill when asked to build a GraphQL API with graphql-yoga, add subscriptions, file uploads, response caching, depth limits, rate limiting or error masking, or move from Apollo Server to Yoga and Envelop plugins.
Как установить скилл graphql-yoga?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл graphql-yoga запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic