BoilerPrompt
GitHub Copilot

GitHub Copilot prompt to build a GraphQL API

Schema-first GraphQL work suits chat that can hold a contract file in context. This prompt has GitHub Copilot write schema.graphql before any resolver, then keeps every follow-up pinned to it with a #file reference, so the API you get matches the types you approved instead of drifting resolver by resolver.

Last updated

Prompt
Create a GraphQL API for a book catalog in {{language}}, schema first. Start in schema.graphql: types Book, Author, and Review, a books query with cursor pagination taking first and after, and an addReview mutation returning the updated Book. Then open src/resolvers/ and write one resolver file per type, reading from {{database}} through the existing db module, no raw connection strings. Wire a DataLoader for Author so resolving fifty books issues one author query, not fifty. Mutations must validate that rating sits between 1 and 5 and return a typed error in the payload rather than throwing. Reference #file:schema.graphql in follow-ups so the chat stays anchored to the contract. To verify, I will start the server and run a query fetching ten books with authors while logging SQL, expecting two statements.

Customize it

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

Your customized prompt
Create a GraphQL API for a book catalog in TypeScript, schema first. Start in schema.graphql: types Book, Author, and Review, a books query with cursor pagination taking first and after, and an addReview mutation returning the updated Book. Then open src/resolvers/ and write one resolver file per type, reading from PostgreSQL through the existing db module, no raw connection strings. Wire a DataLoader for Author so resolving fifty books issues one author query, not fifty. Mutations must validate that rating sits between 1 and 5 and return a typed error in the payload rather than throwing. Reference #file:schema.graphql in follow-ups so the chat stays anchored to the contract. To verify, I will start the server and run a query fetching ten books with authors while logging SQL, expecting two statements.

Same task in other tools

Questions about this prompt

Do the resolvers stay in sync with schema.graphql automatically?

No. Chat only sees what is in context, so attach the schema with #file on every follow-up. Without it, Copilot regenerates field names from memory and the resolver map drifts from the SDL.

How do I extend the mutation pattern beyond addReview?

Repeat the payload shape: each mutation returns the changed entity plus a typed error list. Ask for one new mutation at a time with the schema attached and it will copy the established structure.

The DataLoader exists but the author query count did not drop. Why?

The Author field resolver is probably still calling the db module directly. Ask Copilot to show that resolver and route the lookup through the loader, then recheck the SQL log for two statements.

Related prompts