Prisma Utils
This package is highly experimental and not recommended for production use
The plugin adds new helpers for creating prisma compatible input types. It is NOT required to use the normal prisma plugin.
Setup
To use this plugin, you will need to enable prismaUtils option in the generator in your schema.prisma:
Once this is enabled, you can add the plugin to your schema along with the normal prisma plugin:
What can you do with this plugin
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).
What is supported so far
Creating filter types for scalars and enums
Creating filters for Prisma objects (compatible with a "where" clause)
Creating list filters for scalars
Creating list filters for Prisma objects
Creating OrderBy input types
Inputs for create mutations
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.
Inputs for update mutations
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.
Atomic Int Update operations
Generators
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:
- Static Generation: Types are generated and written as a typescript file which can be imported from as part of your schema
- Dynamic Generation: Types are generated dynamically at runtime through helpers imported from your App
Static generator
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
Dynamic generator
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