-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Authorization: Scoping #1671
Comments
I suppose this works with fields that return AR relations because AR won't materialize the actual array until as late as possible so you can always append more (It's not clear to me if there's any kind of helper that would make our use case better though.) |
There's really not yet, but maybe the trick is to implement this feature on top of #1411, which would give a proper way to add layers to resolve. |
Fixed by #1723 |
One related feature to authorization is scoping (see a comment on the auth PR, Pundit scopes and CanCan
accessible_by
.In this feature, there's a function that takes
(items, context)
as input and returnsfiltered_items
, where items has been scoped to remove items that are inaccessible tocontext
. For example, an ActiveRecord::Relation might receive.where
calls or an Array might receive.select
.This is different than filtering a list based on a GraphQL field's arguments, because the filtering might be based on something outside the client's control (for example, the current user's permission level). Also, the same filter may apply to lists of the same kinds of objects, even if those lists are returned from different fields or different combinations of arguments.
This feature is complementary to authorization. Authorization is a last-ditch effort to avoid returning unauthorized objects to clients; scoping is part of the application logic to filter return values. (An authorization failure should probably be corrected by adding filtering to a resolve method; scoping may be that filtering.)
How can it be added to GraphQL-Ruby? How about:
.scope_list(list, context)
methodT
, it callsT.scope_list(list, context)
with the returned values. The return ofT.scope_list
is used in place of the originally-returned list..scope_list
isreturn list
(no-op)Advantages:
Disadvantages:
list
and routing it to different methods, egfilter_array
andfilter_relation
)Any other thoughts on this?
The text was updated successfully, but these errors were encountered: