Skip to content

Commit 543c9f7

Browse files
authored
fix(utils): Query filters API should have nested optional props (medusajs#13583)
1 parent a75cf7f commit 543c9f7

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

packages/core/core-flows/src/common/steps/__fixtures__/remote-query.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@ export interface SimpleProduct {
22
id: string
33
title: string
44
description: string
5+
variants: Variant[]
6+
}
7+
8+
export interface Variant {
9+
id: string
10+
title: string
11+
sku: string
12+
product_id: string
513
}
614

715
export interface FixtureEntryPoints {
816
simple_product: SimpleProduct
17+
variant: Variant
918
}
1019

1120
declare module "@medusajs/types/dist/modules-sdk/remote-query-entry-points" {

packages/core/core-flows/src/common/steps/__tests__/use-query-graph-step.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { MedusaContainer } from "@medusajs/framework"
2+
import { asFunction, createContainer } from "@medusajs/framework/awilix"
3+
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
14
import { createWorkflow, WorkflowResponse } from "@medusajs/workflows-sdk"
25
import { expectTypeOf } from "expect-type"
36
import { FixtureEntryPoints } from "../__fixtures__/remote-query"
47
import { useQueryGraphStep } from "../use-query-graph"
5-
import { MedusaContainer } from "@medusajs/framework"
6-
import { asFunction, createContainer } from "@medusajs/framework/awilix"
7-
import { ContainerRegistrationKeys } from "@medusajs/framework/utils"
88

99
describe("useQueryGraphStep", () => {
1010
let container!: MedusaContainer
@@ -28,6 +28,9 @@ describe("useQueryGraphStep", () => {
2828
fields: ["*"],
2929
filters: {
3030
id: "123",
31+
variants: {
32+
id: "123",
33+
},
3134
},
3235
options: {
3336
isList: false,

packages/core/types/src/modules-sdk/to-remote-query.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { Prettify } from "../common"
1+
import { Prettify as CorePrettify } from "../common"
22
import { OperatorMap } from "../dal"
33
import { RemoteQueryEntryPoints } from "./remote-query-entry-points"
44

5+
type DeepPartial<T> = {
6+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
7+
}
8+
9+
type Prettify<T> = DeepPartial<CorePrettify<T>>
510
type ExcludedProps = "__typename"
611
type Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
712
type CleanupObject<T> = Prettify<Omit<Exclude<T, symbol>, ExcludedProps>>
@@ -83,16 +88,20 @@ export type RemoteQueryFilters<
8388
Exclusion extends string[] = [],
8489
Lim extends number = Depth[3]
8590
> = RemoteQueryFilterOperators<
86-
InternalRemoteQueryFilters<
87-
TEntry,
88-
RemoteQueryEntryPointsLevel,
89-
Exclusion,
90-
Lim
91+
DeepPartial<
92+
InternalRemoteQueryFilters<
93+
TEntry,
94+
RemoteQueryEntryPointsLevel,
95+
Exclusion,
96+
Lim
97+
>
9198
>
9299
> &
93-
InternalRemoteQueryFilters<
94-
TEntry,
95-
RemoteQueryEntryPointsLevel,
96-
Exclusion,
97-
Lim
100+
DeepPartial<
101+
InternalRemoteQueryFilters<
102+
TEntry,
103+
RemoteQueryEntryPointsLevel,
104+
Exclusion,
105+
Lim
106+
>
98107
>

0 commit comments

Comments
 (0)