I’m trying to implement market-scoped price sorting using Optimizely Content Graph and have run into an issue where orderBy on a nested field does not appear to respect the filter applied to the nested array.
Scenario
We have a GenericProduct type with a nested Variants array. Each element in the array represents one purchasable variant of a product and carries its own Market, Price, and AvailableInventory values.
Simplified schema:
type GenericProduct {
Code: String
Name: String
Status: String
Variants: [VariantModel]
}
type VariantModel {
Code: String
Market: String # e.g. "US-WHOLESALE", "CA-WHOLESALE"
Price: MoneyModel
AvailableInventory: Int
WarehouseCode: String
}
type MoneyModel {
Amount: Float
Currency: String
}
The where clause correctly restricts which products appear — only products that have at least one Variants entry satisfying Market = US-WHOLESALE are returned. This works correctly.
When orderBy: { Variants: { Price: { Amount: ASC } } } is applied, we expect the sort to use only the variant(s) that also satisfy the market filter — i.e., the minimum price across US-WHOLESALE variants only.
Expected sort order for the US-WHOLESALE user
Product
US-WHOLESALE Price
Expected Rank
PROD-C (Pixel 7)
$380.00
1st
PROD-B (Galaxy S23)
$420.00
2nd
PROD-A (iPhone 14)
$450.00
3rd
What actually happens
The orderBy on the nested field is not scoped to the market filter. Content Graph evaluates the sort using the minimum price across all nested Variants regardless of market, including variants the user cannot access.
Product
All-variant minimum
Actual sort rank
PROD-C (Pixel 7)
$310.00 (CA-WHOLESALE)
1st
PROD-A (iPhone 14)
$390.00 (CA-WHOLESALE)
2nd
PROD-B (Galaxy S23)
$420.00 (US-WHOLESALE)
3rd
The displayed Starting Price for PROD-A (after client-side market filtering) is $450.00, but it ranks 2nd — above PROD-B at $420.00. The sort order is incorrect for the user's accessible market.
Request / Question
Is there a planned or existing mechanism in Content Graph's GQL orderBy syntax to apply a filter on the nested path used for sorting?
If not, is there a recommended pattern for market-scoped price sorting on a GenericProduct type with a nested variants array, without fetching all documents client-side?
Hi Optimizely Team,
I’m trying to implement market-scoped price sorting using Optimizely Content Graph and have run into an issue where
orderByon a nested field does not appear to respect the filter applied to the nested array.Scenario
We have a
GenericProducttype with a nestedVariantsarray. Each element in the array represents one purchasable variant of a product and carries its ownMarket,Price, andAvailableInventoryvalues.Simplified schema:
Sample documents:
The Query
A user authenticated to
US-WHOLESALEonly searches for products and requests results sorted by Starting Price ascending:Problem Statement
The
whereclause correctly restricts which products appear — only products that have at least oneVariantsentry satisfyingMarket = US-WHOLESALEare returned. This works correctly.When
orderBy: { Variants: { Price: { Amount: ASC } } }is applied, we expect the sort to use only the variant(s) that also satisfy the market filter — i.e., the minimum price acrossUS-WHOLESALEvariants only.Expected sort order for the US-WHOLESALE user
What actually happens
The
orderByon the nested field is not scoped to the market filter. Content Graph evaluates the sort using the minimum price across all nestedVariantsregardless of market, including variants the user cannot access.The displayed Starting Price for PROD-A (after client-side market filtering) is $450.00, but it ranks 2nd — above PROD-B at $420.00. The sort order is incorrect for the user's accessible market.
Request / Question
Is there a planned or existing mechanism in Content Graph's GQL
orderBysyntax to apply a filter on the nested path used for sorting?If not, is there a recommended pattern for market-scoped price sorting on a
GenericProducttype with a nested variants array, without fetching all documents client-side?Environment
Optimizely CMS: 12
Optimizely Commerce: 14
Content Graph packages:
Thanks in advance for any guidance on the supported query syntax, limitations of nested sorting, or recommended approach for this scenario.