diff --git a/lib/shopify_api/webhooks/registrations/event_bridge.rb b/lib/shopify_api/webhooks/registrations/event_bridge.rb index 51076861..beb65b0a 100644 --- a/lib/shopify_api/webhooks/registrations/event_bridge.rb +++ b/lib/shopify_api/webhooks/registrations/event_bridge.rb @@ -30,6 +30,8 @@ def build_check_query edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookEventBridgeEndpoint { @@ -48,12 +50,17 @@ def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil current_address = nil + fields = nil + metafield_namespaces = nil unless edges.empty? node = edges[0]["node"] webhook_id = node["id"].to_s current_address = node["endpoint"]["arn"].to_s + fields = node["includeFields"] + metafield_namespaces = node["metafieldNamespaces"] end - { webhook_id: webhook_id, current_address: current_address } + { webhook_id: webhook_id, current_address: current_address, fields: fields, + metafield_namespaces: metafield_namespaces, } end end end diff --git a/lib/shopify_api/webhooks/registrations/http.rb b/lib/shopify_api/webhooks/registrations/http.rb index a8446ac2..9c33f2b7 100644 --- a/lib/shopify_api/webhooks/registrations/http.rb +++ b/lib/shopify_api/webhooks/registrations/http.rb @@ -36,6 +36,8 @@ def build_check_query edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookHttpEndpoint { @@ -54,6 +56,8 @@ def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil current_address = nil + fields = nil + metafield_namespaces = nil unless edges.empty? node = edges[0]["node"] webhook_id = node["id"].to_s @@ -63,8 +67,11 @@ def parse_check_result(body) else node["callbackUrl"].to_s end + fields = node["includeFields"] + metafield_namespaces = node["metafieldNamespaces"] end - { webhook_id: webhook_id, current_address: current_address } + { webhook_id: webhook_id, current_address: current_address, fields: fields, + metafield_namespaces: metafield_namespaces, } end end end diff --git a/lib/shopify_api/webhooks/registrations/pub_sub.rb b/lib/shopify_api/webhooks/registrations/pub_sub.rb index c1a22934..9c06f271 100644 --- a/lib/shopify_api/webhooks/registrations/pub_sub.rb +++ b/lib/shopify_api/webhooks/registrations/pub_sub.rb @@ -34,6 +34,8 @@ def build_check_query edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookPubSubEndpoint { @@ -53,12 +55,17 @@ def parse_check_result(body) edges = body.dig("data", "webhookSubscriptions", "edges") || {} webhook_id = nil current_address = nil + fields = nil + metafield_namespaces = nil unless edges.empty? node = edges[0]["node"] webhook_id = node["id"].to_s current_address = "pubsub://#{node["endpoint"]["pubSubProject"]}:#{node["endpoint"]["pubSubTopic"]}" + fields = node["includeFields"] + metafield_namespaces = node["metafieldNamespaces"] end - { webhook_id: webhook_id, current_address: current_address } + { webhook_id: webhook_id, current_address: current_address, fields: fields, + metafield_namespaces: metafield_namespaces, } end end end diff --git a/lib/shopify_api/webhooks/registry.rb b/lib/shopify_api/webhooks/registry.rb index df8ebb1b..a274f63b 100644 --- a/lib/shopify_api/webhooks/registry.rb +++ b/lib/shopify_api/webhooks/registry.rb @@ -221,7 +221,9 @@ def webhook_registration_needed?(client, registration) "Failed to check if webhook was already registered" unless check_response.ok? parsed_check_result = registration.parse_check_result(T.cast(check_response.body, T::Hash[String, T.untyped])) - must_register = parsed_check_result[:current_address] != registration.callback_address + must_register = parsed_check_result[:current_address] != registration.callback_address || + parsed_check_result[:fields] != registration.fields || + parsed_check_result[:metafield_namespaces] != registration.metafield_namespaces { webhook_id: parsed_check_result[:webhook_id], must_register: must_register } end diff --git a/test/webhooks/webhook_registration_queries.rb b/test/webhooks/webhook_registration_queries.rb index 4d941592..627baf50 100644 --- a/test/webhooks/webhook_registration_queries.rb +++ b/test/webhooks/webhook_registration_queries.rb @@ -14,6 +14,8 @@ def queries edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookHttpEndpoint { @@ -207,6 +209,8 @@ def queries edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookEventBridgeEndpoint { @@ -397,6 +401,8 @@ def queries edges { node { id + includeFields + metafieldNamespaces endpoint { __typename ... on WebhookPubSubEndpoint {