P
💻DeveloppementAdvancedAll AIs

Prompt to Generate a GraphQL Schema and Resolvers

This prompt generates a complete GraphQL schema with types, queries, mutations, subscriptions and resolvers implemented following best practices.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un architecte backend spécialisé en GraphQL. Génère un schéma GraphQL complet avec ses resolvers pour le domaine suivant :

Domaine métier : [DOMAINE_METIER]
Entités principales : [LISTE_ENTITES]
Langage backend : [LANGAGE_BACKEND]
Bibliothèque GraphQL : [LIBRAIRIE_GRAPHQL]

Pour chaque entité, fournis :

  1. Types GraphQL : Définis les types avec tous les champs, leurs types scalaires ou personnalisés, et les relations entre entités (one-to-one, one-to-many, many-to-many).

  2. Queries : Génère les queries pour récupérer une entité par ID, lister les entités avec pagination (cursor-based), et filtrer par critères pertinents au domaine.

  3. Mutations : Crée les mutations CRUD (create, update, delete) avec des input types dédiés et une validation des données entrantes.

  4. Resolvers : Implémente les resolvers correspondants avec :

    • Gestion des relations N+1 via DataLoader
    • Gestion des erreurs avec des codes d'erreur métier explicites
    • Authentification et autorisation via le contexte GraphQL
    • Typage strict de bout en bout
  5. Subscriptions (si pertinent) : Ajoute des subscriptions pour les événements temps réel du domaine.

  6. Schéma SDL complet : Fournis le fichier .graphql avec tous les types, queries, mutations et subscriptions.

Respecte les bonnes pratiques suivantes :

  • Nommage cohérent (PascalCase pour les types, camelCase pour les champs)
  • Types d'entrée (Input) séparés pour create et update
  • Utilisation d'enums pour les valeurs contraintes
  • Type de retour unifié pour les mutations (payload pattern)
  • Commentaires de documentation dans le schéma SDL
  • Pagination Relay-style avec edges et pageInfo

Personalize this prompt with Léa

Answer 3 questions and Léa tailors the prompt to your situation.

Why this prompt works

<p>This prompt is designed to produce a <strong>complete, production-ready GraphQL API</strong> from your business entities. By specifying the domain, entities, language and library used, the AI adapts the generated code to your exact tech stack.</p><p>The prompt covers the entire GraphQL development cycle: from the declarative <strong>SDL schema</strong> to <strong>implemented resolvers</strong> with N+1 relationship handling via DataLoader, contextual authentication and cursor-based pagination. Each mutation uses the <strong>payload pattern</strong> that returns both the result and potential errors, making client-side handling easier.</p><p>For optimal results:</p><ul><li>Describe your entities with their key relationships (e.g., <em>User hasMany Posts, Post belongsTo Category</em>)</li><li>Specify your exact stack (e.g., <em>TypeScript + Apollo Server</em> or <em>Python + Strawberry</em>)</li><li>Add specific business constraints if needed (roles, permissions, validation rules)</li></ul>

Use Cases

Design a new application GraphQL API from scratchMigrate an existing REST API to GraphQL with a well-structured schemaQuickly generate a working prototype with complete types and resolversLearn GraphQL best practices (pagination, error handling, DataLoader)

Expected Output

A complete documented GraphQL SDL schema, associated Input and Payload types, resolvers implemented in the chosen language with DataLoader and error handling, and optionally real-time subscriptions.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Astuce : pour éviter des réponses génériques, précisez le format des identifiants (UUID, serial) et le style de pagination attendu (Relay vs simple offset). Ajoutez des exemples de données métier pour chaque entité, cela améliore nettement la pertinence des filtres, des subscriptions et des règles d’autorisation.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementAdvancedAll AIs

Implement pipeline as code testing

Test CI/CD pipelines

0185
💻DeveloppementIntermediateChatGPT

Prompt ChatGPT to Create a REST API

Creating a REST API is a fundamental step in modern application development. Whether you're building a mobile app, a dashboard or a microservices system, a well-designed API is the backbone of your architecture. ChatGPT proves to be a valuable ally to accelerate this development phase: it can generate the complete structure of your API, define endpoints according to REST conventions, produce server code with error handling, and even create the associated OpenAPI documentation. By using a well-structured prompt, you get in seconds a functional API skeleton that follows best practices — route naming, appropriate HTTP codes, incoming data validation, and separation of concerns. Instead of starting from scratch, you iterate on a solid foundation that ChatGPT adapts to your tech stack (Node.js, Python, Go, PHP…) and your business domain. This guide offers optimized prompts to get the most out of ChatGPT in designing and implementing your REST APIs, from rapid prototyping to production-ready API.

0137
💻DeveloppementIntermediateAll AIs

Optimize Your SQL Queries and Boost Performance

A complete prompt to analyze, diagnose, and optimize your SQL queries with indexing and rewriting recommendations adapted to your database engine.

0374
💻DeveloppementIntermediateAll AIs

Migrating from JavaScript to TypeScript

Gradually migrating a codebase to TypeScript

0176