Module: GraphQL::StaticValidation::ArgumentNamesAreUnique
- Includes:
- Error::ErrorHelper
- Defined in:
- lib/graphql/static_validation/rules/argument_names_are_unique.rb
Instance Method Summary collapse
- #on_directive(node, parent) ⇒ Object
- #on_field(node, parent) ⇒ Object
- #validate_arguments(node) ⇒ Object
Methods included from Error::ErrorHelper
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 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/graphql/static_validation/rules/argument_names_are_unique.rb', line 17 def validate_arguments(node) argument_defns = node.arguments if argument_defns.size > 1 seen = {} argument_defns.each do |a| name = a.name if seen.key?(name) prev = seen[name] if prev.is_a?(Array) prev << a else seen[name] = [prev, a] end else seen[name] = a end end seen.each do |name, val| if val.is_a?(Array) add_error(GraphQL::StaticValidation::ArgumentNamesAreUniqueError.new("There can be only one argument named \"#{name}\"", nodes: val, name: name)) end end end end |