Add warnings for Field Access Control limitations with context.db#9034
Merged
Conversation
context.dbcontext.db
This comment was marked as resolved.
This comment was marked as resolved.
borisno2
approved these changes
Feb 22, 2024
emmatown
reviewed
Feb 22, 2024
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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, andupdatefield operations. The behavior ofcontext.db.*not adhering to{field}.access.readis 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, applyingreadfield-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 asvirtualfields.That said, developers are incentivized to use
context.dbfor 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.readfield access control rules are not applied tocontext.dboperations. This should help prevent confusion until we bridge the gap betweencontext.queryand Typescript.