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
30
31
32
33
34
35
36
37
38
39
40
# 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_default_value = arg_defn.default_value
    if ast_arg.nil? && arg_default_value.nil?
      # If it wasn't in the document,
      # and there's no provided default,
      # then don't pass it to the resolve function
      next
    else
      arg_value = nil

      if ast_arg
        arg_value = coerce(arg_defn.type, ast_arg.value, variables)
      end

      if arg_value.nil?
        arg_value = arg_default_value
      end

      values_hash[arg_name] = arg_value
    end
  end
  GraphQL::Query::Arguments.new(values_hash, argument_definitions: argument_defns)
end