Module: GraphQL::Define::AssignMutationFunction

Defined in:
lib/graphql/define/assign_mutation_function.rb

Defined Under Namespace

Classes: ResultProxy

Class Method Summary collapse

Class Method Details

.call(target, function) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql/define/assign_mutation_function.rb', line 5

def self.call(target, function)
  # TODO: get all this logic somewhere easier to test

  if !function.type.is_a?(GraphQL::ObjectType)
    raise "Mutation functions must return object types (not #{function.type.unwrap})"
  end

  target.return_type = function.type.redefine {
    name(target.name + "Payload")
    field :clientMutationId, types.String, "A unique identifier for the client performing the mutation.", property: :client_mutation_id
  }

  target.arguments = function.arguments
  target.description = function.description
  target.resolve = ->(o, a, c) {
    res = function.call(o, a, c)
    ResultProxy.new(res, a[:clientMutationId])
  }
end