Graphql query for products with a "status" of "active" and belonging to a specific channel

We need to grab the top-level collections published to a channel and then grab the products inside of those collections that are active and published to the same channel of the collection. However, when we do it this way, we cannot get the “productPublicationsV3” on line 34 of this query.

Here is an almost exact query of what we need. You will see that products inside the collections will not be affected by the status now, however which is what we really need.

{
  publication(id: "gid://shopify/Publication/67267264703") {
    name
    id
    collectionPublicationsV3(first: 1) {
      edges {
        node {
          publication {
            id
            name
            collections(first: 10) {
              edges {
                node {
                  id
                  handle
                  title
                  descriptionHtml
                  image {
                    originalSrc
                  }
                  seo {
                    description
                    title
                  }
                  metafields(first: 1) {
                    edges {
                      node {
                        namespace
                        key
                        value
                      }
                    }
                  }
                  products(first: 5) {
                    edges {
                      node {
                        id
                        title
                        handle
                        tags
                        productType
                        vendor
                        descriptionHtml
                        productType
                        featuredImage {
                          originalSrc
                        }
                        seo {
                          title
                          description
                        }
                        metafields(first: 1) {
                          edges {
                            node {
                              namespace
                              key
                              value
                            }
                          }
                        }
                        variants(first: 1) {
                          edges {
                            node {
                              id
                              title
                              price
                              sku
                              barcode
                              compareAtPrice
                              availableForSale
                              weight
                              weightUnit
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Hey @tbaustin ,

Happy to help you out with this.

If you use publishedOnPublication on the product node, specifying the same publication id, true will be displayed if that product is still available on that channel, and false other wise. Tweaking your example to use publishedOnPublication, could this work?

{
  publication(id: "gid://shopify/Publication/1234") {
    name
    id
    collectionPublicationsV3(first: 1) {
      edges {
        node {
          publication {
            id
            name
            collections(first: 10) {
              edges {
                node {
                  id
                  handle
                  title
                  products(first:10){
                    edges{
                      node{
                        publishedOnPublication(publicationId: "gid://shopify/Publication/1234")
                        title
                       
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Let me know if that will work, or if you have any another questions please don’t hesitate to reach out.

Regards,

John

@_JCC

The one thing we were trying to do was avoid any parsing or massaging of the data after we do the query. The goal was to run the query and return the correct data. In the example you gave us we would have to run a .filter() on the products and only return products that have a publishedOnPublication of true.

This defeats the purpose of what we are really trying to do, but maybe it is not possible for what we are trying to do?

Hey @tbaustin ,

Sorry about that. I certainly understand your point about not wanting to filter the query after the fact. I’ll reach out to some more teams internally to confirm if the option presented is as close as is possible right now. Will likely be tomorrow before I hear back. Have a good evening.

Regards,

John

Hey @_JCC ,

Just wanted to follow up and see if there was any progress on this?

Thank you!
Taylor

Hey @tbaustin ,

Was just about send a reply. Unfortunately at this time the only approach is filtering the results after the fact. I’ve shared the use case with the necessary team so they’re aware of the need for such functionality, but at this time there’s no timeline on when this change might get implemented. If anything changes or as I hear more I can follow-up and let you know.

Regards,

John

@_JCC
The query runs fine until it’s run as a bulk export then I get the following errors.

“userErrors”: [
{
“field”: [
“query”
],
“message”: “Bulk queries cannot contain more than 5 connections.”
},
{
“field”: [
“query”
],
“message”: “Bulk queries cannot contain connections with a nesting depth greater than 2.”
},
{
“field”: [
“query”
],
“message”: “The parent ‘node’ field for a nested connection must select the ‘id’ field. Connection fields without ‘id’: collectionPublicationsV3.”
}
]

Hey @tbaustin ,

Sorry for the delay in my response to your most recent inquiry.

Running queries in the context of a bulk operation have additional platform protection measures. Bulk queries cannot contain more than 5 connections, and Bulk queries cannot contain connections with a nesting depth greater than 2, are both measures to ensure overall platform health. The third error The parent ‘node’ field for a nested connection must select the ‘id’ field. Connection fields without ‘id’: collectionPublicationsV3, occurs because the underlying type of collectionPublicationsV3 is a resource_publication that can be both a product or collection publication and because of this the id field is not exposed.

Given the limitations of nesting depth, and number of connections for bulk operations the only option would be to run the queries outside the context of a bulk operation.

If you have any other questions please don’t hesitate to reach out.

Regards,

John