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
# File 'lib/graphql/static_validation/rules/directives_are_defined.rb', line 5

def initialize(*)
  super
end

#on_directive(node, parent) ⇒ Object



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

def on_directive(node, parent)
  if !@types.directive_exists?(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