Class: GraphQL::StaticValidation::ArgumentLiteralsAreCompatible

Inherits:
ArgumentsValidator show all
Defined in:
lib/graphql/static_validation/rules/argument_literals_are_compatible.rb

Instance Method Summary collapse

Methods inherited from ArgumentsValidator

#validate

Methods included from Message::MessageHelper

#message

Instance Method Details

#validate_node(node, defn, context) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/graphql/static_validation/rules/argument_literals_are_compatible.rb', line 2

def validate_node(node, defn, context)
  args_with_literals = node.arguments.select {|a| !a.value.is_a?(GraphQL::Language::Nodes::VariableIdentifier)}
  validator = GraphQL::StaticValidation::LiteralValidator.new
  args_with_literals.each do |arg|
    arg_defn = defn.arguments[arg.name]
    valid = validator.validate(arg.value, arg_defn.type)
    if !valid
      context.errors << message("Argument #{arg.name} on #{node.class.name.split("::").last} '#{node.name}' has an invalid value", node)
    end
  end
end