-
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
[pro] Pundit integration fails with plain Array field #2008
Comments
👌 Thanks for the bug report, I'll take a look and follow up here. |
Any progress/update on this? We're currently blocked on a few fronts because of this bug. Thanks 😄 |
My workaround: module Types
class BaseObject < GraphQL::Schema::Object
# override
# see: https://github.com/rmosolgo/graphql-ruby/issues/2008
def self.scope_by_policy(items, context)
items.is_a?(Array) ? items : super
end
end
end |
Thanks for the bump here, this slipped off my radar over the holidays 😊 I just pushed graphql-pro 1.9.5 which includes the same kind of solution that @cainlevy posted. Thanks for sharing your workaround and let me know if you run into any trouble with that new version! |
Context
Every mutation in my GraphQL API may optionally return a list of validation errors (as data). This is typed as:
Now I'm adding Pundit integration, and my tests fail with:
Bug
The problem is that
Pundit::PolicyFinder
expects an Array to be a list of constant names, not a list of values. Thus, any attempt to return more than one ServiceError will fail the policy lookup.This logic is not problematic for Relations, because a Relation is not an Array.
Example
Suggestion
Disable scoping logic for plain arrays. It's a conceptual mismatch.
Workarounds
scope: false
on everythingScopeByPolicy
logicThe text was updated successfully, but these errors were encountered: