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.warden.directives.map(&:graphql_name)
end

#on_directive(node, parent) ⇒ Object



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

def on_directive(node, parent)
  if !@directive_names.include?(node.name)
    @directives_are_defined_errors_by_name ||= {}
    error = @directives_are_defined_errors_by_name[node.name] ||= begin
      err = GraphQL::StaticValidation::DirectivesAreDefinedError.new(
        "Directive @#{node.name} is not defined",
        nodes: [],
        directive: node.name
      )
      add_error(err)
      err
    end
    error.nodes << node
  else
    super
  end
end