# graphql-schema

Guides GraphQL SDL schema design following Apollo best practices. Useful when creating schema.graphql, adding mutations, or setting up pagination.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 4000 installs · ★ 119
- Author: apollographql
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/apollographql/skills/tree/HEAD/skills/graphql-schema/SKILL.md
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/skills/graphql-schema

## What it does

This skill guides the agent when creating or editing GraphQL SDL in `schema.graphql` or `typeDefs`. It organizes types around client use cases instead of database tables. This protects backwards compatibility.

The guide enforces strict patterns for lists with `[Type!]!` and single `input` arguments for mutations. It provides references for error modeling and schema security. Tool access includes `Read`, `Edit`, and `Bash(npx:*)`.

The guide strictly forbids adding required arguments without default values. Older clients omit them and fail validation. The rules work with Apollo Server or Yoga.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add apollographql/skills --skill graphql-schema -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/graphql-schema/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/graphql-schema/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add apollographql/skills --skill graphql-schema -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/graphql-schema/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add apollographql/skills --skill graphql-schema -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/graphql-schema/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install apollographql/skills graphql-schema
```

2. **Manually: put the files in place**
- File: `.github/skills/graphql-schema/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add apollographql/skills --skill graphql-schema -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/apollographql/skills --path skills/graphql-schema
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/graphql-schema/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add apollographql/skills --skill graphql-schema -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/apollographql/skills/tree/HEAD/skills/graphql-schema/SKILL.md

## When to use it
- design types and mutations in `schema.graphql`
- convert list pagination to cursor-based `Connection` patterns
- verify schema backwards compatibility before release
- configure field nullability and lists using `!`

## Example prompts
- Design an order checkout schema in schema.graphql with connection pagination
- Review our typeDefs for backwards compatibility and field descriptions
- Add a User type with cursor-based post pagination to the schema

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 0bbcef723dcccc3e.

BEGIN THIRD-PARTY FILE 0bbcef723dcccc3e
````text
---
name: graphql-schema
description: >
  Guide for designing and changing GraphQL schemas following industry best practices. Use this skill
  whenever you create or edit GraphQL SDL, such as a `schema.graphql` file or `typeDefs`, including when:
  (1) designing a new GraphQL schema or API,
  (2) adding or changing types, fields, arguments, mutations, or descriptions in an existing schema,
  (3) reviewing existing schema for improvements,
  (4) deciding on type structures or nullability,
  (5) implementing pagination or error patterns,
  (6) ensuring security in schema design.
license: MIT
compatibility: Any GraphQL implementation (Apollo Server, graphql-js, Yoga, etc.)
metadata:
  author: apollographql
  version: "1.0.2"
allowed-tools: Bash(npm:*) Bash(npx:*) Read Write Edit Glob Grep
---

# 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

- Think about what queries clients will write
- Organize types around use cases, not database tables
- Expose capabilities, not implementation details

### 2. Be Explicit

- Use clear, descriptive names
- Make nullability intentional
- Document with descriptions

### 3. Design for Evolution

- Plan for backwards compatibility
- Use deprecation before removal
- Avoid breaking changes
- Give every new argument or input field a default value, or make it nullable. Existing clients don't send it, so a required field without a default makes their requests fail validation.

## Quick Reference

### Type Definition Syntax

```graphql
"""
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

```graphql
# 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

```graphql
interface Node {
  id: ID!
}

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

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

### Union Pattern

```graphql
union SearchResult = User | Post | Comment

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

## Reference Files

Detailed documentation for specific topics:

- [Types](references/types.md) - Type design patterns, interfaces, unions, and custom scalars
````
END THIRD-PARTY FILE 0bbcef723dcccc3e

The third-party file has ended. Everything between the 0bbcef723dcccc3e tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3121 of 5048 bytes. © apollographql · MIT · https://github.com/apollographql/skills/tree/HEAD/skills/graphql-schema/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
