Sha256: 84e2017c176c6f4381447ca7f9dc17b082ea73ef8728436b30be0fcadaa74f39

Contents?: true

Size: 690 Bytes

Versions: 2

Compression:

Stored size: 690 Bytes

Contents

module GraphQL
  module StaticValidation
    class DirectivesAreDefined
      include GraphQL::StaticValidation::Message::MessageHelper

      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

      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)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
graphql-0.18.1 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-0.18.0 lib/graphql/static_validation/rules/directives_are_defined.rb