-
Notifications
You must be signed in to change notification settings - Fork 31
Class based API: parent object passed to policy is instance of the object type class, not an instance of the model class. #53
Comments
@phyrog - Am I missing something here? That is not the intended behavior is it? |
No, you're right, that shouldn't happen. The fix for Edit: The reason for scope being more complicated is that the return values of the scopes need to be wrapped with a graphql type before calling the resolve method or returning; the easiest solution is probably just to take the class of the originally passed in parent object and wrap the return value in that, but I'm not sure yet if that already solves the problem. Side note: the internals of graphql-ruby are currently really complicated with the new API building on top of the old API, but also mixing in new code into the old stuff (e.g. the new resolver stuff that wraps values in the type classes). I hope this will become cleaner in the future. |
Thanks for the explanation. |
I came across this and fixed it by defining a So my def policy_class
self.class.name.gsub(/^Types::(\w+)Type$/, "\\1Policy")
end |
Quick heads up from me: While I no longer officially work for Ontohub, I will still support this Gem in the future. However: I don't think there currently is a fix for this issue that doesn't involve rewriting large portions of the code; that, and the planned graphql-ruby support for authorization and scopes mean, that this issue will probably have to wait for a while until the situation on the graphql-ruby side has settled down a bit. In the meantime, I would suggest either using the define-based API (at least for the types that need authorization) or the workaround by @jejacks0n. On the other hand: If someone wants to take a shot at this, feel free to create a PR 😁 |
When calling authorize, the 'parent object' passed to the policy is not an instance of the relevant model, it is instead an instance of the object type.
The text was updated successfully, but these errors were encountered: