Class: GraphQL::StaticValidation::ArgumentsValidator

Inherits:
Object
  • Object
show all
Includes:
ArgumentsValidatorHelpers, Message::MessageHelper
Defined in:
lib/graphql/static_validation/arguments_validator.rb

Overview

Implement validate_node

Defined Under Namespace

Modules: ArgumentsValidatorHelpers

Instance Method Summary collapse

Methods included from Message::MessageHelper

#message

Instance Method Details

#validate(context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/graphql/static_validation/arguments_validator.rb', line 27

def validate(context)
  visitor = context.visitor
  visitor[GraphQL::Language::Nodes::Argument] << ->(node, parent) {
    case parent
    when GraphQL::Language::Nodes::InputObject
      arg_defn = context.argument_definition
      if arg_defn.nil?
        return
      else
        parent_defn = arg_defn.type.unwrap
        if !parent_defn.is_a?(GraphQL::InputObjectType)
          return
        end
      end
    when GraphQL::Language::Nodes::Directive
      parent_defn = context.schema.directives[parent.name]
    when GraphQL::Language::Nodes::Field
      parent_defn = context.field_definition
    else
      raise "Unexpected argument parent: #{parent.class} (##{parent})"
    end
    validate_node(parent, node, parent_defn, context)
  }
end