Next Generation Events now available in Developer Preview

I wonder if you can use the InventoryItem topic to trigger when quantities change, and then go from Inventory → Product Variant → sellableOnlineQuantity in your query

Thank you for the hint, I haven’t explored the new event system yet, so I can’t tell whether it would solve the issue for the moment, but if it helps to get all the relevant data in a single event, even if we have to re-compute the value by ourselves, it would already help a lot!

will do.

Also, i’m also thinking perhaps batched sends will be useful particularly if apps are trying to sync state, take for example a merchant uploading thousands of products, or bulk updating metafields, the current triggers will send one update for every product update, another for a variant update, and one for each metafield, if these are batched in say 1 minute intervals, perhaps we could get a payload with multiple updates in one? This will save a lot of overhead.

During Developer Preview, queries are limited to a complexity of 250 points.
How much would it be when it is generally available?

Also, is there any limitation on how many level deep can we query? eg: product → variants → inventoryItem

During Developer Preview, queries are limited to a complexity of 250 points.
How much would it be when it is generally available?

If 250 query points are not enough, I’m happy to talk about your use case

Also, is there any limitation on how many level deep can we query? eg: product → variants → inventoryItem

You can absolutely go from Product → Variant → InventoryItem

I’d encourage you to actually try out your production use cases and we can talk about optimizing them

Batching is something we’ll be looking into early next year - it is in the roadmap.

Sorry for the late response. I didn’t realise that 250 points cover a lot of data already. Can’t remember if this was always the case or if the Graphql queries are very cost efficient now.

I have one more question though. Which trigger would be suitable to know if the product gets published/unpublished on the online store or other sales channels? The publishedAt field doesn’t seem to eligible for the trigger.

Just wanted some clarification, for the “collection.products” trigger ( Collection ) , does it trigger when a product is added into a collection, and when it is removed from a collection? Or does it only trigger when a product that is already included in a collection, has its field updated? (eg: change of product price, in a product that belongs to a collection)

This would be part of the Publication related topics^

collection.product is for product memberships to a collection (manual / smart) only - for any Product related changes, you should use the Product topic^

@Harshdeep-Shopify btw, there is no more manual vs smart collections

I’m aware. They’re new enough that a lot of developers haven’t caught up yet, since they don’t work with Collection APIs every day :slight_smile:

Thank you for the clarification! Are there ways to check which products that was added / removed? Does the productsId in the query_variables contain this information?

query_variables currently only contain IDs and fields_changed tell you where the change happened. You can make a query to check if a product still exists on a collection^

@Harshdeep-Shopify thank you for the information about products that were added and removed using an extra query - at scale querying whether a product exists everytime we receive a webhook is not working well though.

I guess we’d still have to add some kind of in-house debouncing before we query the list of products.

You’re not making additional queries every time you receive an Event. It goes in as part of your Event subscription.

[[events.subscription]]
topic = "Collection"
actions = ["update"]
triggers = ["collection.products"]

query = """
  query CollectionMembership($collectionId: ID!, $productsId: ID!) {
    collection(id: $collectionId) {
      id
      hasProduct(id: $productsId)
    }
  }
"""

This would yield in an Event like this:

{
  "topic": "Collection",
  "action": "update",
  "handle": "collection-membership",
  "data": {
    "collection": {
      "id": "gid://shopify/Collection/494970863907",
      "hasProduct": false
    }
  },
  "fields_changed": [
    "collection[id: 'gid://shopify/Collection/494970863907'].products[id: 'gid://shopify/Product/9938496684323']"
  ],
  "query_variables": {
    "productsId": "gid://shopify/Product/9938496684323",
    "collectionId": "gid://shopify/Collection/494970863907"
  }
}

So you’re not really making a follow up query, your collection subscription is giving you all the data you need.