# API GRAPHQL Schema Design

> Designs advanced GraphQL schemas — interfaces, unions, custom scalars — and federated graphs with Apollo Federation subgraphs. Use when working with schema design, federation or when the user mentions schema design, federation.

- Skill: `opknock/api-graphql-schema-design` (Agent Skill)
- Install (CLI): `npx get-skill add opknock/api-graphql-schema-design`
- Raw SKILL.md: https://api.skillmd.com/api/skills/opknock/api-graphql-schema-design/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- License: MIT
- Author: OpKnock (https://skillmd.com/u/opknock)
- Updated: 2026-11-23
- Page: https://skillmd.com/skills/opknock/api-graphql-schema-design

---


Designs advanced GraphQL schemas — interfaces, unions, custom scalars — and federated graphs with Apollo Federation subgraphs.

## Agentic Workflow: Read -> Reason -> Act (api-graphql-schema-design)

You are **Api Graphql Schema Design** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.

### 1. Read — backend context for `api-graphql-schema-design`
- Domain: Designs advanced GraphQL schemas — interfaces, unions, custom scalars — and federated graphs with Apollo Federation subgraphs.
- **schema-design**: Model enterprise GraphQL schemas with shared type patterns and schema-first authoring — `npx graphql-codegen init`
- **federation**: Compose subgraphs into a supergraph with Apollo Federation and Rover — `rover subgraph publish my-graph@prod --name inventory --schema ./inventory.graph`
- Check `knowledge` and `prerequisites: apollo-server, graphql-codegen, dataloader`

### 2. Reason — think for `api-graphql-schema-design`
- For `schema-design`: Model enterprise GraphQL schemas with shared type patterns and schema-first authoring — decide which checks to run
- For `federation`: Compose subgraphs into a supergraph with Apollo Federation and Rover — decide which checks to run
- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs

### 3. Act — execute with `api-graphql-schema-design` tools
- Tools: `Glob`, `Grep`, `Read`, `Npx`, `Strawberry` (see frontmatter `tools`/`allowed-tools`)
- Use `safe_path` for any write; record evidence (paths, checksums)
- Fingerprint: `api-graphql-schema-design:58adacca`

# API GraphQL (Schema Design & Federation)

Designs advanced GraphQL schemas and composes them into federated graphs.

## When to Use
- Enterprise GraphQL with multiple teams
- Schema-first design with governance
- Composing subgraphs into a supergraph
- Adding real-time via subscriptions

## Real Commands

```bash
# Generate types from schema
npx graphql-codegen init
npx graphql-codegen --config codegen.yml

# Export schema (Python/Strawberry)
strawberry export-schema -o schema.graphql

# Introspect a running server
rover graph introspect http://localhost:4001/graphql > local.graphql

# Compose supergraph
rover supergraph compose --config supergraph.yaml --output supergraph.graphql
```

## Supergraph Config

```yaml
# supergraph.yaml
subgraphs:
  inventory:
    routing_url: http://inventory:4001/graphql
    schema:
      file: ./inventory.graphql
  products:
    routing_url: http://products:4002/graphql
    schema:
      file: ./products.graphql
```

## Testing
Use `rover subgraph check` against the prod schema before publishing to catch breaking subgraph changes.

## Best Practices
- Keep subgraph boundaries at team ownership lines
- Run `rover subgraph check` on every subgraph PR
- Version and back up the composed supergraph

## Capabilities

### schema-design
Model enterprise GraphQL schemas with shared type patterns and schema-first authoring

**Parameters:**
- `schema` (string): Path to GraphQL SDL schema file
- `config` (string): graphql-codegen config path

**Commands:**
- `npx graphql-codegen init`
- `npx graphql-codegen --config codegen.yml`
- `strawberry export-schema -o schema.graphql`
- `npm run graphql:schema:print > schema.graphql`
- `npx graphql-inspector validate schema.graphql`

**Examples:**
- npx graphql-codegen --config codegen.yml && git diff --stat
- strawberry export-schema -o schema.graphql && graphql-inspector validate schema.graphql
- npx graphql-inspector validate documents/**/*.graphql schema.graphql

### federation
Compose subgraphs into a supergraph with Apollo Federation and Rover

**Parameters:**
- `graphRef` (string): Apollo graph ref like my-graph@prod
- `subgraph` (string): Subgraph name

**Commands:**
- `rover subgraph publish my-graph@prod --name inventory --schema ./inventory.graphql --routing-url http://inventory:4001`
- `rover supergraph compose --config supergraph.yaml --output supergraph.graphql`
- `rover dev --supergraph-config supergraph.yaml`
- `rover graph introspect http://localhost:4001/graphql > local.graphql`
- `rover subgraph check my-graph@prod --name inventory --schema ./inventory.graphql`

**Examples:**
- rover supergraph compose --config supergraph.yaml --output supergraph.graphql
- rover subgraph check my-graph@prod --name products --schema ./products.graphql
- rover dev --supergraph-config supergraph.yaml --watch

## References
- [Apollo Federation Docs](https://www.apollographql.com/docs/federation/)
- [Rover CLI](https://www.apollographql.com/docs/rover/)
- [GraphQL Code Generator](https://the-guild.dev/graphql/codegen/docs)

