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
15
# File 'lib/graphql/relay/mutation/resolve.rb', line 10

def initialize(mutation, resolve)
  @mutation = mutation
  @resolve = resolve
  @wrap_result = mutation.is_a?(GraphQL::Relay::Mutation) && mutation.has_generated_return_type?
  @class_based = mutation.is_a?(Class)
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.



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

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