Class: ShopifyClient::DeleteAllWebhooks

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify-client/delete_all_webhooks.rb

Instance Method Summary collapse

Instance Method Details

#call(client, ids: nil) ⇒ Object

Delete any existing webhooks.

Parameters:

  • client (Client)
  • ids (Array<Integer>, nil) (defaults to: nil)

    GraphQL IDs



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/shopify-client/delete_all_webhooks.rb', line 9

def call(client, ids: nil)
  ids ||= client.graphql(%({
    webhookSubscriptions(first: 100) {
      edges {
        node {
          id
        }
      }
    }
  })).data['data']['webhookSubscriptions']['edges'].map do |edge|
    edge['node']['id']
  end

  return if ids.empty?

  client.graphql(%(
    mutation webhookSubscriptionDelete(
      #{ids.each_with_index.map { |_, i| %(
        $id#{i}: ID!
      )}.join("\n")}
    ) {
      #{ids.each_with_index.map { |_, i| %(
        webhookSubscriptionDelete#{i}: webhookSubscriptionDelete(id: $id#{i}) {
          userErrors {
            field
            message
          }
        }
      )}.join("\n")}
    }
  ), ids.each_with_index.each_with_object({}) do |(id, i), variables|
    variables["id#{i}"] = id
  end)
end