Skip to content

Commit 2005188

Browse files
authored
docs: fix step detection of useQueryGraphStep (medusajs#12842)
1 parent f7e4a80 commit 2005188

File tree

3 files changed

+194
-14
lines changed
  • www
    • apps/resources/references
      • core_flows/Common/Steps_Common/functions/core_flows.Common.Steps_Common.useQueryGraphStep
      • helper_steps/functions/helper_steps.useQueryGraphStep
    • utils/packages/utils/src

3 files changed

+194
-14
lines changed

www/apps/resources/references/core_flows/Common/Steps_Common/functions/core_flows.Common.Steps_Common.useQueryGraphStep/page.mdx

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,83 @@ import { TypeList, WorkflowDiagram } from "docs-ui"
1212

1313
This documentation provides a reference to the `useQueryGraphStep`. It belongs to the `@medusajs/medusa/core-flows` package.
1414

15-
## Type Parameters
15+
This step fetches data across modules using the Query.
1616

17-
<TypeList types={[{"name":"TEntry","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
17+
Learn more in the [Query documentation](https://docs.medusajs.com/learn/fundamentals/module-links/query).
1818

19-
## Parameters
19+
## Example
2020

21-
<TypeList types={[{"name":"input","type":"[UseQueryGraphStepInput](../../../../types/core_flows.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"options","type":"[RemoteJoinerOptions](../../../../../types/interfaces/types.RemoteJoinerOptions/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"throwIfKeyNotFound","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"throwIfRelationNotFound","type":"`boolean` \\| `string`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"initialData","type":"`object` \\| `object`[]","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"initialDataOnly","type":"`boolean`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
21+
To retrieve a list of records of a data model:
2222

23-
## Returns
23+
```ts
24+
const { data: products } = useQueryGraphStep({
25+
entity: "product",
26+
fields: [
27+
"*",
28+
"variants.*"
29+
]
30+
})
31+
```
2432

25-
<TypeList types={[{"name":"ReturnType","type":"ReturnType&#60;[StepFunction](../../../../../workflows/types/workflows.StepFunction/page.mdx)&#60;[UseQueryGraphStepInput](../../../../types/core_flows.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;, [GraphResultSet](../../../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.GraphResultSet/page.mdx)&#60;TEntry&#62;&#62;&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"UseQueryGraphStepInput","type":"[UseQueryGraphStepInput](../../../../types/core_flows.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]},{"name":"GraphResultSet","type":"[GraphResultSet](../../../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.GraphResultSet/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
33+
To retrieve a single item instead of a an array:
34+
35+
```ts
36+
const { data: products } = useQueryGraphStep({
37+
entity: "product",
38+
fields: [
39+
"*",
40+
"variants.*"
41+
],
42+
filters: {
43+
id: "123"
44+
}
45+
})
46+
```
47+
48+
To throw an error if a record isn't found matching the specified ID:
49+
50+
```ts
51+
const { data: products } = useQueryGraphStep({
52+
entity: "product",
53+
fields: [
54+
"*",
55+
"variants.*"
56+
],
57+
filters: {
58+
id: "123"
59+
},
60+
options: {
61+
throwIfKeyNotFound: true
62+
}
63+
})
64+
```
65+
66+
To set pagination configurations:
67+
68+
```ts
69+
const { data: products } = useQueryGraphStep({
70+
entity: "product",
71+
fields: [
72+
"*",
73+
"variants.*"
74+
],
75+
filters: {
76+
id: "123"
77+
},
78+
pagination: {
79+
take: 10,
80+
skip: 10,
81+
order: {
82+
created_at: "DESC"
83+
}
84+
}
85+
})
86+
```
87+
88+
## Input
89+
90+
<TypeList types={[{"name":"UseQueryGraphStepInput","type":"[UseQueryGraphStepInput](../../../../types/core_flows.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" openedLevel={1} sectionTitle="useQueryGraphStep"/>
91+
92+
## Output
93+
94+
<TypeList types={[{"name":"GraphResultSet","type":"[GraphResultSet](../../../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.GraphResultSet/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" openedLevel={1} sectionTitle="useQueryGraphStep"/>

www/apps/resources/references/helper_steps/functions/helper_steps.useQueryGraphStep/page.mdx

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,83 @@ import { TypeList } from "docs-ui"
99

1010
This documentation provides a reference to the `useQueryGraphStep` step. It belongs to the `@medusajs/medusa/core-flows` package.
1111

12-
## Type Parameters
12+
This step fetches data across modules using the Query.
1313

14-
<TypeList types={[{"name":"TEntry","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
14+
Learn more in the [Query documentation](https://docs.medusajs.com/learn/fundamentals/module-links/query).
1515

16-
## Parameters
16+
## Example
1717

18-
<TypeList types={[{"name":"input","type":"[UseQueryGraphStepInput](../../types/helper_steps.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;","description":"","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"options","type":"[RemoteJoinerOptions](../../../types/interfaces/types.RemoteJoinerOptions/page.mdx)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
18+
To retrieve a list of records of a data model:
1919

20-
## Returns
20+
```ts
21+
const { data: products } = useQueryGraphStep({
22+
entity: "product",
23+
fields: [
24+
"*",
25+
"variants.*"
26+
]
27+
})
28+
```
2129

22-
<TypeList types={[{"name":"ReturnType","type":"ReturnType&#60;[StepFunction](../../../workflows/types/workflows.StepFunction/page.mdx)&#60;[UseQueryGraphStepInput](../../types/helper_steps.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;, [GraphResultSet](../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.GraphResultSet/page.mdx)&#60;TEntry&#62;&#62;&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="useQueryGraphStep"/>
30+
To retrieve a single item instead of a an array:
31+
32+
```ts
33+
const { data: products } = useQueryGraphStep({
34+
entity: "product",
35+
fields: [
36+
"*",
37+
"variants.*"
38+
],
39+
filters: {
40+
id: "123"
41+
}
42+
})
43+
```
44+
45+
To throw an error if a record isn't found matching the specified ID:
46+
47+
```ts
48+
const { data: products } = useQueryGraphStep({
49+
entity: "product",
50+
fields: [
51+
"*",
52+
"variants.*"
53+
],
54+
filters: {
55+
id: "123"
56+
},
57+
options: {
58+
throwIfKeyNotFound: true
59+
}
60+
})
61+
```
62+
63+
To set pagination configurations:
64+
65+
```ts
66+
const { data: products } = useQueryGraphStep({
67+
entity: "product",
68+
fields: [
69+
"*",
70+
"variants.*"
71+
],
72+
filters: {
73+
id: "123"
74+
},
75+
pagination: {
76+
take: 10,
77+
skip: 10,
78+
order: {
79+
created_at: "DESC"
80+
}
81+
}
82+
})
83+
```
84+
85+
## Input
86+
87+
<TypeList types={[{"name":"UseQueryGraphStepInput","type":"[UseQueryGraphStepInput](../../types/helper_steps.UseQueryGraphStepInput/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" openedLevel={1} sectionTitle="useQueryGraphStep"/>
88+
89+
## Output
90+
91+
<TypeList types={[{"name":"GraphResultSet","type":"[GraphResultSet](../../../types/ModulesSdkTypes/types/types.ModulesSdkTypes.GraphResultSet/page.mdx)&#60;TEntry&#62;","optional":false,"defaultValue":"","description":"","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" openedLevel={1} sectionTitle="useQueryGraphStep"/>

www/utils/packages/utils/src/step-utils.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import { ArrayType, SignatureReflection, SomeType, UnionType } from "typedoc"
1+
import {
2+
ArrayType,
3+
ReferenceType,
4+
SignatureReflection,
5+
SomeType,
6+
UnionType,
7+
} from "typedoc"
28

39
const disallowedIntrinsicTypeNames = ["unknown", "void", "any", "never"]
410

511
export function isWorkflowStep(reflection: SignatureReflection): boolean {
612
if (reflection.parent?.children?.some((child) => child.name === "__step__")) {
713
return true
814
}
15+
if (
16+
reflection.type?.type === "reference" &&
17+
reflection.type.name === "ReturnType"
18+
) {
19+
return getStepFunctionTypeArg(reflection.type) !== undefined
20+
}
921
if (reflection.type?.type !== "intersection") {
1022
return false
1123
}
@@ -19,7 +31,21 @@ export function isWorkflowStep(reflection: SignatureReflection): boolean {
1931
export function getStepInputType(
2032
reflection: SignatureReflection
2133
): SomeType | undefined {
22-
if (!isWorkflowStep(reflection) || !reflection.parameters?.length) {
34+
if (!isWorkflowStep(reflection)) {
35+
return
36+
}
37+
38+
if (reflection.type?.type === "reference") {
39+
const stepFunctionType = getStepFunctionTypeArg(reflection.type)
40+
41+
if (stepFunctionType) {
42+
return cleanUpType(stepFunctionType.typeArguments?.[0])
43+
}
44+
45+
return
46+
}
47+
48+
if (!reflection.parameters?.length) {
2349
return
2450
}
2551

@@ -40,6 +66,16 @@ export function getStepOutputType(
4066
return
4167
}
4268

69+
if (reflection.type?.type === "reference") {
70+
const stepFunctionType = getStepFunctionTypeArg(reflection.type)
71+
72+
if (stepFunctionType) {
73+
return cleanUpType(stepFunctionType.typeArguments?.[1])
74+
}
75+
76+
return
77+
}
78+
4379
if (reflection.type?.type !== "intersection") {
4480
return reflection.type
4581
}
@@ -95,3 +131,9 @@ function cleanUpArrayType(arrayType: ArrayType): SomeType {
95131

96132
return new ArrayType(cleanedUpType)
97133
}
134+
135+
function getStepFunctionTypeArg(referenceType: ReferenceType) {
136+
return referenceType.typeArguments?.find(
137+
(typeArg) => typeArg.type === "reference" && typeArg.name === "StepFunction"
138+
) as ReferenceType | undefined
139+
}

0 commit comments

Comments
 (0)