Selections
Includes on types
In some cases, you may want to always pre-load certain relations. This can be helpful for defining fields directly on type where the underlying data may come from a related table.
Select mode for types
By default, the prisma plugin will use include
when including relations, or generating fallback
queries. This means we are always loading all columns of a table when loading it in a
t.prismaField
or a t.relation
. This is usually what we want, but in some cases, you may want to
select specific columns instead. This can be useful if you have tables with either a very large
number of columns, or specific columns with large payloads you want to avoid loading.
To do this, you can add a select
instead of an include to your prismaObject
:
The t.expose*
and t.relation
methods will all automatically add selections for the exposed
fields WHEN THEY ARE QUERIED, ensuring that only the requested columns will be loaded from the
database.
In addition to the t.expose
and t.relation
, you can also add custom selections to other fields:
Using arguments or context in your selections
The following is a slightly contrived example, but shows how arguments can be used when creating a selection for a field:
Optimized queries without t.prismaField
In some cases, it may be useful to get an optimized query for fields where you can't use
t.prismaField
.
This may be required for combining with other plugins, or because your query does not directly
return a PrismaObject
. In these cases, you can use the queryFromInfo
helper. An example of this
might be a mutation that wraps the prisma object in a result type.