Module: GraphQL::StaticValidation::DirectivesAreDefined

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

Instance Method Summary collapse

Instance Method Details

#initializeObject



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

def initialize(*)
  super
  @directive_names = context.schema.directives.keys
end

#on_directive(node, parent) ⇒ Object



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

def on_directive(node, parent)
  if !@directive_names.include?(node.name)
    add_error(GraphQL::StaticValidation::DirectivesAreDefinedError.new(
      "Directive @#{node.name} is not defined",
      nodes: node,
      directive: node.name
    ))
  else
    super
  end
end