Sha256: c89fa3c092fbd524bb3aa0f3e94c96ed7f23ad91505674263816f5bd3b77fe14

Contents?: true

Size: 789 Bytes

Versions: 75

Compression:

Stored size: 789 Bytes

Contents

# frozen_string_literal: true
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)
          GraphQL::Language::Visitor::SKIP
        else
          nil
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 1 rubygems

Version Path
graphql-1.5.10 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.9 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.8 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.7 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.6 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.5 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.4 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.5.3 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.5 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.4 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.3 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.2 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.1 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.4.0 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.3.0 lib/graphql/static_validation/rules/directives_are_defined.rb