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