Skip to main content
The @team-plain/graphql package provides a fully typed client for Plain’s GraphQL API. It is auto-generated from the GraphQL schema, which means every query and mutation available in the API is available in the SDK. You can use any GraphQL client to interact with Plain’s API, but this SDK gives you type safety, automatic pagination, and structured error handling out of the box.

Installation

Supports both ESM and CJS.

Setup

You will need an API key — see authentication for how to create one.

Queries

Queries are available under client.query. Relations on returned models are lazy-loaded — accessing them triggers a separate API call automatically.

Mutations

Mutations are available under client.mutation. Mutation errors are returned as typed data, not thrown as exceptions. This matches Plain’s API where all mutations return *Output types with an optional error field.

Pagination

Union types

GraphQL union and interface fields are exposed as discriminated unions of model classes. Each union member has a __typename property for type narrowing and supports the same lazy-loading as any other model.
Models also support querying sub-connections directly:

Error handling

  • Queries: network, auth (401), forbidden (403), and rate limit (429) errors throw typed exceptions (AuthenticationError, ForbiddenError, RateLimitError, NetworkError, PlainGraphQLError).
  • Mutations: return the full *Output type. Check result.error for a typed MutationError with message, type, code, and fields[]. This is intentional — Plain’s API treats mutation errors as data.
For more details on error handling patterns, see error handling.

Migrating from @team-plain/typescript-sdk

If you’re upgrading from the old @team-plain/typescript-sdk package, see the migration guide for a full breakdown of breaking changes.

Resources