Gathering detailed insights and metrics for @pothos/plugin-prisma-utils
Gathering detailed insights and metrics for @pothos/plugin-prisma-utils
Gathering detailed insights and metrics for @pothos/plugin-prisma-utils
Gathering detailed insights and metrics for @pothos/plugin-prisma-utils
Pothos GraphQL is library for creating GraphQL schemas in typescript using a strongly typed code first approach
npm install @pothos/plugin-prisma-utils
Typescript
Module System
Node Version
NPM Version
@pothos/plugin-relay@4.6.1
Updated on Jul 11, 2025
@pothos/core@4.7.2
Updated on Jul 11, 2025
@pothos/core@4.7.1
Updated on Jul 10, 2025
@pothos/plugin-relay@4.6.0
Updated on Jul 10, 2025
@pothos/plugin-prisma@4.10.0
Updated on Jul 10, 2025
@pothos/plugin-directives@4.2.4
Updated on Jul 10, 2025
TypeScript (83.15%)
MDX (16.2%)
JavaScript (0.54%)
CSS (0.09%)
Shell (0.02%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
2,487 Stars
2,907 Commits
172 Forks
13 Watchers
36 Branches
120 Contributors
Updated on Jul 11, 2025
Latest Version
1.3.2
Package Id
@pothos/plugin-prisma-utils@1.3.2
Unpacked Size
224.45 kB
Size
27.81 kB
File Count
42
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 18, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
The plugin adds new helpers for creating prisma compatible input types. It is NOT required to use the normal prisma plugin.
To use this plugin, you will need to enable prismaUtils option in the generator in your schema.prisma:
1generator pothos { 2 provider = "prisma-pothos-types" 3 // Enable prismaUtils feature 4 prismaUtils = true 5}
Once this is enabled, you can add the plugin to your schema along with the normal prisma plugin:
1import SchemaBuilder from '@pothos/core'; 2import { PrismaClient } from '@prisma/client'; 3import type PrismaTypes from '@pothos/plugin-prisma/generated'; 4import PrismaPlugin from '@pothos/plugin-prisma'; 5import PrismaUtils from '@pothos/plugin-prisma-utils'; 6 7export const prisma = new PrismaClient({}); 8 9export default new SchemaBuilder<{ 10 Scalars: { 11 DateTime: { 12 Input: Date; 13 Output: Date; 14 }; 15 }; 16 PrismaTypes: PrismaTypes; 17}>({ 18 plugins: [PrismaPlugin, PrismaUtils], 19 prisma: { 20 client: prisma, 21 }, 22});
Currently this plugin is focused on making it easier to define prisma compatible input types that take advantage of the types defined in your Prisma schema.
The goal is not to generate all input types automatically, but rather to provide building blocks so that writing your own helpers or code-generators becomes a lot easier. There are far too many tradeoffs and choices to be made when designing input types for queries that one solution won't work for everyone.
This plugin will eventually provide more helpers and examples that should allow anyone to quickly set something up to automatically creates all their input types (and eventually other crud operations).
1const StringFilter = builder.prismaFilter('String', { 2 ops: ['contains', 'equals', 'startsWith', 'not'], 3}); 4 5export const IDFilter = builder.prismaFilter('Int', { 6 ops: ['equals', 'not'], 7}); 8 9builder.enumType(MyEnum, { name: 'MyEnum' }); 10const MyEnumFilter = builder.prismaFilter(MyEnum, { 11 ops: ['not', 'equals'], 12});
1const UserWhere = builder.prismaWhere('User', { 2 fields: { 3 id: IDFilter, 4 }, 5}); 6 7const PostFilter = builder.prismaWhere('Post', { 8 fields: (t) => ({ 9 // You can use either filters 10 id: IDFilter, 11 // or scalar types to only support equality 12 title: 'String', 13 createdAt: 'DateTime', 14 // Relations are supported by referencing other scalars 15 author: UserFilter, 16 // use t.field to provide other field options 17 authorId: t.field({ type: IDFilter, description: 'filter by author id' }), 18 }), 19});
1export const StringListFilter = builder.prismaScalarListFilter('String', { 2 name: 'StringListFilter', 3 ops: ['has', 'hasSome', 'hasEvery', 'isEmpty', 'equals'], 4});
1const UserListFilter = builder.prismaListFilter(UserWhere, { 2 ops: ['every', 'some', 'none'], 3});
1const UserOrderBy = builder.prismaOrderBy('User', { 2 fields: { 3 name: true, 4 }, 5}); 6 7export const PostOrderBy = builder.prismaOrderBy('Post', { 8 fields: () => ({ 9 id: true, 10 title: true, 11 createdAt: true, 12 author: UserOrderBy, 13 }), 14});
You can use builder.prismaCreate
to create input types for create mutations.
To get these types to work correctly for circular references, it is recommended to add explicit type annotations, but for simple types that do not have circular references the explicit types can be omitted.
1import { InputObjectRef } from '@pothos/core'; 2import { Prisma } from '@prisma/client'; 3 4export const UserCreate: InputObjectRef<Prisma.UserCreateInput> = builder.prismaCreate('User', { 5 name: 'UserCreate', 6 fields: () => ({ 7 // scalars 8 id: 'Int', 9 email: 'String', 10 name: 'String', 11 // inputs for relations need to be defined separately as shown below 12 profile: UserCreateProfile, 13 // create fields for list relations are defined just like normal relations. 14 // Pothos will automatically handle making the inputs lists 15 posts: UserCreatePosts, 16 }), 17}); 18 19export const UserCreateProfile = builder.prismaCreateRelation('User', 'profile', { 20 fields: () => ({ 21 // created with builder.prismaCreate as shown above for User 22 create: ProfileCreateWithoutUser, 23 // created with builder.prismaWhere 24 connect: ProfileUniqueFilter, 25 }), 26}); 27 28export const UserCreatePosts = builder.prismaCreateRelation('User', 'posts', { 29 fields: () => ({ 30 // created with builder.prismaCreate as shown above for User 31 create: PostCreateWithoutAuthor, 32 // created with builder.prismaWhere 33 connect: PostUniqueFilter, 34 }), 35});
You can use builder.prismaUpdate
to Update input types for update mutations.
To get these types to work correctly for circular references, it is recommended to add explicit type annotations, but for simple types that do not have circular references the explicit types can be omitted.
1export const UserUpdate: InputObjectRef<Prisma.Prisma.UserUpdateInput> = builder.prismaUpdate( 2 'User', 3 { 4 name: 'UserUpdate', 5 fields: () => ({ 6 id: 'Int', 7 email: 'String', 8 name: 'String', 9 // inputs for relations need to be defined separately as shown below 10 profile: UserUpdateProfile, 11 posts: UserUpdatePosts, 12 }), 13 }, 14); 15 16export const UserUpdateProfile = builder.prismaUpdateRelation('User', 'profile', { 17 fields: () => ({ 18 // created with builder.prismaCreate 19 create: ProfileCreateWithoutUser, 20 // created with builder.prismaUpdate 21 update: ProfileUpdateWithoutUser, 22 // created with builder.prismaWhereUnique 23 connect: ProfileUniqueFilter, 24 }), 25}); 26 27export const UserUpdatePosts = builder.prismaUpdateRelation('User', 'posts', { 28 fields: () => ({ 29 // Not all update methods need to be defined 30 // created with builder.prismaCreate 31 create: PostCreateWithoutAuthor, 32 // created with builder.prismaCreateMany 33 createMany: { 34 skipDuplicates: 'Boolean', 35 data: PostCreateManyWithoutAuthor, 36 }, 37 // created with builder.prismaWhereUnique 38 set: PostUniqueFilter, 39 // created with builder.prismaWhereUnique 40 disconnect: PostUniqueFilter, 41 delete: PostUniqueFilter, 42 connect: PostUniqueFilter, 43 44 update: { 45 // created with builder.prismaWhereUnique 46 where: PostUniqueFilter, 47 // created with builder.prismaUpdate 48 data: PostUpdateWithoutAuthor, 49 }, 50 updateMany: { 51 // created with builder.prismaWhere 52 where: PostWithoutAuthorFilter, 53 // created with builder.prismaUpdate 54 data: PostUpdateWithoutAuthor, 55 }, 56 // created with builder.prismaWhere 57 deleteMany: PostWithoutAuthorFilter, 58 }), 59});
1const IntUpdate = builder.prismaIntAtomicUpdate(); 2// or with options 3const IntUpdate = builder.prismaIntAtomicUpdate({ 4 name: 'IntUpdate', 5 ops: ['increment', 'decrement'], 6}); 7 8export const PostUpdate = builder.prismaUpdate('Post', { 9 name: 'PostUpdate', 10 fields: () => ({ 11 title: 'String', 12 views: IntUpdate, 13 }), 14});
Manually defining all the different input types shown above for a large number of tables can become very repetitive. These utilities are designed to be building blocks for generators or utility functions, so that you don't need to hand write these types yourself.
Pothos does not currently ship an official generator for prisma types, but there are a couple of example generators that can be copied and modified to suite your needs. These are intentionally somewhat limited in functionality and not written to be easily exported because they will be updated with breaking changes as these utilities are developed further. They are only intended as building blocks for you to build you own generators.
There are 2 main approaches:
You can find an example static generator here
This generator will generate a file with input types for every table in your schema as shown here
These generated types can be used in your schema as shown here
You can find an example dynamic generator here
This generator exports a class that can be used to dynamically create input types for your builder as shown here
No vulnerabilities found.
No security vulnerabilities found.