Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Rails Graphql resolve error: wrong number of arguments (given 1, expected 3)

I created fresh rails app with graphql, but had a lot of problems agains guides aged 6+ months. I suspect that graphql-ruby changing quite fast.

So my last issue in resolve method:

module Types
  class QueryType < Types::BaseObject
    graphql_name "Root Query"
    description "The query root of this schema"

    field :allProducts, [ProductType], null: false do
      resolve ->(_obj, _args, _ctx) { Product.all }
    end
  end
end

Error:

wrong number of arguments (given 1, expected 3)
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/field.rb:430:in `resolve'
/Users/alder/Projects/_apps/service_exchange/any-do-api/app/graphql/types/query_type.rb:7:in `block in <class:QueryType>'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/field.rb:222:in `instance_eval'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/field.rb:222:in `initialize'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/member/accepts_definition.rb:142:in `initialize'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/field.rb:88:in `new'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/field.rb:88:in `from_options'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/graphql-1.9.0.pre1/lib/graphql/schema/member/has_fields.rb:52:in `field'
/Users/alder/Projects/_apps/service_exchange/any-do-api/app/graphql/types/query_type.rb:6:in `<class:QueryType>'
/Users/alder/Projects/_apps/service_exchange/any-do-api/app/graphql/types/query_type.rb:2:in `<module:Types>'
/Users/alder/Projects/_apps/service_exchange/any-do-api/app/graphql/types/query_type.rb:1:in `<main>'

Full log

You can check out the full project here

I'm using the latest version:

gem "graphql", "~> 1.9.0.pre1"

But the same error with 1.8.*

Upvotes: 5

Views: 1944

Answers (1)

Alexander Kireyev
Alexander Kireyev

Reputation: 10825

Ok, that resolve thing doesn't work anymore. Next code works fine:

class QueryType < Types::BaseObject
  graphql_name "RootQuery"

  field :categories, [Types::CategoryType], null: false

  def categories
    Category.all
  end
end

Upvotes: 7

Related Questions