Class: GraphQL::Subscriptions::BroadcastAnalyzer Private

Inherits:
Analysis::AST::Analyzer show all
Defined in:
lib/graphql/subscriptions/broadcast_analyzer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Detect whether the current operation:

  • Is a subscription operation
  • Is completely broadcastable

Assign the result to context.namespace(:subscriptions)[:subscription_broadcastable]

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(subject) ⇒ BroadcastAnalyzer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BroadcastAnalyzer.



13
14
15
16
17
18
# File 'lib/graphql/subscriptions/broadcast_analyzer.rb', line 13

def initialize(subject)
  super
  @default_broadcastable = subject.schema.subscriptions.default_broadcastable
  # Maybe this will get set to false while analyzing
  @subscription_broadcastable = true
end

Instance Method Details

#analyze?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Only analyze subscription operations

Returns:

  • (Boolean)


21
22
23
# File 'lib/graphql/subscriptions/broadcast_analyzer.rb', line 21

def analyze?
  @query.subscription?
end

#on_enter_field(node, parent, visitor) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/graphql/subscriptions/broadcast_analyzer.rb', line 25

def on_enter_field(node, parent, visitor)
  if (@subscription_broadcastable == false) || visitor.skipping?
    return
  end

  current_field = visitor.field_definition
  apply_broadcastable(current_field)

  current_type = visitor.parent_type_definition
  if current_type.kind.interface?
    pt = @query.possible_types(current_type)
    pt.each do |object_type|
      ot_field = @query.get_field(object_type, current_field.graphql_name)
      # Inherited fields would be exactly the same object;
      # only check fields that are overrides of the inherited one
      if ot_field && ot_field != current_field
        apply_broadcastable(ot_field)
      end
    end
  end
end

#resultvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Assign the result to context. (This method is allowed to return an error, but we don't need to)



50
51
52
53
# File 'lib/graphql/subscriptions/broadcast_analyzer.rb', line 50

def result
  query.context.namespace(:subscriptions)[:subscription_broadcastable] = @subscription_broadcastable
  nil
end