Add warnings for Field Access Control limitations with context.db
#9034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request adds a warning to the field access control documentation to clarify that field access control rules do not apply when using
context.db.*
for database operations.Keystone has a number of access control capabilities, including field-level access control for
read
,create
, andupdate
field operations. The behavior ofcontext.db.*
not adhering to{field}.access.read
is likely not apparent to many developers, especially when many developers often prefercontext.db.*
for the refined Typescript support.Field access control has been designed to co-operate with GraphQL resolvers, ensuring that any data returned by your GraphQL API respects the field access control rules for a set of particular output types. We refer to this in the documentation as
Since
context.db.*
operations don't pass through the GraphQL layer, and interact directly with Prisma, applyingread
field-level access controls isn't straight forward. You especially need to consider that many fields don't have reasonable behavior without passing through GraphQL output resolvers first, such asvirtual
fields.That said, developers are incentivized to use
context.db
for the superior Typescript integration at this stage of Keystone 6's development, therefore we need to capture these limitations more readily in the documentation; and we should potentially review this behaviour in upcoming major versions.This pull request adds some warnings that explicitly state that
access.read
field access control rules are not applied tocontext.db
operations. This should help prevent confusion until we bridge the gap betweencontext.query
and Typescript.