Class: GraphQL::Query::LiteralInput

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/query/literal_input.rb

Overview

Turn query string values into something useful for query execution

Class Method Summary collapse

Class Method Details

.coerce(type, value, variables) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/graphql/query/literal_input.rb', line 5

def self.coerce(type, value, variables)
  if value.is_a?(Language::Nodes::VariableIdentifier)
    variables[value.name]
  elsif value.nil?
    nil
  else
    LiteralKindCoercers::STRATEGIES.fetch(type.kind).coerce(value, type, variables)
  end
end

.from_arguments(ast_arguments, argument_defns, variables) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/graphql/query/literal_input.rb', line 15

def self.from_arguments(ast_arguments, argument_defns, variables)
  values_hash = {}
  argument_defns.each do |arg_name, arg_defn|
    ast_arg = ast_arguments.find { |ast_arg| ast_arg.name == arg_name }
    arg_value = nil
    if ast_arg
      arg_value = coerce(arg_defn.type, ast_arg.value, variables)
    end
    if arg_value.nil?
      arg_value = arg_defn.type.coerce_input(arg_defn.default_value)
    end
    values_hash[arg_name] = arg_value
  end
  GraphQL::Query::Arguments.new(values_hash)
end