Storefront API: Cart query returning "Cannot return null for non-nullable field"

Hello,

This is mostly to communicate what I think is a bug to the Shopify team, but we just ran into an error with a cart query on the Storefront API (2024-07), where when the cart has a line item in it that has recently been archived, then any query into the product field of cart.lineItem.merchandise creates a type error in kills the rest of the query.

For example, with this simplified query:

{
  cart(
    id: "gid://shopify/Cart/xxxxx"
  ) {
    id
    lines(first: 250) {
      edges {
        node {
          id
          merchandise {
            ... on ProductVariant {
              id
              product {
                title
              }
            }
          }
        }
      }
    }
  }
}

We get the response:

{
  "data": {
    "cart": null
  },
  "errors": [
    {
      "message": "Cannot return null for non-nullable field ProductVariant.product"
    }
  ]
}

But when the query into the ProductVariant’s product is removed, the cart response is fine, and the variant properties are still returned.

We can handle the error in our app, and just create a new cart for the user, but I think a better experience would be to just remove that item from the cart, or even have availableForSale marked as false in the product variant (or merchandise), as now it’s still true, and then we could just send a mutation to remove the item and surface a message to the user. Or, of course, if you have any recommendations we would be happy to adjust something, or I’d be curious to hear if this is intentional.

Thanks,
Joe

Reposted this from the old forum, as it would still be nice to handle this case better

Thank you for reporting. I’ve forwarded this internally.

1 Like

We are experiencing this issue as well when attempting to read products that have recently been created. Are there any updates with regards to this?

Hi @Bret-Shopify. We are also experiencing the same issue when fetching products.
API version: January 2025.

{
    data: null,
    errors: [{
        message: 'Cannot return null for non-nullable field ProductVariantEdge.node'
    }]
}

Is there a solution to this?

Aras

Also facing this and not sure what determines this behaviour. It seems to only happen on random products on random stores.

For example it’s now happening on a specific store with only products created through the Shopify Bundles app.

EDIT:
This seems to happen in our case when one of the components of a bundle is in Draft mode and the other is Active.

@Bret-Shopify any update on this? It’s quite disruptive, as just one bundle component being in draft mode nukes the whole cart query.