Overview
Pothos is a GraphQL schema builder for TypeScript. You define types, fields, and resolvers in TypeScript, and Pothos checks how they fit together without generating resolver types or maintaining a separate schema definition.
builder.toSchema() creates a standard graphql-js GraphQLSchema that you can pass to your GraphQL
server. The core package has graphql as its only peer dependency. Plugins add features such as
authorization, pagination, and ORM integration to the same builder.
Build a schema from your data
import SchemaBuilder from '@pothos/core';
const builder = new SchemaBuilder({});
const Giraffe = builder.objectRef<{ name: string; heightInMeters: number }>('Giraffe').implement({
fields: (t) => ({
name: t.exposeString('name'),
heightInFeet: t.float({
resolve: (giraffe) => giraffe.heightInMeters * 3.28084,
}),
}),
});
builder.queryType({
fields: (t) => ({
giraffe: t.field({
type: Giraffe,
resolve: () => ({ name: 'Gina', heightInMeters: 5 }),
}),
}),
});
export const schema = builder.toSchema();The backing data and the GraphQL type can have different shapes. Here, the resolver returns a height
in meters, while clients query heightInFeet. Pothos checks the data returned by giraffe and infers
the giraffe parameter's type in the field resolver.
Follow the Guide to install Pothos, start a server, and run your first query. Objects explains object references, classes, and registering backing types by name. The API reference lists the builder's methods and options.
Plugins that make Pothos even better
Add GraphQL
Add existing GraphQL types to your schema
Auth
Add global, type level, or field level authorization checks to your schema
Complexity
A plugin for defining and limiting complexity of queries
Dataloader
Quickly define data-loaders for your types and fields to avoid n+1 queries.
Directives
Integrate with existing schema graphql directives in a type-safe way.
Drizzle
A plugin to support efficient queries through drizzles relational query builder API
Errors
A plugin for easily including error types in your GraphQL schema and hooking up error types to resolvers.
Grafast
A plugin for using grafast plans instead of resolvers in your schema
Mocks
Add mock resolvers for easier testing
Prisma
A plugin for more efficient integration with prisma that can help solve n+1 issues and more efficiently resolve queries
Relay
Easy to use builder methods for defining relay style nodes and connections, and helpful utilities for cursor based pagination.
Simple Objects
Define simple object types without resolvers or manual type definitions.
Smart Subscriptions
Make any part of your graph subscribable to get live updates as your data changes.
Sub-Graph
Build multiple subsets of your graph to easily share code between internal and external APIs.
Tracing
Add tracing for resolver execution, with support for opentelemetry, newrelic, sentry, logging, and custom tracers
Validation
Validation using StandardSchemaV1 compatible libraries like Zod, Valibot, and ArkType
With-Input
Define fields with inline input objects