-
|
Please give me some advice from your experience on how it is better to restrict users of the GraphQL API from modifying all fields of a document except for several that are explicitly allowed, and allow them to modify only documents related to the current user? Let's take, as an example, the How to implement this in the best way? I see these options:
This option is recommended in the docs, but it looks to me not very good for performance, because the same check will be executed 10+ times (one time for each field).
Looks good to me, but is it okay to analyze the input data here and produce a conditional result (true/false) depending on the input data?
This looks good too, but I don't like that the access check is performed not in the access control hook, but in the operation execution hook.
This looks too complicated for such a common task. -- So, which approach is better to use for such tasks? Or suggest another option that is better than described. And would be awesome to update the documentation with more examples for such cases. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
And, actually, the same question is for the access control function for the "read" operation: I need to allow reading only a limited list of fields: id, createdAt, title, body, isRead, and archived, reading other fields should be restricted. Creating access control functions for each field would be a lot of boilerplate, and not good for performance, right? It's much better to handle a "allow list" of fields in a single place. |
Beta Was this translation helpful? Give feedback.
-
|
Hey @MurzNN this is a great question! I've run into this myself a few times. My suggested approach would be something like this: Then you can apply that access to each of your fields: Since Only the ownership constraint at the collection level hits the database, and that only runs once per request. For read access, you can use the same pattern — one shared The |
Beta Was this translation helpful? Give feedback.
Hey @MurzNN this is a great question! I've run into this myself a few times.
My suggested approach would be something like this:
Then you can apply that access to each of your fields: