Pothos

Overview

Pothos

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

On this page