BoilerPrompt
Claude Code

Claude Code prompt to build a GraphQL API

GraphQL schemas drift from their resolvers when both are written in parallel. This prompt has Claude Code validate schema.graphql before any resolver exists, then prove the finished server with a curl introspection query from the terminal. You get cursor pagination, dataloaders against your database, and depth limits, all confirmed by tests the agent runs itself.

Last updated

Prompt
Add a GraphQL API to this repo in {{language}}. Define the schema first in schema.graphql: a Query type with paginated lists, a Mutation type for create and update, and one connection-style type for {{resource}} with cursor pagination. Wire resolvers to {{database}} with a dataloader per parent-child relation so nested queries do not N+1. Reject queries deeper than 6 levels and add a 30-second timeout per operation. Before writing resolvers, run the schema through the linter or validation step and fix any errors. Then write resolver tests covering pagination cursors, a nested query, and a mutation with invalid input. Run the tests. Finally start the server, POST an introspection query with curl, and paste the type names returned so I can confirm the schema is actually being served.

Customize it

Runs in your browser. Nothing you type here is sent anywhere.

Your customized prompt
Add a GraphQL API to this repo in TypeScript. Define the schema first in schema.graphql: a Query type with paginated lists, a Mutation type for create and update, and one connection-style type for users with cursor pagination. Wire resolvers to PostgreSQL with a dataloader per parent-child relation so nested queries do not N+1. Reject queries deeper than 6 levels and add a 30-second timeout per operation. Before writing resolvers, run the schema through the linter or validation step and fix any errors. Then write resolver tests covering pagination cursors, a nested query, and a mutation with invalid input. Run the tests. Finally start the server, POST an introspection query with curl, and paste the type names returned so I can confirm the schema is actually being served.

Same task in other tools

Questions about this prompt

How does Claude Code confirm the schema is served without a GraphQL playground?

It POSTs a plain introspection query with curl and reads the JSON response in the terminal. That check catches a server that boots but serves a stale or empty schema, which a green unit test run can miss.

My API needs subscriptions. How do I extend this prompt?

Add a line asking for a Subscription type over WebSockets and tell the agent to verify it with a small client script it writes and runs itself. Keep the depth limit; subscriptions are just as easy to abuse with deep selections.

The resolver tests pass but nested queries still hammer the database. What is the fix?

Ask the agent to turn on statement logging during the nested-query test and count the queries executed. If the count scales with the number of child rows, the dataloader is not actually batching, and the log shows exactly which resolver bypasses it.

Related prompts