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.

๐Ÿ”— Related Prompts

๐Ÿ’ป Coding beginner

Explain Code Like Im a Beginner

Get any code explained in plain English with line-by-line breakdowns, analogies, and learning suggestions.

๐Ÿ’ป Coding beginner

Debug My Code and Explain the Fix

Get your code debugged with clear explanations of what went wrong and why, plus the corrected version.

๐Ÿ’ป Coding intermediate

Write Unit Tests for My Code

Generate thorough unit tests covering edge cases, error handling, and both positive and negative scenarios.

๐Ÿ’ป Coding intermediate

Convert Code Between Languages

Convert code between any programming languages while maintaining idiomatic patterns and best practices.

๐Ÿ’ป Coding intermediate

Write a REST API Endpoint

Generate production-ready REST API endpoints with validation, error handling, and documentation.

๐Ÿ’ป Coding advanced

Create a GitHub Actions CI/CD Workflow for Automated Testing and Deployment

Generate a complete GitHub Actions CI/CD workflow with build, test, deploy, and notification jobs for your project.