Class: GraphQL::Query::Arguments

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/graphql/query/arguments.rb

Overview

Read-only access to values, normalizing all keys to strings

Arguments recursively wraps the input in Arguments instances.

Defined Under Namespace

Classes: ArgumentValue

Instance Method Summary collapse

Constructor Details

#initialize(values, argument_definitions:) ⇒ Arguments

Returns a new instance of Arguments.



9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/query/arguments.rb', line 9

def initialize(values, argument_definitions:)
  @original_values = values
  @argument_values = values.inject({}) do |memo, (inner_key, inner_value)|
    string_key = inner_key.to_s
    arg_defn = argument_definitions[string_key]
    arg_value = wrap_value(inner_value, arg_defn.type)
    memo[string_key] = ArgumentValue.new(string_key, arg_value, arg_defn)
    memo
  end
end

Instance Method Details

#[](key) ⇒ Object

Returns the argument at that key.

Parameters:

  • key (String, Symbol)

    name or index of value to access

Returns:

  • (Object)

    the argument at that key



22
23
24
# File 'lib/graphql/query/arguments.rb', line 22

def [](key)
  @argument_values.fetch(key.to_s, NULL_ARGUMENT_VALUE).value
end

#each_value {|argument_value| ... } ⇒ Object

Access each key, value and type for the arguments in this set.

Yields:

Yield Parameters:



43
44
45
46
47
# File 'lib/graphql/query/arguments.rb', line 43

def each_value
  @argument_values.each_value do |argument_value|
    yield(argument_value)
  end
end

#key?(key) ⇒ Boolean

Returns true if the argument was present in this field.

Parameters:

  • key (String, Symbol)

    name of value to access

Returns:

  • (Boolean)

    true if the argument was present in this field



28
29
30
# File 'lib/graphql/query/arguments.rb', line 28

def key?(key)
  @argument_values.key?(key.to_s)
end

#to_hHash

Get the original Ruby hash

Returns:

  • (Hash)

    the original values hash



34
35
36
# File 'lib/graphql/query/arguments.rb', line 34

def to_h
  @unwrapped_values ||= unwrap_value(@original_values)
end