Module: GraphQL::StaticValidation::FragmentSpreadsArePossible

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

Overview

-- @requires_ancestor: GraphQL::StaticValidation::BaseVisitor @requires_ancestor: GraphQL::StaticValidation::BaseVisitor::ContextMethods

Defined Under Namespace

Classes: FragmentSpread

Instance Method Summary collapse

Instance Method Details

#initialize(document, context) ⇒ Object

: (GraphQL::Language::Nodes::Document document, GraphQL::StaticValidation::ValidationContext context) -> void



11
12
13
14
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 11

def initialize(document, context)
  super
  @spreads_to_validate = [] #: Array[FragmentSpread]
end

#on_document(node, parent) ⇒ Object

: (GraphQL::Language::Nodes::Document node, GraphQL::Language::Nodes::AbstractNode? parent) -> void



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 34

def on_document(node, parent)
  super
  @spreads_to_validate.each do |frag_spread|
    frag_node = context.fragments[frag_spread.node.name]
    if frag_node
      fragment_child_name = frag_node.type.name
      fragment_child = types.type(fragment_child_name)
      # Might be non-existent type name
      if fragment_child
        validate_fragment_in_scope(frag_spread.parent_type, fragment_child, frag_spread.node, context, frag_spread.path)
      end
    end
  end
end

#on_fragment_spread(node, parent) ⇒ Object

: (GraphQL::Language::Nodes::FragmentSpread node, GraphQL::Language::Nodes::AbstractNode? parent) -> void



27
28
29
30
31
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 27

def on_fragment_spread(node, parent)
  fragment_parent = type_definition
  @spreads_to_validate << FragmentSpread.new(node: node, parent_type: fragment_parent, path: context.path)
  super
end

#on_inline_fragment(node, parent) ⇒ Object

: (GraphQL::Language::Nodes::InlineFragment node, GraphQL::Language::Nodes::AbstractNode? parent) -> void



17
18
19
20
21
22
23
24
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 17

def on_inline_fragment(node, parent)
  fragment_parent = parent_type_definition
  fragment_child = type_definition
  if fragment_child
    validate_fragment_in_scope(fragment_parent, fragment_child, node, context, context.path)
  end
  super
end