-
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
incosistent subject used for CanCan integration #4291
Comments
Hey, sorry for the trouble with this! Thanks for reporting it, I definitely want to get to the bottom of it. As I try to understand what's going wrong, I'm wondering, what Also, would you mind sharing an example query that demonstrates this bug? It's not totally clear to me whether you expect |
I expect I know this is related to the gem cancancan and I do not know if this is the expected behaviour but it is leading to several issues with our application. I'm asking if you can do something with your CanCanIntegration now that we figured out this weird behaviour from cancancan
{:search=>
#<Search:0x000000012b07e280
id: 1,
type: "Search",
name: "Test search 1_380">,
:configuration=>{:my_field=>"hello"}} You can replicate the issue with this code that emulates the data CanCanCan receives from the CanCanIntegration: class Search < ActiveRecord::Base
end
class Ability
include CanCan::Ability
attr_accessor :user
def initialize
can :read, Search do |search|
puts search.class
true
end
end
end
Ability.new.can?(:read, { search: Search.new, configuration: {field: 'hello' }}) it will print or using a GraphQL query, it happens by just calling a resolver:
|
Thanks for sharing those details. Does your class SearchWithConfiguration
def initialize(search:, configuration:)
@search = search
@configuration = configuration
end
attr_reader :search, :configuration
end Then, return that from your resolver instead: # ...
SearchWithConfiguration.new(search: search, configuration: configuration) Then, when the What do you think of that approach? |
Thanks for your support, this solution seems to be working, it's not perfect but I understand this is due to CanCan behaviour so you can do little to change it. I think we can close the issue, thank you |
Describe the bug
Using the CanCan integration with a Resolver that returns a custom type with multiple fields gives inconsistent behaviour while choosing the right Ability rule to use.
with a bit of debugging I found out why this happens.
the line
subject = subject.values.first if subject.class == Hash
changes the subject to Search type but the rest of the code does not mirror this behaviour so it passes a Hash to the authorization block instead of using thesubject.values.first
value.At the same time, if I define a block like this
it is ignored
Versions
graphql (2.0.14)
graphql-pro (1.23.1)
GraphQL schema
my Resolver
the type I want to return and authorize
the Ability file
GraphQL query
Just calling the resover
Expected behavior
I expected the block to be called with a Search object
Actual behavior
The block is being called with a Hash
The text was updated successfully, but these errors were encountered: