Class: GraphQL::StaticValidation::FragmentsAreUsed

Inherits:
Object
  • Object
show all
Includes:
Message::MessageHelper
Defined in:
lib/graphql/static_validation/rules/fragments_are_used.rb

Instance Method Summary collapse

Methods included from Message::MessageHelper

#message

Instance Method Details

#validate(context) ⇒ Object


4
5
6
7
8
9
10
11
# File 'lib/graphql/static_validation/rules/fragments_are_used.rb', line 4

def validate(context)
  v = context.visitor
  used_fragments = []
  defined_fragments = []
  v[GraphQL::Language::Nodes::FragmentSpread] << -> (node, parent) { used_fragments <<  node }
  v[GraphQL::Language::Nodes::FragmentDefinition] << -> (node, parent) { defined_fragments << node}
  v[GraphQL::Language::Nodes::Document].leave << -> (node, parent) { add_errors(context.errors, used_fragments, defined_fragments) }
end