Sha256: b1fed3ae3b2d53ba0f9a390d8764ba6c3fe68316b6d7775b3bc0260fcbe816e4

Contents?: true

Size: 975 Bytes

Versions: 17

Compression:

Stored size: 975 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    class ArgumentNamesAreUnique
      include GraphQL::StaticValidation::Message::MessageHelper

      def validate(context)
        context.visitor[GraphQL::Language::Nodes::Field] << ->(node, parent) {
          validate_arguments(node, context)
        }

        context.visitor[GraphQL::Language::Nodes::Directive] << ->(node, parent) {
          validate_arguments(node, context)
        }
      end

      def validate_arguments(node, context)
        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
              context.errors << message("There can be only one argument named \"#{name}\"", defns, context: context)
            end
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
graphql-1.8.18 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.17 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.16 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.15 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.14 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.13 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.12 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.11 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.10 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.9 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.8 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.7 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.6 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.5 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.4 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.3 lib/graphql/static_validation/rules/argument_names_are_unique.rb
graphql-1.8.2 lib/graphql/static_validation/rules/argument_names_are_unique.rb