Class: ShopifyGraphql::Webhook
- Inherits:
-
Object
- Object
- ShopifyGraphql::Webhook
- Includes:
- Resource
- Defined in:
- lib/shopify_graphql/resources/webhook.rb
Constant Summary collapse
- ALL_WEBHOOKS_QUERY =
"query {\n webhookSubscriptions(first: 250) {\n edges {\n node {\n id\n topic\n endpoint {\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n }\n }\n }\n }\n}\n"- CREATE_WEBHOOK_MUTATION =
"mutation($topic: WebhookSubscriptionTopic!, $webhookSubscription: WebhookSubscriptionInput!) {\n webhookSubscriptionCreate(topic: $topic, webhookSubscription: $webhookSubscription) {\n webhookSubscription {\n id\n }\n userErrors {\n field\n message\n }\n }\n}\n"- DELETE_WEBHOOK_MUTATION =
"mutation($id: ID!) {\n webhookSubscriptionDelete(id: $id) {\n deletedWebhookSubscriptionId\n userErrors {\n field\n message\n }\n }\n}\n"
Class Method Summary collapse
Class Method Details
.all ⇒ Object
50 51 52 53 54 55 |
# File 'lib/shopify_graphql/resources/webhook.rb', line 50 def all response = execute(ALL_WEBHOOKS_QUERY) response.data.webhookSubscriptions.edges.map do |edge| edge.node end end |
.create(topic:, address:, include_fields:) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/shopify_graphql/resources/webhook.rb', line 57 def create(topic:, address:, include_fields:) response = execute(CREATE_WEBHOOK_MUTATION, topic: topic, webhookSubscription: { callbackUrl: address, format: 'JSON', includeFields: include_fields, }, ) response = response.data.webhookSubscriptionCreate handle_user_errors(response) end |
.delete(id) ⇒ Object
70 71 72 73 74 |
# File 'lib/shopify_graphql/resources/webhook.rb', line 70 def delete(id) response = execute(DELETE_WEBHOOK_MUTATION, id: id) response = response.data.webhookSubscriptionDelete handle_user_errors(response) end |