# Design URL: /docs/design Design overview for Pothos ## Type System [#type-system] The type system that powers most of the Pothos type checking has 2 components. The first is the SchemaTypes type param passed into the SchemaBuilder. This allows a shared set of types to be reused throughout the schema, and is responsible for providing type information for shared types like the [Context](./guide/context) object, and any Object, Interface, or Scalar types that you want to reference by name (as a string). Having all type information in a single object can be convenient at times, but with large schemas, can become unwieldy. To support a number of additional use cases, including Unions and Enums, large schemas, and plugins that extract type information from other sources (eg the Prisma, or the simple-objects plugin), Pothos has another way of passing around type information. This system uses `Ref` objects whose TypeScript types carry the backing shapes they represent. Every builder method for creating a type or a field returns a `Ref` object. Using Ref objects allows us to separate the type information from the implementation, and allows for a more modular design. For example, `builder.objectRef<{ id: string }>('User')` declares the backing shape before fields are defined with `implement`. The ref carries that shape at compile time and identifies the GraphQL type at runtime; it does not validate resolver values at runtime. See [Objects](./guide/objects) and [Circular References](./guide/circular-references) for examples. # Getting started URL: /docs Install Pothos, build a schema, and run your first GraphQL query. Define your GraphQL types, fields, and resolvers in TypeScript. Pothos checks how they fit together without generating resolver types or maintaining a separate schema definition. This guide creates a small schema, serves it with [GraphQL Yoga](https://the-guild.dev/graphql/yoga-server), and runs a query against it. You can try the schema immediately with its Playground action below. Follow the setup steps to run the same schema in your own server. [Using the playground](/docs/guide/playground) explains the editor controls. ## Installing [#installing] Start in an empty directory with Node.js and npm installed: ```sh npm init -y npm pkg set type=module ``` Install Pothos, its `graphql` peer dependency, and Yoga: npm pnpm yarn bun ```bash npm install @pothos/core graphql graphql-yoga ``` ```bash pnpm add @pothos/core graphql graphql-yoga ``` ```bash yarn add @pothos/core graphql graphql-yoga ``` ```bash bun add @pothos/core graphql graphql-yoga ``` Install TypeScript and `tsx` to check and run the example: npm pnpm yarn bun ```bash npm install --save-dev typescript @types/node tsx ``` ```bash pnpm add --save-dev typescript @types/node tsx ``` ```bash yarn add --dev typescript @types/node tsx ``` ```bash bun add --dev typescript @types/node tsx ``` ## Set up TypeScript [#set-up-typescript] Create `tsconfig.json`: ```json { "compilerOptions": { "target": "ES2022", "module": "NodeNext", "types": ["node"], "strict": true, "noEmit": true, "skipLibCheck": true }, "include": ["*.ts"] } ``` Pothos relies on strict null checking for its type inference. Keep `strict` enabled when adding Pothos to an existing project too. ## Create a simple schema [#create-a-simple-schema] Create `schema.ts`: ```typescript playground example="foundations-getting-started" import SchemaBuilder from '@pothos/core'; const builder = new SchemaBuilder({}); builder.queryType({ fields: (t) => ({ hello: t.string({ args: { name: t.arg.string(), }, resolve: (_parent, { name }) => `hello, ${name ?? 'World'}`, }), }), }); export const schema = builder.toSchema(); ``` `queryType` defines the fields clients can query. Here, `hello` returns a string and accepts an optional `name` argument. Pothos infers the resolver's argument types from that definition. `toSchema()` builds a graphql-js `GraphQLSchema`. You can use it with Yoga or another server that accepts a `GraphQLSchema`. ## Create a server [#create-a-server] Create `server.ts` alongside `schema.ts`: ```typescript import { createServer } from 'node:http'; import { createYoga } from 'graphql-yoga'; import { schema } from './schema.js'; const yoga = createYoga({ schema }); const server = createServer(yoga); server.listen(4000, () => { console.log('Visit http://localhost:4000/graphql'); }); ``` Check the types, then start the server: ```sh npx tsc npx tsx server.ts ``` `tsx` runs TypeScript without checking types, so run `tsc` separately to catch type errors. ## Run a query [#run-a-query] Open [http://localhost:4000/graphql](http://localhost:4000/graphql) to use Yoga's GraphiQL explorer. Run this query: ```graphql playground example="foundations-getting-started" query Hello { hello(name: "Pothos") } ``` The response is: ```json { "data": { "hello": "hello, Pothos" } } ``` Omit the `name` argument to get `"hello, World"`. Stop the server with Ctrl+C when you're done. ## Continue building [#continue-building] [Objects](/docs/guide/objects) shows how to expose your application's data. [Fields](/docs/guide/fields) covers resolvers, lists, and nullability, and [Arguments](/docs/guide/args) explains how clients pass values to them. When your schema needs request data, see [Context](/docs/guide/context). [App layout](/docs/guide/app-layout) shows how to organize a larger schema across files. # LLM Integration URL: /docs/llms Read the Pothos documentation as plain text for use with LLMs and other tools. The documentation is also available as plain text. Use the index to find a topic, fetch an individual page, or download the complete documentation. ## Documentation index [#documentation-index] [`/llms.txt`](/llms.txt) lists each page's title, description, and link to its plain-text version. ## Full Documentation [#full-documentation] [`/llms-full.txt`](/llms-full.txt) combines all documentation pages into one response. Each page includes its title, URL, description, and processed content. ## Individual Pages [#individual-pages] Append `.mdx` to a documentation URL to read that page as text. For example, [`/docs/guide/objects.mdx`](/docs/guide/objects.mdx) contains the Objects guide. Despite the `.mdx` URL suffix, these responses contain processed documentation text, rather than the original source file with its component imports. # Resources URL: /docs/resources External guides, tools, and libraries created by members of the Pothos community. ## Guides and Tutorials [#guides-and-tutorials] * [End-To-End Type-Safety with GraphQL, Prisma & React: GraphQL API](https://www.prisma.io/blog/e2e-type-safety-graphql-react-3-fbV2ZVIGWg#start-up-a-graphql-server) by [Sabin Adams](https://twitter.com/sabinthedev) * [Code-first GraphQL with Pothos](https://graphql.wtf/episodes/60-code-first-graphql-with-pothos) by [Jamie Barton](https://twitter.com/notrab) * [Type-safe GraphQL Server with Pothos](https://omkarkulkarni.hashnode.dev/type-safe-graphql-server-with-pothos-formerly-giraphql) by [Omkar Kulkarni](https://twitter.com/omkar_k45) * [Build a GraphQL server running on Cloudflare Workers](https://the-guild.dev/blog/graphql-yoga-worker) by [Rito Tamata](https://twitter.com/chimame_rt) ## Third-party tools and libraries [#third-party-tools-and-libraries] * [Prisma Generator Pothos Codegen](https://github.com/Cauen/prisma-generator-pothos-codegen) by [Emanuel](https://twitter.com/cauenor) * [Nexus to Pothos codemod](https://github.com/villesau/nexus-to-pothos-codemod) by [Ville Saukkonen](https://twitter.com/SaukkonenVille) * [protoc-gen-pothos](https://github.com/proto-graphql/proto-graphql-js/tree/main/packages/protoc-gen-pothos) by [Masayuki Izumi](https://twitter.com/izumin5210) * [@smatch-corp/nestjs-pothos](https://github.com/smatch-corp/nestjs-pothos) by [Chanhee Lee](https://github.com/iamchanii) * [pothos-protoc-gen](https://iamchanii.github.io/pothos-protoc-gen/) by [Chanhee Lee](https://github.com/iamchanii) * [rumble](https://github.com/m1212e/rumble) (GraphQL + Drizzle + Abilities) by [m1212e](https://github.com/m1212e) [(introduction)](https://github.com/hayes/pothos/discussions/1414) ## Templates and Examples [#templates-and-examples] * [Server Template with Pothos](https://github.com/nkzw-tech/server-template) by [Nakazawa Tech](https://nakazawa.tech) * [Pothos GraphQL Server](https://github.com/theogravity/graphql-pothos-server-example) by [Theo Gravity](https://github.com/theogravity) * [GraphQL countries server](https://github.com/gbicou/countries-server) by [Benjamin VIELLARD](https://github.com/gbicou) * [datalake-graphql-wrapper](https://github.com/dbsystel/datalake-graphql-wrapper) by [noxify](https://github.com/noxify) ## Conference talks [#conference-talks] * [Pothos + Prisma: delightful, type-safe and efficient GraphQL](https://www.youtube.com/watch?v=LqKPfMmxFxw) by [Michael Hayes](https://twitter.com/yavascript) * [Building Scalable Applications](https://www.youtube.com/watch?v=rxPTEko8J7c\&t=36s) by [Christoph Nakazawa](https://cpojer.net) ## Paid tools [#paid-tools] * [Bedrock](https://bedrock.mxstbr.com/) by [Max Stoiber](https://twitter.com/mxstbr) * [nytro](https://www.nytro.dev/) by Jordan Gensler # Sponsors URL: /docs/sponsors The generous people supporting Pothos development Pothos development is supported by [sponsorships](https://github.com/sponsors/hayes) from these generous people and organizations: * The Guild * Prisma * GitHub * Stellate * [@saevarb](https://github.com/saevarb) * [@seanaye](https://github.com/seanaye) * [@arimgibson](https://github.com/arimgibson) * [@ccfiel](https://github.com/ccfiel) * [@JoviDeCroock](https://github.com/JoviDeCroock) * [@hellopivot](https://github.com/hellopivot) * [@robmcguinness](https://github.com/robmcguinness) * [@Gomah](https://github.com/Gomah) * IPS Hosting * [@garth](https://github.com/garth) * [@lifedup](https://github.com/lifedup) * [@skworden](https://github.com/skworden) * [@jacobgmathew](https://github.com/jacobgmathew) * [@aniravi24](https://github.com/aniravi24) * [@mizdra](https://github.com/mizdra) * [@3nk1du](https://github.com/3nk1du) * [@FarazPatankar](https://github.com/FarazPatankar) * [@noxify](https://github.com/noxify) * [@matthawk60](https://github.com/matthawk60) * [@BitPhinix](https://github.com/BitPhinix) * [@nathanchapman](https://github.com/nathanchapman) * [@pradyuman](https://github.com/pradyuman) * [@tmm](https://github.com/tmm)