Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Add backward compatibility with REST-style webhook topics (e.g. "orders/create") #868

Merged
merged 5 commits into from
Jul 8, 2021
Merged

Add backward compatibility with REST-style webhook topics (e.g. "orders/create") #868

merged 5 commits into from
Jul 8, 2021

Conversation

squatto
Copy link
Contributor

@squatto squatto commented Jul 6, 2021

v17 requires webhooks to be configured with GraphQL-style webhook topics (e.g. "ORDERS_CREATE") instead of the previously-used REST-style webhook topics (e.g. "orders/create"). If there are webhooks in the config and topic isn't changed on all of them during the upgrade process, an exception is thrown that it isn't terribly clear how to fix: Variable $topic of type WebhookSubscriptionTopic! was provided invalid value.

This PR adds backward compatibility with REST-style webhook topics through the use of a new utility method: Util::getGraphQLWebhookTopic(string $topic): string

Util::getGraphQLWebhookTopic('orders/created') === 'ORDERS_CREATED'

When the webhooks in the config are being created on the store, the topic is run through this method to ensure that the GraphQL-style topic is being used, even if the topic in the config is REST style.


I also updated the shopify-app:make:webhook command output to include the GraphQL-style topic and the actual webhook handler URL (instead of a generic URL). For example:

$ php artisan shopify-app:make:webhook OrdersCreate orders/create
For non-GDPR webhooks, don't forget to register the webhook in config/shopify-app.php. Example:

    'webhooks' => [
        [
            'topic' => 'ORDERS_CREATE',
            'address' => 'https://shopifyapptest.ngrok.io/webhook/orders-create'
        ]
    ]

@gnikyt gnikyt merged commit 320ea52 into gnikyt:master Jul 8, 2021
@squatto squatto deleted the handle-slash-in-webhook-topic branch July 8, 2021 20:14
@squatto
Copy link
Contributor Author

squatto commented Jul 8, 2021

Thanks @osiset! 👍🏻

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants