chore(product, modules-sdk): Add missing index for select-in strategy + allow to pass top level strategy to force the behaviour (#12508)

**What**
- Add missing index for query that falls in select in strategy, specifically the heaviest one with variant IN filtering
- Allow to force the strategy to be sent to the entry point module when using the graph API. It is useful with big dataset where filtering is enough without pagination and select in can offer better performances

e.g
```ts
       await query.graph({
            entity: 'product',
            fields,
            filters,
            strategy: 'select-in' // <-- this will force the module to use receive this value and apply it accordingly 
        })
```
This commit is contained in:
Adrien de Peretti
2025-05-19 17:57:58 +02:00
committed by GitHub
parent 397d353af6
commit 52bd9f9a53
9 changed files with 70 additions and 1 deletions

View File

@@ -40,6 +40,28 @@ describe("toRemoteQuery", () => {
})
})
it("should transform a query with strategy", () => {
const format = toRemoteQuery(
{
entity: "product",
fields: ["id", "handle", "description"],
strategy: "select-in",
},
entitiesMap
)
expect(format).toEqual({
product: {
__fields: ["id", "handle", "description"],
__args: {
options: {
strategy: "select-in",
},
},
},
})
})
it("should transform a query with pagination", () => {
const format = toRemoteQuery(
{

View File

@@ -159,6 +159,7 @@ export class Query {
queryOptions,
this.#remoteQuery.getEntitiesMap()
)
let response:
| any[]
| { rows: any[]; metadata: RemoteQueryFunctionReturnPagination }

View File

@@ -313,6 +313,7 @@ export class RemoteQuery {
"sort",
"order",
"withDeleted",
"options",
]
const availableOptionsAlias = new Map([
["limit", "take"],

View File

@@ -37,6 +37,7 @@ export function toRemoteQuery<const TEntity extends string>(
pagination?: Partial<RemoteQueryInput<TEntity>["pagination"]>
context?: Record<string, any>
withDeleted?: boolean
strategy?: "joined" | "select-in"
},
entitiesMap: Map<string, any>
): RemoteQueryGraph<TEntity> {
@@ -46,6 +47,7 @@ export function toRemoteQuery<const TEntity extends string>(
filters = {},
context = {},
withDeleted,
strategy,
} = config
const joinerQuery: Record<string, any> = {
@@ -130,6 +132,12 @@ export function toRemoteQuery<const TEntity extends string>(
}
}
if (strategy) {
joinerQuery[entity][ARGUMENTS] ??= {} as any
joinerQuery[entity][ARGUMENTS]["options"] ??= {} as any
joinerQuery[entity][ARGUMENTS]["options"]["strategy"] = strategy
}
if (withDeleted) {
joinerQuery[entity][ARGUMENTS] ??= {} as any
joinerQuery[entity][ARGUMENTS]["withDeleted"] = true