Prisma Objects
Creating types with builder.prismaObject
builder.prismaObject
takes 2 arguments:
name
: The name of the prisma model this new type representsoptions
: options for the type being created, this is very similar to the options for any other object type
So far, this is just creating some simple object types. They work just like any other object type in Pothos. The main advantage of this is that we get the type information without using object refs, or needing imports from prisma client.
Adding prisma fields to non-prisma objects (including Query and Mutation)
There is a new t.prismaField
method which can be used to define fields that resolve to your prisma
types:
This method works just like the normal t.field
method with a couple of differences:
- The
type
option must contain the name of the prisma model (eg.User
or[User]
for a list field). - The
resolve
function has a new first argumentquery
which should be spread into query prisma query. This will be used to load data for nested relationships.
You do not need to use this method, and the builder.prismaObject
method returns an object ref than
can be used like any other object ref (with t.field
), but using t.prismaField
will allow you to
take advantage of more efficient queries.
The query
object will contain an object with include
or select
options to pre-load data needed
to resolve nested parts of the current query. The included/selected fields are based on which fields
are being queried, and the options provided when defining those fields and types.
Extending prisma objects
The normal builder.objectField(s)
methods can be used to extend prisma objects, but do not support
using selections, or exposing fields not in the default selection. To use these features, you can
use
builder.prismaObjectField
or builder.prismaObjectFields
instead.