Prisma JS/TS client generator exclude attribute
See original GitHub issueCurrently, the client selects all fields when querying a model. There’s no easy way to exclude a field by default. This makes it easy to accidentally send sensitive information back to the client, for example a password hash on a user model.
It is infeasible or too complicated to build a solution for this issue without undermining the current design of the client (exclude
can’t neatly fit in besides include
and select
in the type system) or building complex hacks that do not work for more involved scenarios.
This proposal introduces a generator attribute that will instruct the client to not query a field by default, but it must be explicitly selected instead for it to get fetched.
Prisma Schema Language (PSL) Syntax Proposal
With the concept of generator attributes being a decided addition in the future of the Prisma Schema (https://github.com/prisma/prisma/issues/7209), we can already decide to implement exclude as a “known” generator attribute, meaning that while we don’t have pluggable generators formalized, we can skip the generic plugin part and include it first-party into the Prisma code until we have a real system in place:
generator client { ... }
model Model {
...
field String @client.exclude
}
The exclude
property is namespaced to the generator that will use it in the end.
Technical Details
The attribute will be attached to all places in the underlying protocol (currently internal, used by the language generators) where something has been derived from the field:
{
"name": "Model",
"fields": [
{
"name": "field",
"args": [],
"isNullable": false,
"attributes": [{
"generator": "client",
"name": "exclude"
}],
"outputType": {
"type": "String",
"location": "scalar",
"isList": false
}
}
]
}
Note that the above is not a final version and may change.
Feedback
- Do you agree with the
exclude
naming? If not, what would be a preferable alternative?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:115
- Comments:17 (1 by maintainers)
Top GitHub Comments
We can also try
@public
and@private
, and maybe even an option to mark everything as private by default:any updates?