Class: GraphQL::StaticValidation::FragmentsAreFinite

Inherits:
Object
  • Object
show all
Includes:
Message::MessageHelper
Defined in:
lib/graphql/static_validation/rules/fragments_are_finite.rb

Instance Method Summary collapse

Methods included from Message::MessageHelper

#message

Instance Method Details

#validate(context) ⇒ Object


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

def validate(context)
  context.visitor[GraphQL::Language::Nodes::Document].leave << ->(_n, _p) do
    dependency_map = context.dependencies
    dependency_map.cyclical_definitions.each do |defn|
      if defn.node.is_a?(GraphQL::Language::Nodes::FragmentDefinition)
        context.errors << message("Fragment #{defn.name} contains an infinite loop", defn.node, path: defn.path)
      end
    end
  end
end