Module: GraphQL::StaticValidation::SubscriptionRootExistsAndSingleSubscriptionSelection

Defined in:
lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb

Instance Method Summary collapse

Instance Method Details

#on_operation_definition(node, parent) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/graphql/static_validation/rules/subscription_root_exists_and_single_subscription_selection.rb', line 5

def on_operation_definition(node, parent)
  if node.operation_type == "subscription"
    if context.types.subscription_root.nil?
      add_error(GraphQL::StaticValidation::SubscriptionRootExistsError.new(
        'Schema is not configured for subscriptions',
        nodes: node
      ))
    elsif node.selections.size != 1
      add_error(GraphQL::StaticValidation::NotSingleSubscriptionError.new(
        'A subscription operation may only have one selection',
        nodes: node,
      ))
    else
      super
    end
  else
    super
  end
end