Sha256: d9a20b0dfcf2b51ed85c359d329117dc2e37b0d48b8005010e72b7481664d0eb

Contents?: true

Size: 716 Bytes

Versions: 5

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true
module GraphQL
  module StaticValidation
    module VariableNamesAreUnique
      def on_operation_definition(node, parent)
        var_defns = node.variables
        if !var_defns.empty?
          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
              add_error(GraphQL::StaticValidation::VariableNamesAreUniqueError.new(
                "There can only be one variable named \"#{name}\"",
                nodes: defns,
                name: name
              ))
            end
          end
        end
        super
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphql-2.4.9 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-2.4.8 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-2.4.7 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-2.4.6 lib/graphql/static_validation/rules/variable_names_are_unique.rb
graphql-2.4.5 lib/graphql/static_validation/rules/variable_names_are_unique.rb