Design a GraphQL schema in SDL from your domain and client queries, with input types, pagination, error handling, authorization rules and an N+1-safe resolver plan.
Design a GraphQL API for the domain below. Produce the schema in SDL, plus a separate resolver and authorization plan; SDL describes types and operations, while resolvers are application code. ## Inputs Domain entities, fields and relationships: [ENTITIES] Client screens or queries the API must serve: [CLIENT_QUERIES] Mutations required: [MUTATIONS] Roles and access rules: [ACCESS_RULES] Server stack (for example Apollo Server, GraphQL Yoga, Strawberry, Hot Chocolate): [SERVER_STACK] Existing conventions (ID format, pagination style, error format): [CONVENTIONS] ## Instructions 1. Define object types and relationships with descriptions on types and fields. Use non-null only where the field is always present for every caller allowed to see it. 2. Use custom scalars or dedicated types where built-in scalars lose meaning (for example a Money type with amount and currency instead of Float). 3. Define input types for mutations. Do not accept server-derived values such as prices or totals from clients. 4. Return mutation payload types that include the changed object and user-facing errors, or document the chosen error convention. 5. Add pagination for any list that can grow (cursor connections or the convention in [CONVENTIONS]). 6. Use interfaces or unions only where clients need to query several types through one field. 7. For each field, state the authorization rule from [ACCESS_RULES]. 8. Plan resolvers to avoid N+1 fetching (batching such as DataLoader) and protect the server with depth or complexity limits. ## Return 1. Schema in SDL. 2. Example operations for each item in [CLIENT_QUERIES] and [MUTATIONS], valid against the schema. 3. Resolver plan: data source per field, batching, caching. 4. Authorization table: type/field, rule, enforced where. 5. Open questions and deferred features. ## Acceptance checks - Every example operation validates against the SDL. - No client-supplied price, total or ownership field in inputs. - Every list that can grow is paginated. - Authorization covers every query and mutation.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Entities: Product (name, price, stock), Customer (name, email), Order (items, status, total, createdAt), Review (rating 1-5, text, author) Client queries: product page with reviews; a customer's order history; admin order search by status Mutations: createOrder(items: product IDs and quantities), updateCustomerProfile, submitReview Access rules: customers see only their own orders and profile; anyone can read products and reviews; only customers who bought a product may review it; admins see all orders Server: Apollo Server 4 with PostgreSQL Conventions: cursor pagination
SDL with a Money type, Product.reviews and Customer.orders as cursor connections, a CreateOrderInput containing only productId and quantity per item (no price or total), payload types with a userErrors list, Query.me for the signed-in customer instead of customer(id:) for customers, an admin-only orders(status:) query, and a rating constraint documented on submitReview. The resolver plan batches Review and Product lookups with DataLoader; the authorization table includes the purchase check for reviews. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts: