Module: GraphQL::StaticValidation::FragmentsAreFinite

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

Instance Method Summary collapse

Instance Method Details

#on_document(_n, _p) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/static_validation/rules/fragments_are_finite.rb', line 5

def on_document(_n, _p)
  super
  dependency_map = context.dependencies
  dependency_map.cyclical_definitions.each do |defn|
    if defn.node.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
      context.errors << GraphQL::StaticValidation::FragmentsAreFiniteError.new(
        "Fragment #{defn.name} contains an infinite loop",
        nodes: defn.node,
        path: defn.path,
        name: defn.name
      )
    end
  end
end