Class: GraphQL::Relay::Mutation::Resolve Private

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/relay/mutation/resolve.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wrap a user-provided resolve function, wrapping the returned value in a Result. Also, pass the clientMutationId to that result object.

Instance Method Summary collapse

Constructor Details

#initialize(mutation, resolve) ⇒ Resolve

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Resolve.



10
11
12
13
14
# File 'lib/graphql/relay/mutation/resolve.rb', line 10

def initialize(mutation, resolve)
  @mutation = mutation
  @resolve = resolve
  @wrap_result = mutation.has_generated_return_type?
end

Instance Method Details

#call(obj, args, ctx) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql/relay/mutation/resolve.rb', line 16

def call(obj, args, ctx)
  mutation_result = begin
    @resolve.call(obj, args[:input], ctx)
  rescue GraphQL::ExecutionError => err
    err
  end

  if ctx.schema.lazy?(mutation_result)
    mutation_result
  else
    build_result(mutation_result, args, ctx)
  end
end