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

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

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 mutation testing

Measure test suite effectiveness

0313
💻DeveloppementBeginnerAll AIs

Implement input validation

Validate and sanitize inputs

0339
💻DeveloppementIntermediateClaude

Complete Code Review for Pull Requests

Get an exhaustive code review covering quality, performance, security, and maintainability for any language.

34729
💻DeveloppementAdvancedAll AIs

Prompt to Implement Real-Time WebSockets

A complete prompt to design and implement a real-time WebSocket architecture with connection management, authentication, scalability and monitoring.

0362