Skip to main content

Schema Definition

Prism’s GraphQL engine lets you define schemas entirely in Swift using a typed DSL. Every field, argument, and type is a first-class Swift value — you get compiler checks, autocomplete, and zero code generation.

Type System

GraphQL types map directly to PrismGraphQLType:
Available Types
Use .nonNull() to mark fields as required in your schema. Clients will get a validation error if a non-null field returns nil.

Defining Fields

Each field has a name, type, optional arguments, and a resolver function:
Field with Resolver

Fields with Arguments

Field with Arguments

Object Types

Group fields into object types:
User Type

Building a Complete Schema

1

Define your types

Create object types for each entity in your domain.
2

Define the Query type

The Query type is the entry point for all read operations.
3

Define Mutation type (optional)

Mutations handle create, update, and delete operations.
4

Assemble the schema

Combine everything into a PrismGraphQLSchema.

Blog Schema Example

Complete Blog Schema
The schema object is Sendable and can be shared across concurrent requests safely. Define it once at startup and pass it to your middleware.

Schema with Type Registry

For schemas with nested object types (e.g., a User that has Posts), register types in the schema so the executor can resolve nested selections:
Registering Types

What’s Next

Queries

Learn how to write resolvers and handle nested data

Mutations

Create, update, and delete data through GraphQL