Previously the mutation was defined like this:
class Mutations::SomeMutation < Mutations::BaseMutation
null false
argument :some_argument, String, required: true
field :some_field, String, null: false
def resolve(some_argument:)
...
end
end
And the following mutation would return the clientMutationId
when specified.
mutation {
someMutation(
input: {
someArgument: "string"
clientMutationId: "123"
}
) {
someField
clientMutationId
}
}
{
"data": {
"someMutation": {
"someField": "hello",
"clientMutationId": "123"
}
}
}
However after adding specific classes for the arguments and return type it no longer works without specifically adding the clientMutationId
field to the return type:
class Mutations::SomeMutation < Mutations::BaseMutation
null false
class SomeInput < Types::BaseInputObject
argument :some_argument, String, required: true
end
input_object_class SomeInput
class SuccessResult < Types::BaseObject
field :some_field, String, null: false
field :client_mutation_id, String, null: true
end
class SomeMutationResult < Types::BaseUnion
possible_types SuccessResult, ErrorType
def self.resolve_type(object, _context)
object[:some_field].valid? ? SuccessResult : ErrorType
end
end
type SomeMutationResult
def resolve(some_argument:)
...
end
end
I'm guessing because the return type does not exist inside the class that inherits from BaseMutation
it loses this functionality.
Here is what the base class looks like:
module Mutations
class BaseMutation < GraphQL::Schema::RelayClassicMutation
argument_class Types::BaseArgument
field_class Types::BaseField
input_object_class Types::BaseInputObject
object_class Types::BaseObject
end
end
All of these classes are just inheriting from the standard GraphQL classes from the Gem.