kirillplatonov / shopify_graphql

Less painful way to work with Shopify Graphql API in Ruby.
MIT License
59 stars 9 forks source link

WebhooksManager job not firing on install #14

Closed vasaf closed 1 year ago

vasaf commented 1 year ago

Hi @kirillplatonov, thank's for your work. It's much appreciated.

When installing my app on my store, the WebhooksManager job doesn't fire and subscribe to the topics I have configured in shopify_app.rb.

I have to manually call ShopifyGraphql::WebhooksManager.queue_create from console for the webhooks to register.

I've added WEBHOOKS_ENABLED=true to .env but the job still isn't firing on install? Do you have any suggestions why this might be happening?

shopify_app.rb

ShopifyGraphql.configure do |config|
  webhooks_prefix = "https://#{Rails.configuration.app_host}/graphql_webhooks"
  config.webhook_jobs_namespace = ''
  config.webhook_enabled_environments = ['development']
  config.webhooks = [
    { topic: 'SHOP_UPDATE', address: "#{webhooks_prefix}/shop_update" },
    { topic: 'APP_SUBSCRIPTIONS_UPDATE', address: "#{webhooks_prefix}/app_subscriptions_update" },
    { topic: 'APP_UNINSTALLED', address: "#{webhooks_prefix}/app_uninstalled" },
  ]
end
kirillplatonov commented 1 year ago

Hey,

This part is missing in the documentation. In order to register webhooks after app installation you have to call ShopifyGraphql::UpdateWebhooksJob. I do it in AfterInstallJob. Here's an example:

# config/initializers/shopify_app.rb
ShopifyApp.configure do |config|
  # ...
  config.after_authenticate_job = {job: "AfterAuthenticateJob", inline: true}
end
# app/jobs/after_install_job.rb
class AfterInstallJob < ApplicationJob
  def perform(shop)
    # ...
    update_webhooks(shop)
  end

  def update_webhooks(shop)
    ShopifyGraphql::UpdateWebhooksJob.perform_later(
      shop_domain: shop.shopify_domain,
      shop_token: shop.shopify_token
    )
  end
end
kirillplatonov commented 1 year ago

Added this instruction to README. @vasaf thanks for raising this question 👍