Module: GraphQL::StaticValidation::FragmentNamesAreUnique

Defined in:
lib/graphql/static_validation/rules/fragment_names_are_unique.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



6
7
8
9
# File 'lib/graphql/static_validation/rules/fragment_names_are_unique.rb', line 6

def initialize(*)
  super
  @fragments_by_name = Hash.new { |h, k| h[k] = [] }
end

#on_document(_n, _p) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphql/static_validation/rules/fragment_names_are_unique.rb', line 16

def on_document(_n, _p)
  super
  @fragments_by_name.each do |name, fragments|
    if fragments.length > 1
      add_error(GraphQL::StaticValidation::FragmentNamesAreUniqueError.new(
        %|Fragment name "#{name}" must be unique|,
        nodes: fragments,
        name: name
      ))
    end
  end
end

#on_fragment_definition(node, parent) ⇒ Object



11
12
13
14
# File 'lib/graphql/static_validation/rules/fragment_names_are_unique.rb', line 11

def on_fragment_definition(node, parent)
  @fragments_by_name[node.name] << node
  super
end