Class: GraphQL::StaticValidation::SubscriptionRootExists

Inherits:
Object
  • Object
show all
Includes:
Message::MessageHelper
Defined in:
lib/graphql/static_validation/rules/subscription_root_exists.rb

Instance Method Summary collapse

Methods included from Message::MessageHelper

#message

Instance Method Details

#validate(context) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/graphql/static_validation/rules/subscription_root_exists.rb', line 7

def validate(context)
  return if context.warden.root_type_for_operation("subscription")

  visitor = context.visitor

  visitor[GraphQL::Language::Nodes::OperationDefinition].enter << ->(ast_node, prev_ast_node) {
    if ast_node.operation_type == 'subscription'
      context.errors << message('Schema is not configured for subscriptions', ast_node, context: context)
      return GraphQL::Language::Visitor::SKIP
    end
  }
end