What kind of magic is this?
class Types::Mutation < Types::BaseObject
field :createUser, mutation: Mutations::CreateUser
...
end
class Mutations::CreateUser < Mutations::BaseMutation
argument :email, String, required: true
argument :password, String, required: true
type Types::User
def resolve args
# binding.pry
User.create!(args.slice(:email, :password) )
rescue ActiveRecord::RecordInvalid => e
GraphQL::ExecutionError.new("Invalid input: #{e.record.errors.full_messages.join(', ')}")
end
end
Runing mutation:

Got: can't write unknown attribute client_mutation_id, but user was created!
Running pry
From: /home/user/code/walexypro/app/graphql/mutations/create_user.rb @ line 8 Mutations::CreateUser#resolve:
7: def resolve args
=> 8: binding.pry
9: User.create!(args.slice(:email, :password) )
10: rescue ActiveRecord::RecordInvalid => e
11: GraphQL::ExecutionError.new("Invalid input: #{e.record.errors.full_messages.join(', ')}")
12: end
[WallexyPro][development] #<Mutations::CreateUser:0x000055a7ab7d0ac0>:0> args
=> {:email=>"[email protected]", :password=>"123123123"}
[WallexyPro][development] #<Mutations::CreateUser:0x000055a7ab7d0ac0>:0> User.create!(args )
User created with no problems. adding args.slice(:email, :password) not helps too.
def resolve args
# binding.pry
# User.create!(args)
User.first
# rescue ActiveRecord::RecordInvalid => e
# GraphQL::ExecutionError.new("Invalid input: #{e.record.errors.full_messages.join(', ')}")
end
def resolve email:, password:
# binding.pry
# User.create!(args)
User.first
# rescue ActiveRecord::RecordInvalid => e
# GraphQL::ExecutionError.new("Invalid input: #{e.record.errors.full_messages.join(', ')}")
end
Two variants above got same error can't write unknown attribute client_mutation_id
I have only one question WTF happens here?
If I'm not mistaken, client_mutation_id is part of a Relay Input Object and not part of a basic mutation. Can you try to extend your mutations from GraphQL::Schema::RelayClassicMutation instead of Mutations::BaseMutation and see what happens?
Yeah, I think @Willianvdv is on to something. Does your Mutations::BaseMutation extend RelayClassicMutation? If so, you need to return a hash and use field ... to describe the return type instead of type ....
If you want to use type ... maybe you shold extend GraphQL::Schema::Mutation instead. See also https://github.com/rmosolgo/graphql-ruby/issues/1638
@Willianvdv thanks for renaming this issue to something descriptive and helpful 馃槈
class Mutations::BaseMutation < GraphQL::Schema::RelayClassicMutation
end
class Mutations::CreateUser < Mutations::BaseMutation
argument :email, String, required: true
argument :password, String, required: true
field :user, Types::User, null: false
def resolve email:, password:
# binding.pry
# User.create!(args)
# rescue ActiveRecord::RecordInvalid => e
# GraphQL::ExecutionError.new("Invalid input: #{e.record.errors.full_messages.join(', ')}")
User.first
end
end
same error https://i.imgur.com/70ZYSXO.png
try
- User.first
+ { user: User.first }
So that field :user, ... will look up the :user key in that Hash.
@rmosolgo thanks, this works
Most helpful comment
try
So that
field :user, ...will look up the:userkey in that Hash.