---
name: graphql-schema-builder
description: "A complete GraphQL schema package for your data model: type definitions plus whichever pieces you tick (input types, enums, Relay connections, directives, subscriptions) and matching resolver stubs with mock data, so the API runs on day one. Use when a data model needs turning into a runnable GraphQL schema with the extras ticked: input and enum types, Relay connections, directives, subscriptions, and resolver stubs with mock data. Do not use for making design decisions about a domain you have not modelled yet, or reviewing an existing schema. Related topics: coding, api, graphql."
---

# GraphQL Schema Builder

A complete GraphQL schema package for your data model: type definitions plus whichever pieces you tick (input types, enums, Relay connections, directives, subscriptions) and matching resolver stubs with mock data, so the API runs on day one.

## When to use

Use this skill when a data model needs turning into a runnable GraphQL schema with the extras ticked: input and enum types, Relay connections, directives, subscriptions, and resolver stubs with mock data. Do not use it for making design decisions about a domain you have not modelled yet, or reviewing an existing schema.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Emit the ticked components in dependency order: scalars and enums, object types, inputs, connections, then the Query, Mutation, and Subscription roots.
3. Apply the chosen nullability policy to every field, commenting the reason on each nullable field when the policy is Mixed.
4. Add Relay connection types with first and after arguments and pageInfo to every list field when Relay pagination is on.
5. Declare and apply directives in the SDL when enabled, placing auth directives on the operations the authentication model protects.
6. Write resolver stubs for the chosen server library with typed mock data when requested, and the entry file that starts the server.

## Inputs

- **Project domain** (free text, e.g. "E-commerce or Blog platform or Social network")
- **Main entity types** (longer free text)
- **Authentication model** (choose one: JWT, API Key, Session-based, None)
- **Server library** (choose one: Apollo Server, GraphQL Yoga, graphql-js, Mercurius, Other)
- **Components** (choose any: Type definitions, Input types, Enum types, Query resolvers, Mutation resolvers, Subscription resolvers, Pagination types (Connection/Edge pattern))
- **Relay-style pagination** (choose one: Yes, No)
- **Add schema directives** (choose one: Yes, No)
- **Include mock resolver examples** (choose one: Yes, No)
- **Strict nullability** (choose one: All required by default, Allow nulls, Mixed (explained in comments))

## Output

A fenced graphql block with the SDL, then a fenced code block per resolver file and the server entry file, each preceded by its path, and a one-line start command.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### GraphQL Schema Builder

Build the schema and the scaffolding around it so I can run the API immediately.

#### Schema overview
- Project domain: {{Project domain}}
- Main entity types: {{Main entity types}}
- Authentication model: {{Authentication model}}
- Server library: {{Server library}}

#### Components to generate
- Components: {{Components}}

#### Options
- Relay-style pagination: {{Relay-style pagination}}
- Add schema directives: {{Add schema directives}}
- Include mock resolver examples: {{Include mock resolver examples}}
- Strict nullability: {{Strict nullability}}

Generate only the components ticked, in dependency order: scalars and enums, object types, input types, connection types, then the Query, Mutation, and Subscription roots. Apply the nullability policy consistently and, for Mixed, leave a comment on every nullable field saying why. When Relay pagination is on, give each list field first and after arguments and a typed Connection with edges, node, cursor, and pageInfo. When directives are on, declare them in the SDL and apply them where auth matters. When resolvers are requested, write them for the selected server library with a resolver per root field and per non-trivial relationship, returning mock data shaped exactly like the types when mocks are on, and a TODO where real data access goes. Include the minimal server entry file that loads the schema and resolvers so the whole thing starts with one command.

## Pitfalls

- Generating subscriptions without a pub/sub source, so the stubs compile but never emit an event.
- Returning mock data whose shape drifts from the type definitions, which fails the first real query with a null on a non-null field.
- Applying Relay connections to short fixed lists like a set of statuses, which adds cursor plumbing for nothing.
