Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warnings for Field Access Control limitations with context.db #9034

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

dcousens
Copy link
Member

@dcousens dcousens commented Feb 22, 2024

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, and update field operations. The behavior of context.db.* not adhering to {field}.access.read is likely not apparent to many developers, especially when many developers often prefer context.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

field-level rules for... Read - [are] applied when the field is selected through any GraphQL operation

Since context.db.* operations don't pass through the GraphQL layer, and interact directly with Prisma, applying read 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 as virtual 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 to context.db operations. This should help prevent confusion until we bridge the gap between context.query and Typescript.

@dcousens dcousens changed the title Add warnings for Field Access Control limitation with context.db Add warnings for Field Access Control limitations with context.db Feb 22, 2024

This comment was marked as resolved.

Copy link
Member

@emmatown emmatown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth noting in the docs that if you return what you get from context.db in a GraphQL resolver, read field access control will apply?

@dcousens dcousens merged commit 4ad977f into main Feb 26, 2024
1 check passed
@dcousens dcousens deleted the field-access-quirks branch February 26, 2024 03:36
@dcousens dcousens mentioned this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants