Pothos GraphQL schema served by GraphQL Yoga: working versions (tested 2026-10-15)
Build a typed GraphQL schema with Pothos (queries and mutations over an in-memory store) and execute it offline through GraphQL Yoga's fetch handler.
passed1 passed · 0 failed2026-10-15 14:59 UTC- Status
- passed
- Last passed
- 2026-10-15 14:59 UTC
- Tests
- 1 / 1
- Language
- TypeScript
- Runtime
- node v22.23.3
npm install --no-audit --no-fund --ignore-scripts=false npm test
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38755782594
The code
Exactly the files that passed. Your agent can pull them with get_recipe("graphql-pothos-yoga-schema") (install), or see them on GitHub.
{
"name": "graphql-pothos-yoga-schema",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"@pothos/core": "4.15.1",
"graphql": "17.0.2",
"graphql-yoga": "5.24.5"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
import SchemaBuilder from "@pothos/core";
import { createYoga } from "graphql-yoga";
type Post = { id: number; title: string; published: boolean };
const posts: Post[] = [];
const builder = new SchemaBuilder<{}>({});
const PostRef = builder.objectRef<Post>("Post");
PostRef.implement({
fields: (t) => ({
id: t.exposeInt("id"),
title: t.exposeString("title"),
published: t.exposeBoolean("published"),
}),
});
builder.queryType({
fields: (t) => ({
posts: t.field({
type: [PostRef],
resolve: () => posts,
}),
post: t.field({
type: PostRef,
nullable: true,
args: { id: t.arg.int({ required: true }) },
resolve: (_r, { id }) => posts.find((p) => p.id === id) ?? null,
}),
}),
});
builder.mutationType({
fields: (t) => ({
createPost: t.field({
type: PostRef,
args: {
title: t.arg.string({ required: true }),
published: t.arg.boolean({ required: true }),
},
resolve: (_r, args) => {
const post = { id: posts.length + 1, title: args.title, published: args.published };
posts.push(post);
return post;
},
}),
}),
});
export const schema = builder.toSchema();
export const yoga = createYoga({ schema, graphqlEndpoint: "/graphql" });
export function reset() { posts.length = 0; }
import { test } from "node:test";
import assert from "node:assert/strict";
import { reset, yoga } from "../src/schema.ts";
async function gql(query: string, variables?: Record<string, unknown>) {
const res = await yoga.fetch("http://local/graphql", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ query, variables }),
});
return { status: res.status, body: await res.json() };
}
test("create and query posts", async () => {
reset();
const created = await gql(
`mutation($title: String!, $published: Boolean!) { createPost(title: $title, published: $published) { id title published } }`,
{ title: "Hello", published: true },
);
assert.equal(created.status, 200);
assert.equal(created.body.data.createPost.title, "Hello");
const listed = await gql(`{ posts { id title } }`);
assert.equal(listed.body.data.posts.length, 1);
const one = await gql(`query($id: Int!) { post(id: $id) { title } }`, { id: 1 });
assert.equal(one.body.data.post.title, "Hello");
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.
Related stacks
GraphQL Yoga 5 schema, context and errors tested via fetch
Build a GraphQL Yoga server with SDL resolvers, per-request context auth and GraphQLError codes, tested in-process with yoga.fetch.
Apollo Server 5 resolvers with per-request DataLoader batching
An Apollo Server 5 schema whose nested resolvers use per-request DataLoader instances to batch and dedupe lookups (no N+1), with GraphQLError extension codes and cache invalidation after a mutation, tested in-process with executeOperation.
graphql-request client with typed operations, mocked by MSW graphql handlers
Call a GraphQL API with graphql-request (variables, headers, error handling) and test offline with MSW's graphql.link(url).query/mutation handlers (msw 3 API). graphql stays on 16.x: graphql-request 7 peers on graphql 14 - 16.
All @pothos/core recipesAll graphql recipesAll graphql-yoga recipes