class GraphQL::StaticValidation::DirectivesAreDefined

Public Instance Methods

validate(context) click to toggle source
# File lib/graphql/static_validation/rules/directives_are_defined.rb, line 6
def validate(context)
  directive_names = context.schema.directives.keys
  context.visitor[GraphQL::Language::Nodes::Directive] << ->(node, parent) {
    validate_directive(node, directive_names, context)
  }
end

Private Instance Methods

validate_directive(ast_directive, directive_names, context) click to toggle source
# File lib/graphql/static_validation/rules/directives_are_defined.rb, line 15
def validate_directive(ast_directive, directive_names, context)
  if !directive_names.include?(ast_directive.name)
    context.errors << message("Directive @#{ast_directive.name} is not defined", ast_directive, context: context)
    GraphQL::Language::Visitor::SKIP
  else
    nil
  end
end