Class: GraphqlChannel

Inherits:
ApplicationCable::Channel show all
Defined in:
app/channels/graphql_channel.rb

Overview

Instance Method Summary collapse

Instance Method Details

#subscribedObject

rubocop:disable Gitlab/NamespacedClass



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/channels/graphql_channel.rb', line 7

def subscribed
  @subscription_ids = []

  query = params['query']
  variables = Gitlab::Graphql::Variables.new(params['variables']).to_h
  operation_name = params['operationName']

  result = GitlabSchema.execute(
    query,
    context: context,
    variables: variables,
    operation_name: operation_name
  )

  payload = {
    result: result.to_h,
    more: result.subscription?
  }

  # Track the subscription here so we can remove it
  # on unsubscribe.
  @subscription_ids << result.context[:subscription_id] if result.context[:subscription_id]

  transmit(payload)
end

#unsubscribedObject



33
34
35
36
37
# File 'app/channels/graphql_channel.rb', line 33

def unsubscribed
  @subscription_ids.each do |sid|
    GitlabSchema.subscriptions.delete_subscription(sid)
  end
end