Sha256: b3cf82a2b51ca052fd92915a15da5e603e0e49f52308b2604a35895b124e2e73
Contents?: true
Size: 924 Bytes
Versions: 13
Compression:
Stored size: 924 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) 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