-
Notifications
You must be signed in to change notification settings - Fork 36
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
[Bug] Guarding or masking a field on an Object Type hides the entire object and not just the individual field #47
Comments
Hi, just upgraded to 2.0 and have found a couple of issues (see issues) so was curious about this one. It would be good to include what you have in your In my case I have something like: use GraphQL::Guard.new(
policy_object: MyPolicy,
not_authorized: ->(*) { handler(*) }
) If a user is authorized and I add |
GQL Ruby adds this stuff (I remove it as it find it useless/inconsistent). Maybe this factors in to why you get the response you do? |
That's what I thought at first too, but I added this and it's what I currently have in my use GraphQL::Guard.new(
not_authorized: ->(type, field) do
GraphQL::ExecutionError.new("Not authorized to access #{type}.#{field}")
end
) Which I believe should only log an error message, but not nullify the entire object. |
@sshaw Just tried removing the |
Okay! I've figured something out and got it "working", but I feel there may still be improvements that can be made to the gem. It's all based around this section of the docs: https://github.com/exAspArk/graphql-guard#error-handling. # By default it raises an error
not_authorized: ->(type, field) do
raise GraphQL::Guard::NotAuthorizedError.new("#{type}.#{field}")
end This behaves as I would expect, it raises an error and the query fails. # Returns an error in the response
not_authorized: ->(type, field) do
GraphQL::ExecutionError.new("Not authorized to access #{type}.#{field}")
end I would expect this to return either 'null' or the error for the individual field, but not null the whole object type. Could this possibly be because my actual field was an integer value and it just couldn't cast the error to an integer? I didn't see any error that indicated that being the reason, but I wouldn't rule it out. not_authorized: ->(type, field) do
end This works and only nulls out the object level field I want. Interestingly enough returning -- Upon further review, after I started this comment, the following technically "works" if I change my field type to not_authorized: ->(type, field) do
GraphQL::ExecutionError.new("Not authorized to access #{type}.#{field}").to_s
end But of course, it returns -- Now that I've gone through these few different scenarios, I think the real bug is that if the Hopefully, that helps! At the very least I'm now able to use the gem as I intended with the below, but let me know if there's anything else I can assist with! not_authorized: ->(type, field) do
end |
Thanks for the info. I also see with the latest version of the Ruby GraphQL library one cannot return a |
Versions
graphql 1.11.2
graphql-guard 2.0.0
Example Code
Expected Response
Actual Response
null
I've also tried it using this syntax with the same results:
Let me know if I can provide any more information!
The text was updated successfully, but these errors were encountered: