Current Structure
In Shopify Functions, line item attributes are currently queried one at a time:
Input {
cart {
lines {
attribute(key: String!): Attribute!
}
}
}
This means to query multiple attributes, we need multiple separate queries, which creates two significant challenges:
- Increased Query Costs: Each attribute requires its own individual query. For example, if we need 5 attributes, we have to make 5 separate queries, each with its own cost:
{
bundle_type_1_props: attribute(key: "bundle_type_1_props"){
value
}
bundle_type_2_props: attribute(key: "bundle_type_2_props"){
value
}
bundle_type_3_props: attribute(key: "bundle_type_3_props"){
value
}
bundle_type_4_props: attribute(key: "bundle_type_4_props"){
value
}
bundle_type_5_props: attribute(key: "bundle_type_5_props"){
value
}
}
- Limited Dynamic Implementation: Because each attribute needs its own explicit query, we can’t dynamically handle varying attribute requirements without modifying the function input.
Proposed Enhancement
Convert the current singular query to support multiple attributes in one operation:
Input {
cart {
lines {
attributes(keys: [String!]!): [Attribute!]! # Query multiple attributes at once with fixed cost
}
}
}
This would allow querying multiple attributes in a single operation:
{
bundle_type_props: attributes(keys: ["bundle_type_1_props", "bundle_type_2_props", "bundle_type_3_props", "bundle_type_4_props", "bundle_type_5_props"]){
values
}
}
Benefits
- Cost Efficiency: Single query cost for multiple attributes
- Better Performance: Reduced number of operations
- Dynamic Flexibility: Handle varying attribute requirements in one query
- Simplified Development: Cleaner code and easier maintenance
Would love to hear the community’s thoughts on this enhancement request.