Pothos v4 is now available! 🎉Check out the full migration guide here

Pothos

Inferring Types

In some cases you may want to use the types from your input of object refs to build helpers, or provide accurate types for other functions.

To get types from any Pothos ref object, you can use the $inferType and $inferInput properties on the ref. This pattern is inspired by drizzle ORM.

const MyInput = builder.inputType('MyInput', {
  fields: (t) => ({
    id: t.id({ required: true }),
    name: t.string({ required: true }),
  }),
});
 
// { id: string; name: string; }
type MyInputShape = typeof MyInput.$inferInput; /
 
// infer the shape of the Prisma User model
const UserRef = builder.prismaObject('User', {});
type UserType = typeof UserRef.$inferType;

On this page

No Headings