-
Notifications
You must be signed in to change notification settings - Fork 1.4k
load: on plain argument #2762
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
Comments
Thanks for the detailed report, I'll take a look! |
I tried to replicate this issue in a little script, but it seemed to work for me: require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "graphql", "1.10.4"
source "https://gems.graphql.pro" do
gem "graphql-pro"
end
gem "pundit"
end
class ThingPolicy
def initialize(obj, viewer)
end
def view?
false
end
end
class BaseArgument < GraphQL::Schema::Argument
include GraphQL::Pro::PunditIntegration::ArgumentIntegration
pundit_role nil
end
class BaseField < GraphQL::Schema::Field
include GraphQL::Pro::PunditIntegration::FieldIntegration
pundit_role nil
argument_class(BaseArgument)
end
class BaseObject < GraphQL::Schema::Object
include GraphQL::Pro::PunditIntegration::ObjectIntegration
pundit_role nil
field_class(BaseField)
end
class Thing < BaseObject
field :name, String, null: false
end
class Query < BaseObject
field :thing, Thing, null: true do
argument :thing_id, ID, required: true, loads: Thing,
pundit_role: :view,
pundit_policy_class: ThingPolicy
end
def thing(thing: nil)
thing
end
end
class Schema < GraphQL::Schema
query Query
def self.object_from_id(id, ctx)
OpenStruct.new(name: id)
end
def self.resolve_type(abst_type, obj, ctx)
Thing
end
end
pp Schema.execute('{ thing(thingId: "stuff") { name } }').to_h It returned
Could you please share the full error message and stack trace? That would help me figure out what code is involved (and what code is not catching the error properly!) |
Are you |
Errors have been re-written for the interpreter and they're turned on by default in 1.12. I don't have any more info to debug here, so I'll close the issue. If you're still running into trouble after updating graphql-ruby, please open a new issue! |
@rmosolgo I am bumping into this too (Harry and I work together). The issue I am having is that the behaviour of Here's an enhanced example that demonstrates the difference in behaviour: require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "graphql", "1.13.10"
source "https://gems.graphql.pro" do
gem "graphql-pro", "1.21.4"
end
gem "pundit"
end
class ThingPolicy
def initialize(viewer, obj)
@obj = obj
end
def view?
puts "ThingPolicy#view? ran on #{@obj}"
true
end
def view_and_more?
puts "ThingPolicy#view_and_more? ran on #{@obj}"
true
end
end
class BaseArgument < GraphQL::Schema::Argument
include GraphQL::Pro::PunditIntegration::ArgumentIntegration
pundit_role nil
end
class BaseField < GraphQL::Schema::Field
include GraphQL::Pro::PunditIntegration::FieldIntegration
pundit_role nil
argument_class(BaseArgument)
end
class BaseObject < GraphQL::Schema::Object
include GraphQL::Pro::PunditIntegration::ObjectIntegration
pundit_role :view
field_class(BaseField)
end
class BaseMutation < GraphQL::Schema::Mutation
include GraphQL::Pro::PunditIntegration::MutationIntegration
object_class BaseObject
argument_class BaseArgument
field_class BaseField
pundit_role nil
end
class ThingType < BaseObject
field :name, String, null: false
end
class Query < BaseObject
pundit_role nil
field :thing, ThingType, null: true do
argument :thing_id, ID, required: true, loads: ThingType, pundit_role: :view_and_more
end
def thing(thing: nil)
thing
end
end
class CreateThing < BaseMutation
null true
argument :thing_id, ID, required: true, loads: ThingType, pundit_role: :view_and_more
payload_type ThingType
def resolve(thing:)
thing
end
end
class Mutation < BaseObject
pundit_role nil
field :create_thing, mutation: CreateThing
end
Thing = Struct.new(:id, :name)
class Schema < GraphQL::Schema
query Query
mutation ::Mutation
def self.object_from_id(id, ctx)
Thing.new(id, "test")
end
def self.resolve_type(abst_type, obj, ctx)
ThingType
end
end
pp Schema.execute('mutation { createThing(thingId: "stuff") { name } }').to_h
pp Schema.execute('{ thing(thingId: "stuff") { name } }').to_h which leads to the output
So the mutation case seems sane, if in a confusing order (shouldn't the argument's The query case however, the meaning of |
Uh oh!
There was an error while loading. Please reload this page.
We are starting to migrate to using loads: on plain arguments following this being merged #2720
When i use this in the context of a mutation and it fails the check i get a return of nil
So in the above example if you cant view object_id it returns nil
However
if i do this in the context of a type then i get
GraphQL::UnauthorizedError
error that bubbles out of graphql-ruby. Is this indented behaviour that loads works differently for different cases?I also dont seem to be able to catch the error inside my graphql schema with
We're on graphql 1.10.3 and graphql-pro 1.13.0
The text was updated successfully, but these errors were encountered: