Sha256: 9d5b0b7099798708bed774fe96a1e15ef6db9afaf311183e6e819b5ad97a4a22

Contents?: true

Size: 757 Bytes

Versions: 40

Compression:

Stored size: 757 Bytes

Contents

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

      def validate(context)
        context.visitor[GraphQL::Language::Nodes::OperationDefinition] << ->(node, parent) {
          var_defns = node.variables
          if var_defns.any?
            vars_by_name = Hash.new { |h, k| h[k] = [] }
            var_defns.each { |v| vars_by_name[v.name] << v }
            vars_by_name.each do |name, defns|
              if defns.size > 1
                context.errors << message("There can only be one variable named \"#{name}\"", defns, context: context)
              end
            end
          end
        }
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

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