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

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

Joe
Visitor
2 0 2

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

Reply 1 (1)

DuyThanh
Shopify Partner
1 0 0

Same issues