lib/graphql/query/literal_input.rb in graphql-1.5.5 vs lib/graphql/query/literal_input.rb in graphql-1.5.6
- old
+ new
@@ -12,13 +12,13 @@
when Language::Nodes::VariableIdentifier
variables[ast_node.name]
else
case type
when GraphQL::ScalarType
- type.coerce_input(ast_node)
+ type.coerce_input(ast_node, variables.context)
when GraphQL::EnumType
- type.coerce_input(ast_node.name)
+ type.coerce_input(ast_node.name, variables.context)
when GraphQL::NonNullType
LiteralInput.coerce(type.of_type, ast_node, variables)
when GraphQL::ListType
if ast_node.is_a?(Array)
ast_node.map { |element_ast| LiteralInput.coerce(type.of_type, element_ast, variables) }
@@ -47,17 +47,24 @@
argument_defns.each do |arg_name, arg_defn|
ast_arg = indexed_arguments[arg_name]
# First, check the argument in the AST.
# If the value is a variable,
# only add a value if the variable is actually present.
- # Otherwise, coerce the value in the AST and add it.
+ # Otherwise, coerce the value in the AST, prepare the value and add it.
if ast_arg
- if ast_arg.value.is_a?(GraphQL::Language::Nodes::VariableIdentifier)
- if variables.key?(ast_arg.value.name)
- values_hash[ast_arg.name] = coerce(arg_defn.type, ast_arg.value, variables)
+ value_is_a_variable = ast_arg.value.is_a?(GraphQL::Language::Nodes::VariableIdentifier)
+
+ if (!value_is_a_variable || (value_is_a_variable && variables.key?(ast_arg.value.name)))
+
+ value = coerce(arg_defn.type, ast_arg.value, variables)
+ value = arg_defn.prepare(value)
+
+ if value.is_a?(GraphQL::ExecutionError)
+ value.ast_node = ast_arg
+ raise value
end
- else
- values_hash[ast_arg.name] = coerce(arg_defn.type, ast_arg.value, variables)
+
+ values_hash[ast_arg.name] = value
end
end
# Then, the definition for a default value.
# If the definition has a default value and