Module: GraphQL::StaticValidation::FragmentSpreadsArePossible

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

Defined Under Namespace

Classes: FragmentSpread

Instance Method Summary collapse

Instance Method Details

#initializeObject



5
6
7
8
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 5

def initialize(*)
  super
  @spreads_to_validate = []
end

#on_document(node, parent) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb', line 25

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 = context.warden.get_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



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

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

#on_inline_fragment(node, parent) ⇒ Object



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

def on_inline_fragment(node, parent)
  fragment_parent = context.object_types[-2]
  fragment_child = context.object_types.last
  if fragment_child
    validate_fragment_in_scope(fragment_parent, fragment_child, node, context, context.path)
  end
  super
end