Populating PermaCart Link with browser cookies has an edge case when a product is deleted

in case anyone is wondering what the solution is:

since the permacart link is made up of variant id’s, we can query the GraphQL API for the variants that are stored in the browser’s cookies, and thus are in the user’s cart.

The following query achieves that:

query {
  nodes(ids: ["gid://shopify/ProductVariant/19523123249174", "gid://shopify/ProductVariant/19523123216406", "gid://shopify/ProductVariant/19523123314710"]) {
    ... on ProductVariant {
      id
      title
      price
      # Add additional fields as needed
    }
  }
}

You can try this example at the Shopify GraphQL explorer

https://shopify.dev/graphiql/admin-graphiql

The second variant id is intentionally incorrect as to test to see what the response would be in the case that a variant does not exist in the Shopify store. It will return null in the case that the variant doesn’t exist in the store, and with that information in the response we can then deal with the knowledge that that variant no longer exists.