Module: GraphQL::Schema::HasSingleInputArgument

Included in:
RelayClassicMutation
Defined in:
lib/graphql/schema/has_single_input_argument.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#resolve_with_support(**inputs) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/graphql/schema/has_single_input_argument.rb', line 6

def resolve_with_support(**inputs)
  if inputs[:input].is_a?(InputObject)
    input = inputs[:input].to_kwargs
  else
    input = inputs[:input]
  end

  new_extras = field ? field.extras : []
  all_extras = self.class.extras + new_extras

  # Transfer these from the top-level hash to the
  # shortcutted `input:` object
  all_extras.each do |ext|
    # It's possible that the `extra` was not passed along by this point,
    # don't re-add it if it wasn't given here.
    if inputs.key?(ext)
      input[ext] = inputs[ext]
    end
  end

  if input
    # This is handled by Relay::Mutation::Resolve, a bit hacky, but here we are.
    input_kwargs = input.to_h
  else
    # Relay Classic Mutations with no `argument`s
    # don't require `input:`
    input_kwargs = {}
  end

  if input_kwargs.any?
    super(**input_kwargs)
  else
    super()
  end
end