Design a Complete GraphQL Schema with Types, Queries, and Mutations
Design a fully documented GraphQL schema with types, queries, mutations, subscriptions, pagination, and auth directives for any domain.
๐ The Prompt
You are a senior backend architect specializing in GraphQL API design. Design a complete, well-structured GraphQL schema for a [DOMAIN/APPLICATION] application.
Domain Details:
- Application domain: [DOMAIN/APPLICATION] (e.g., e-commerce platform, project management tool, social media app)
- Core entities: [ENTITY_LIST] (e.g., User, Product, Order, Review)
- Authentication method: [AUTH_METHOD] (e.g., JWT, OAuth 2.0, API key)
- Target backend: [BACKEND_TECH] (e.g., Node.js with Apollo Server, Python with Strawberry, Go with gqlgen)
Design the schema following these requirements:
1. **Type Definitions**: Define GraphQL types for each entity in [ENTITY_LIST]. Include:
- Proper use of ID, String, Int, Float, Boolean, and custom scalar types (e.g., DateTime, URL, Email)
- Enum types where applicable (e.g., OrderStatus, UserRole)
- Interface or union types if entities share common fields
- Proper nullability โ mark fields as non-null (!) only when guaranteed
2. **Relationships**: Model relationships between entities using:
- Nested object types for one-to-one relationships
- Connection-based pagination (Relay cursor specification) for one-to-many and many-to-many relationships
- Include PageInfo type and Edge types
3. **Queries**: Define queries including:
- Fetch single entity by ID (e.g., user(id: ID!): User)
- List queries with filtering, sorting, and cursor-based pagination arguments
- At least one query demonstrating a complex filter input type
4. **Mutations**: Define mutations including:
- Create, update, and delete operations for primary entities
- Use dedicated input types for each mutation (e.g., CreateProductInput)
- Return a payload type with the modified entity and a userErrors field for validation errors
- Include at least one mutation representing a business operation (e.g., placeOrder, assignTask)
5. **Subscriptions**: Add at least two subscription fields for real-time updates relevant to the domain.
6. **Authorization Directives**: Add custom directives (e.g., @auth(requires: ADMIN)) to indicate which roles can access specific queries, mutations, or fields.
7. **Documentation**: Add descriptions (using GraphQL string descriptions) to every type, field, query, mutation, and enum value.
Output the complete schema in SDL (Schema Definition Language) format. After the schema, provide a brief explanation of key design decisions and a list of 3-5 example queries that clients would commonly run against this schema.
๐ก Tips for Better Results
List your core entities with their key attributes upfront so the generated schema reflects your actual data model rather than generic assumptions.
Specify whether you need Relay-style cursor pagination or simple offset pagination โ this significantly changes the schema structure.
Use the generated example queries to immediately test your schema in a GraphQL playground once you implement the resolvers.
๐ฏ Use Cases
Backend developers and API architects starting a new GraphQL API who want a comprehensive, best-practice schema design as a foundation to build upon.