Module: GraphQL::Define::AssignArgument

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

Overview

Turn argument configs into a Argument.

Class Method Summary collapse

Class Method Details

.call(target, name, type = nil, description = nil, **rest, &block) ⇒ 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_argument.rb', line 5

def self.call(target, name, type = nil, description = nil, **rest, &block)
  argument = if block_given?
    GraphQL::Argument.define(&block)
  else
    GraphQL::Argument.new
  end

  unsupported_keys = rest.keys - [:default_value]
  if unsupported_keys.any?
    raise ArgumentError.new("unknown keyword#{unsupported_keys.length > 1 ? 's' : ''}: #{unsupported_keys.join(', ')}")
  end

  argument.name = name.to_s
  type && argument.type = type
  description && argument.description = description
  rest.key?(:default_value) && argument.default_value = rest[:default_value]

  target.arguments[name.to_s] = argument
end