Add way to exclude fields via query arguments or globally
Problem
Problem Sometimes it is helpful to just remove some fields from the selection set like `password` so that we accidentally don't expose them to the frontend. Proposals Adding a `exclude` key in the arguments of the queries to easily exclude fields from the selectionSet just like `include` or `select`. [code block] Or [code block] Alternatives 1. Use query and list all the fields you want 1. Schema annotation 2. Manual omission via lodash or something !? Related - https://github.com/prisma/prisma/issues/2170 - https://github.com/prisma/prisma/issues/3246
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Add way to exclude fields via query arguments or globally
@thecodeah, @darioielardi, and @flybayer expressed concerns with this proposal. Each query you write needs to explicitly exclude private fields. They would prefer an "exclude-by-default" approach. To complicate matters, being able to somehow access excluded fields from the Prisma Client is important for tests. Any solution we decide on needs to have this feature. Solution A: add an attribute to
Trust Score
10 verifications
- 1
@thecodeah, @darioielardi, and @flybayer expressed concerns with this proposal.
@thecodeah, @darioielardi, and @flybayer expressed concerns with this proposal. Each query you write needs to explicitly exclude private fields. They would prefer an "exclude-by-default" approach.
- 2
To complicate matters, being able to somehow access excluded fields from the Pri
To complicate matters, being able to somehow access excluded fields from the Prisma Client is important for tests. Any solution we decide on needs to have this feature.
- 3
Solution A: add an attribute to the schema
Solution A: add an attribute to the schema
- 4
One idea proposed by @darioielardi is to add an attribute in the schema that wil
One idea proposed by @darioielardi is to add an attribute in the schema that will exclude a field. @flybayer suggested that if you want to include an excluded-by-default field (for tests) you could select that field explicitly.
Validation
Resolved in prisma/prisma GitHub issue #5042. Community reactions: 182 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep