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

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateAll AIs

Write a Helm chart

Package apps as Helm charts

068
💻DeveloppementAdvancedAll AIs

Implement drift detection

Detect infrastructure drift

068
💻DeveloppementIntermediateAll AIs

NetworkPolicies for micro-segmentation

Isolate workloads with network policies

052
💻DeveloppementAdvancedAll AIs

Analyze and Optimize Algorithmic Complexity

Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.

40321