Sha256: c43ca3ed594cc316cd0264f342ea83d6d2784bb3c7363fb000597f21d787f99e
Contents?: true
Size: 942 Bytes
Versions: 13
Compression:
Stored size: 942 Bytes
Contents
module GraphQL module StaticValidation class 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, context: context) 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 end end
Version data entries
13 entries across 13 versions & 1 rubygems