Content Graph: Can orderBy on nested Variants.Price.Amount be scoped to the filtered Variants?

Sunil
Sunil
Opal Administrator CertificationCommerce Connect 13 Developer CertificationPaaS CMS Administrator CertificationSaaS CMS Developer CertificationOpal Tools CertificationPaaS CMS Developer Certificationworkspace_premium

Hi Optimizely Team,

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
}

Sample documents:

[
  {
    "Code": "PROD-A",
    "Name": "iPhone 14 128GB",
    "Variants": [
      {
        "Code": "VAR-A1",
        "Market": "US-WHOLESALE",
        "Price": { "Amount": 450.00 },
        "AvailableInventory": 10
      },
      {
        "Code": "VAR-A2",
        "Market": "CA-WHOLESALE",
        "Price": { "Amount": 390.00 },
        "AvailableInventory": 5
      }
    ]
  },
  {
    "Code": "PROD-B",
    "Name": "Samsung Galaxy S23",
    "Variants": [
      {
        "Code": "VAR-B1",
        "Market": "US-WHOLESALE",
        "Price": { "Amount": 420.00 },
        "AvailableInventory": 8
      }
    ]
  },
  {
    "Code": "PROD-C",
    "Name": "Google Pixel 7",
    "Variants": [
      {
        "Code": "VAR-C1",
        "Market": "US-WHOLESALE",
        "Price": { "Amount": 380.00 },
        "AvailableInventory": 3
      },
      {
        "Code": "VAR-C2",
        "Market": "CA-WHOLESALE",
        "Price": { "Amount": 310.00 },
        "AvailableInventory": 2
      }
    ]
  }
]

The Query

A user authenticated to US-WHOLESALE only searches for products and requests results sorted by Starting Price ascending:

GenericProduct(
  where: {
    Status: { eq: "Published" }
    Variants: {
      Market: { in: ["US-WHOLESALE"] }
    }
  }
  orderBy: {
    Variants: {
      Price: {
        Amount: ASC
      }
    }
  }
  limit: 20
) {
  items {
    Code
    Name
    Variants {
      Market
      Price { Amount }
    }
  }
}

Problem Statement

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?

Environment

Optimizely CMS: 12
Optimizely Commerce: 14

Content Graph packages:

<PackageReference Include="Optimizely.ContentGraph.Cms" Version="4.3.1" />
<PackageReference Include="Optimizely.Graph.Commerce" Version="1.3.2" />

Thanks in advance for any guidance on the supported query syntax, limitations of nested sorting, or recommended approach for this scenario.

#343285
Sep 11, 2026 13:42
Praful Jangid

Hi Sunil,

Thanks for the clarification. Based on some initial testing, it looks like the where filter on the nested Variants collection only controls which products are returned. It does not scope the nested field used by orderBy.

For example:

where: {
  Variants: {
    Market: { eq: "US-WHOLESALE" }
  }
}
orderBy: {
  Variants: {
    Price: {
      Amount: ASC
    }
  }
}

The filter correctly limits the products to those having a US variant, but the sorting still considers the minimum price across all variants, including variants from other markets.

I don't see a supported orderBy syntax that allows a filter to be applied specifically to the nested collection used for sorting.

For market-specific price sorting, a few possible approaches would be:

  • Market-specific sortable fields – for example, USWholesaleStartingPrice, CAWholesaleStartingPrice, etc.

  • Market-wise indexing – index the product/variant data as a separate document per market, such as Product + Market + StartingPrice. This would allow filtering by market and sorting directly by StartingPrice.

  • Separate search/index model – create a search-oriented model where the market-specific price is already calculated during indexing.

The market-wise indexing approach seems particularly useful when the number of markets is dynamic or when we need to support other market-specific filters such as inventory, availability, promotions, etc.

It would be useful to know if Optimizely has any planned support for filtering the nested path used by orderBy, similar to the nested sorting/filtering capabilities available in Optimizely Find.

#343333
Edited, Sep 20, 2026 15:31
Mardy

I tested this with a minimal custom Optimizely Graph Source, separate from Commerce, and was able to reproduce the same behavior.

I used three products with nested Market/Price values:

A: US=450, CA=100
B: US=300, CA=500
C: US=350, CA=250

With where Market = US and nested orderBy Price ASC, Graph returned A, C, B, which corresponds to the minimum price across each product's complete variant collection (100, 250, 300) rather than the filtered US prices.

I then tested the market-wise indexing approach suggested above by indexing one document per Product + Market. With Market and Price as fields on that document, the same query returned the expected B(300), C(350), A(450).

I also tried keeping Market + Price together in another nested collection, but that still produced the original behavior. So simply changing the nested structure doesn't appear to solve it; the sortable market-specific value needs to be represented as a scalar on the document (or precomputed into a market-specific field).

#343407
Oct 02, 2026 16:41
Mardy

For CMS 13.1.0+, another possible workaround could be to use the Graph Indexing Conventions API to add a computed market-specific price field at indexing time using IncludeField(), with IndexingType.Queryable.

For example, the computed field could resolve the price for a particular market from the variants and expose it as a scalar such as USWholesaleStartingPrice. The Graph query could then sort directly on that scalar instead of the nested multi-valued Variants.Price.Amount field.

This seems suitable when the set of markets is relatively fixed. For a large or dynamic set of markets, indexing a separate Product + Market document would probably scale better.

#343408
Edited, Oct 02, 2026 18:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.