How do I query the cart line properties attribute?

Topic summary

Issue: A developer struggled to query custom data from the properties attribute on cart lines using GraphQL in Shopify Functions.

Initial Problem:

  • Standard attribute queries weren’t returning the properties field
  • The user needed to access custom data added when products are added to cart

Solution Found:
Custom properties must be queried using a specific key prefix:

attribute(key: "_custom_data")

Key Technical Constraints:

  • Shopify Functions APIs differ from Storefront API—they cannot query unbounded lists for performance reasons
  • Each attribute must be queried individually by specifying its exact key
  • Inline fragments (available in Storefront API) don’t work in Functions context

Ongoing Challenge:
For expanded products with variable/dynamic property names, developers face limitations:

  • All original properties from expanded items don’t automatically carry through to order notes
  • Workaround suggested: stringify all key/value pairs into a single hidden custom attribute, then parse it in cart transform code
  • ExpandedItem attributes are available in API version 2024-04+

Status: Partial resolution—basic querying works, but handling dynamic properties across varied products remains complex.

Summarized with AI on November 7. AI used: claude-sonnet-4-5-20250929.

FYI, There’s a better way to do this using Inline Fragments:

query RunInput {
  cart {
    lines {
      id
      quantity
      attributes {
        ... on Attribute {
          key
          value
        }
      }
    }
  }
}

That will give you an array of all the attributes:

"attributes": [
  {
    "key": "test1",
    "value": "true"
  },
  {
    "key": "test2",
    "value": "false"
  }
]