Sha256: da87d72a5f7e4d970b24df8460dfcca1b9c1bbc56158b73b3255b1184d565b7c
Contents?: true
Size: 824 Bytes
Versions: 25
Compression:
Stored size: 824 Bytes
Contents
class GraphQL::StaticValidation::FragmentsAreFinite include GraphQL::StaticValidation::Message::MessageHelper def validate(context) context.visitor[GraphQL::Language::Nodes::FragmentDefinition] << -> (node, parent) { if has_nested_spread(node, [], context) context.errors << message("Fragment #{node.name} contains an infinite loop", node) end } end private def has_nested_spread(fragment_def, parent_fragment_names, context) nested_spreads = fragment_def.selections .select {|f| f.is_a?(GraphQL::Language::Nodes::FragmentSpread)} nested_spreads.any? do |spread| nested_def = context.fragments[spread.name] parent_fragment_names.include?(spread.name) || has_nested_spread(nested_def, parent_fragment_names + [fragment_def.name], context) end end end
Version data entries
25 entries across 25 versions & 1 rubygems