Module: GraphQL::StaticValidation::ArgumentNamesAreUnique

Includes:
Error::ErrorHelper
Defined in:
lib/graphql/static_validation/rules/argument_names_are_unique.rb

Instance Method Summary collapse

Methods included from Error::ErrorHelper

#error

Instance Method Details

#on_directive(node, parent) ⇒ Object



12
13
14
15
# File 'lib/graphql/static_validation/rules/argument_names_are_unique.rb', line 12

def on_directive(node, parent)
  validate_arguments(node)
  super
end

#on_field(node, parent) ⇒ Object



7
8
9
10
# File 'lib/graphql/static_validation/rules/argument_names_are_unique.rb', line 7

def on_field(node, parent)
  validate_arguments(node)
  super
end

#validate_arguments(node) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/graphql/static_validation/rules/argument_names_are_unique.rb', line 17

def validate_arguments(node)
  argument_defns = node.arguments
  if argument_defns.any?
    args_by_name = Hash.new { |h, k| h[k] = [] }
    argument_defns.each { |a| args_by_name[a.name] << a }
    args_by_name.each do |name, defns|
      if defns.size > 1
        add_error(GraphQL::StaticValidation::ArgumentNamesAreUniqueError.new("There can be only one argument named \"#{name}\"", nodes: defns, name: name))
      end
    end
  end
end