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.0.pre10 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.14 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre9 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre8 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.13 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre7 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.12 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.11 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.10 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre6 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre5 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.9 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre4 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre3 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.8 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre2 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.7 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.8.0.pre1 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.6 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-1.7.5 lib/graphql/static_validation/rules/variable_names_are_unique.rb