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.8.18 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.17 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.16 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.15 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.14 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.13 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.12 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.11 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.10 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.9 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.8 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.7 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.6 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.5 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.4 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.3 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.2 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.1 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.0 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.8.0.pre11 lib/graphql/static_validation/rules/directives_are_defined.rb