Coding
AI Prompt for REST-to-GraphQL
Convert REST to GraphQL with this AI prompt: client-driven schema design, N+1-safe resolvers with batching, and a reversible strangler migration plan.
The prompt
Role: You are a GraphQL architect who designs schemas around client needs, not server tables. Context: From: REST ([ENDPOINT_LIST]). To: GraphQL ([GRAPHQL_SERVER]). Clients: [CLIENTS]. Pain to solve: [PAIN, e.g. mobile over-fetching, many round trips]. Task: 1) Design the GraphQL schema: types, queries, mutations — shaped by what [CLIENTS] need together, not 1:1 with REST endpoints. 2) Map each REST endpoint to its GraphQL equivalent. 3) Implement the resolvers with DataLoader/batching to avoid N+1. 4) Design the migration: strangler approach (GraphQL gateway over REST first?) with steps. 5) Note what GraphQL does WORSE than your REST (caching, file uploads) and the mitigations. Format: Schema first, then the endpoint map, then resolvers, then migration steps, then the honest trade-offs. Constraints: Design for the clients' query patterns — show 2 realistic client queries the schema serves well. N+1-safe resolvers are mandatory, not optional. Do not expose the database schema as the GraphQL schema.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[ENDPOINT_LIST] [GRAPHQL_SERVER] [CLIENTS] [PAIN]
Example input
FROM=REST (GET /orders, POST /orders, GET /orders/:id), TO=GraphQL, STACK=Node.js Apollo, CLIENTS=mobile app over slow networks
How to use this prompt
List the REST endpoints AND what data clients actually need together — GraphQL schema design follows client queries. Name the pain (over-fetching) you want solved.
Tips for the best results
- Start with the client queries, not the REST endpoints — schema follows usage.
- Ask for the DataLoader implementation; N+1 will bite on day one otherwise.
- Read the trade-offs section before committing; GraphQL has real costs.
Frequently asked questions
Is it just wrapping REST?
It designs the schema around your clients' data needs and maps each REST endpoint — then warns about the REST habits that don't translate.
Should I migrate all endpoints at once?
No — strangler pattern: GraphQL gateway over REST first, migrate endpoint by endpoint. The prompt sequences the migration for zero-downtime.