Skip to content

How to combine schema definitions scattered across nested folders/files into one schema? #273

Answered by hayes
xoldd asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, sorry it took me a bit to get around to answering this.

Generally the easiest way to do this is to create a structure like the following:

/builder.ts

import SchemaBuilder from '@pothos/core';
export const builder = new SchemaBuilder({});

/types/{typeName}.ts (Or however you want to split up your files

import { builder } from '../builder';

// exported so it can be imported/referenced by other types, but not required by Pothos
export const User = builder.objectRef<UserShape>('User')

User.implement({ fields: t => ({...}) });

/schema.ts

import { builder } from './builder';
// import all your files that define types here
import './types/user';
import './types/posts';

export const schema =

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@hayes
Comment options

Answer selected by hayes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants