Graphql-ruby: Unknown loads in input object

Created on 7 Sep 2018  路  9Comments  路  Source: rmosolgo/graphql-ruby

Hi!, is loads: in argument are only available from mutation classes?. because right now I'm using it in input objects and I'm getting an error of unknown keyword: loads. Thanks for the help. 馃槃

Most helpful comment

Yeah, it's currently only implemented for mutations. It could be added for input objects probably, with a bit of work.

All 9 comments

Yeah, it's currently only implemented for mutations. It could be added for input objects probably, with a bit of work.

Hey, @rmosolgo any work/progress on this? I don't mind working on a PR for this. I have just encountered a similar situation at work, trying to use the loads argument in the input object type.

I assume that the work involved here would be to reimplement the loads logic in the resolvers class for input objects -

https://github.com/rmosolgo/graphql-ruby/blob/3642ee92b722bccf49562fef9608eaab4e339711/lib/graphql/schema/resolver.rb#L329-L370

Let me know if you had better ideas. 馃槃

Thanks for the efforts put into building this gem!! 馃檶

Hi! No, I haven't done any work on it, I'd be happy to review a PR sometime though!

Sweet! I created a PR https://github.com/rmosolgo/graphql-ruby/pull/2080

I welcome any early feedback on the initial refactor... Thanks

Hey @lemuelbarango, what happened to close the PR?

@duderamos I've reopened the PR. was a mistake

No worries @lemuelbarango. I don't know if it helps, but I tested a scenario on my end and using prepare param seems enough:

https://github.com/rmosolgo/graphql-ruby/blob/master/lib/graphql/schema/argument.rb#L31

In my case, I have something like this:

module Foo
  class UpdateBarAttributes < Types::BaseInputObject
    argument :my_object_id, ID, required: true, prepare: :load_object
  end
end
module Types
  class BaseInputObject < GraphQL::Schema::InputObject
    def load_object(encoded_id)
      MySchema.object_from_id(encoded_id)
    end
  end
end

So I just need to append prepare: :load_object to my ID arguments.

@duderamos Yeah, I didn't know there was a prepare param on the InputObject. That's good to know.

Was this page helpful?
0 / 5 - 0 ratings