Sha256: d9448ea119b139a627024c2e3c69be1a9d33d8c5ef342e541cafd4948f95ef6f

Contents?: true

Size: 759 Bytes

Versions: 10

Compression:

Stored size: 759 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)
          GraphQL::Language::Visitor::SKIP
        else
          nil
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
graphql-1.2.6 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.5 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.4 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.3 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.2 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.1 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.2.0 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.1.0 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-1.0.0 lib/graphql/static_validation/rules/directives_are_defined.rb
graphql-0.19.4 lib/graphql/static_validation/rules/directives_are_defined.rb