Module: GraphQL::Relay::Mutation::Instrumentation Private

Defined in:
lib/graphql/relay/mutation/instrumentation.rb

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

Class Method Summary collapse

Class Method Details

.instrument(type, field) ⇒ 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.

Modify mutation return_field resolves by wrapping the returned object in a Result.

By using an instrumention, we can apply our wrapper last, giving users access to the original resolve function in earlier instrumentation.



12
13
14
15
16
17
18
19
20
# File 'lib/graphql/relay/mutation/instrumentation.rb', line 12

def self.instrument(type, field)
  if field.mutation.is_a?(GraphQL::Relay::Mutation) || (field.mutation.is_a?(Class) && field.mutation < GraphQL::Schema::RelayClassicMutation)
    new_resolve = Mutation::Resolve.new(field.mutation, field.resolve_proc)
    new_lazy_resolve = Mutation::Resolve.new(field.mutation, field.lazy_resolve_proc)
    field.redefine(resolve: new_resolve, lazy_resolve: new_lazy_resolve)
  else
    field
  end
end