Agent Skill · Apollo GraphQL

graphql-schema

Guide for designing GraphQL schemas following industry best practices. Use this skill when: (1) designing a new GraphQL schema or API, (2) reviewing existing schema for improvements, (3) deciding on type structures or nullability, (4) implementing pagination or error patterns, (5) ensuring security in schema design.

Provider: Apollo GraphQL Path in repo: skills/graphql-schema/SKILL.md

Skill body

GraphQL Schema Design Guide

This guide covers best practices for designing GraphQL schemas that are intuitive, performant, and maintainable. Schema design is primarily a server-side concern that directly impacts API usability.

Schema Design Principles

1. Design for Client Needs

2. Be Explicit

3. Design for Evolution

Quick Reference

Type Definition Syntax

"""
A user in the system.
"""
type User {
  id: ID!
  email: String!
  name: String
  posts(first: Int = 10, after: String): PostConnection!
  createdAt: DateTime!
}

Nullability Rules

Pattern Meaning
String Nullable - may be null
String! Non-null - always has value
[String] Nullable list, nullable items
[String!] Nullable list, non-null items
[String]! Non-null list, nullable items
[String!]! Non-null list, non-null items

Best Practice: Use [Type!]! for lists - empty list over null, no null items.

Input vs Output Types

# Output type - what clients receive
type User {
  id: ID!
  email: String!
  createdAt: DateTime!
}

# Input type - what clients send
input CreateUserInput {
  email: String!
  name: String
}

# Mutation using input type
type Mutation {
  createUser(input: CreateUserInput!): User!
}

Interface Pattern

interface Node {
  id: ID!
}

type User implements Node {
  id: ID!
  email: String!
}

type Post implements Node {
  id: ID!
  title: String!
}

Union Pattern

union SearchResult = User | Post | Comment

type Query {
  search(query: String!): [SearchResult!]!
}

Reference Files

Detailed documentation for specific topics:

Key Rules

Type Design

Field Design

Mutation Design

ID Strategy

Ground Rules

Skill frontmatter

license: MIT compatibility: Any GraphQL implementation (Apollo Server, graphql-js, Yoga, etc.) metadata: {"author"=>"apollographql", "version"=>"1.0.1"} allowed-tools: Bash(npm:*) Bash(npx:*) Read Write Edit Glob Grep