docs: change useRemoteQueryStep to useQueryGraphStep (#10051)

* docs: change useRemoteQueryStep to useQueryGraphStep

* fix lint errors
This commit is contained in:
Shahed Nasser
2024-11-13 11:00:55 +02:00
committed by GitHub
parent 823552ecd9
commit 868b1c190f
17 changed files with 241 additions and 266 deletions
@@ -55,7 +55,7 @@ import { DetailWidgetProps, HttpTypes } from "@medusajs/framework/types"
const ProductWidget = () => {
const { data, isLoading } = useQuery({
queryFn: () => sdk.admin.product.list(),
queryKey: ["products"]
queryKey: ["products"],
})
return (
@@ -95,17 +95,17 @@ import { sdk } from "../lib/config"
import { DetailWidgetProps, HttpTypes } from "@medusajs/framework/types"
const ProductWidget = ({
data: productData
data: productData,
}: DetailWidgetProps<HttpTypes.AdminProduct>) => {
const { mutateAsync } = useMutation({
mutationFn: (payload: HttpTypes.AdminUpdateProduct) =>
sdk.admin.product.update(productData.id, payload),
onSuccess: () => alert("updated product")
onSuccess: () => alert("updated product"),
})
const handleUpdate = () => {
mutateAsync({
title: "New Product Title"
title: "New Product Title",
})
}
@@ -57,7 +57,7 @@ import {
LoaderOptions,
} from "@medusajs/framework/types"
import {
ContainerRegistrationKeys
ContainerRegistrationKeys,
} from "@medusajs/framework/utils"
export default async function helloWorldLoader({
@@ -30,7 +30,7 @@ module.exports = defineConfig({
capitalize: true,
},
},
]
],
})
```
@@ -145,7 +145,7 @@ const myWorkflow = createWorkflow(
function (input: WorkflowInput) {
const message = transform(
{
input
input,
},
(data) => data.input.message || "hello"
)
@@ -179,7 +179,7 @@ const myWorkflow = createWorkflow(
"hello-world",
function (input) {
validateHasStr1({
input
input,
})
// workflow continues its execution only if
@@ -135,8 +135,8 @@ module.exports = defineConfig({
modules: [
{
resolve: "./src/modules/hello",
}
]
},
],
})
```
@@ -212,11 +212,11 @@ export async function GET(
)
const my_custom = await helloModuleService.createMyCustoms({
name: "test"
name: "test",
})
res.json({
my_custom
my_custom,
})
}
```
@@ -105,8 +105,8 @@ module.exports = defineConfig({
modules: [
{
resolve: "./src/modules/brand",
}
]
},
],
})
```
@@ -192,7 +192,7 @@ module.exports = defineConfig({
apiKey: process.env.BRAND_API_KEY || "temp",
},
},
]
],
})
```
@@ -349,7 +349,7 @@ You add a step that deletes the manager using the `deleteManagers` method of the
Next, in the same file, add the workflow that deletes a manager:
export const deleteHighlights = [
["30", "manager_id", "If your actor type has a different name, such as vendor, change it to be `{actor_type}_id`."]
["29", "manager_id", "If your actor type has a different name, such as vendor, change it to be `{actor_type}_id`."]
]
```ts title="src/workflows/delete-manager.ts" collapsibleLines="1-15" expandButtonLabel="Show Imports" highlights={deleteHighlights}
@@ -363,7 +363,7 @@ import {
} from "@medusajs/framework/workflows-sdk"
import {
setAuthAppMetadataStep,
useRemoteQueryStep,
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
// ...
@@ -375,17 +375,15 @@ export const deleteManagerWorkflow = createWorkflow(
): WorkflowResponse<string> => {
deleteManagerStep(input)
const authIdentities = useRemoteQueryStep({
entry_point: "auth_identity",
const { data: authIdentities } = useQueryGraphStep({
entity: "auth_identity",
fields: ["id"],
variables: {
filters: {
app_metadata: {
// the ID is of the format `{actor_type}_id`.
manager_id: input.id,
},
},
},
filters: {
app_metadata: {
// the ID is of the format `{actor_type}_id`.
manager_id: input.id,
}
}
})
const authIdentity = transform(
@@ -492,7 +492,7 @@ Finally, you'll create the workflow. Create the file `src/workflows/update-custo
```ts title="src/workflows/update-custom-from-cart/index.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports"
import { CartDTO } from "@medusajs/framework/types"
import { createWorkflow, when, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
import { createRemoteLinkStep, dismissRemoteLinkStep, useRemoteQueryStep } from "@medusajs/medusa/core-flows"
import { createRemoteLinkStep, dismissRemoteLinkStep, useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { createCustomStep } from "../create-custom-from-cart/steps/create-custom"
import { Modules } from "@medusajs/framework/utils"
import { HELLO_MODULE } from "../../modules/hello"
@@ -509,15 +509,12 @@ export type UpdateCustomFromCartStepInput = {
export const updateCustomFromCartWorkflow = createWorkflow(
"update-custom-from-cart",
(input: UpdateCustomFromCartStepInput) => {
const cartData = useRemoteQueryStep({
entry_point: "cart",
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: ["custom.*"],
variables: {
filters: {
id: input.cart.id,
},
},
list: false,
filters: {
id: input.cart.id
}
})
// TODO create, update, or delete Custom record
@@ -534,9 +531,9 @@ Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-cart/index.ts"
const created = when({
input,
cartData,
carts,
}, (data) =>
!data.cartData.custom &&
!data.carts[0].custom &&
data.input.additional_data?.custom_name?.length > 0
)
.then(() => {
@@ -568,25 +565,25 @@ Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-cart/index.ts"
const deleted = when({
input,
cartData,
carts,
}, (data) =>
data.cartData.custom && (
data.carts[0].custom && (
data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
)
.then(() => {
deleteCustomStep({
custom: cartData.custom,
custom: carts[0].custom,
})
dismissRemoteLinkStep({
[HELLO_MODULE]: {
custom_id: cartData.custom.id,
custom_id: carts[0].custom.id,
},
})
return cartData.custom.id
return carts[0].custom.id
})
// TODO delete Custom record
@@ -599,11 +596,11 @@ Finally, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-cart/index.ts"
const updated = when({
input,
cartData,
}, (data) => data.cartData.custom && data.input.additional_data?.custom_name?.length > 0)
carts,
}, (data) => data.carts[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => {
const custom = updateCustomStep({
id: cartData.custom.id,
id: carts[0].custom.id,
custom_name: input.additional_data.custom_name,
})
@@ -504,7 +504,7 @@ Finally, you'll create the workflow. Create the file `src/workflows/update-custo
```ts title="src/workflows/update-custom-from-customer/index.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports"
import { CustomerDTO } from "@medusajs/framework/types"
import { createWorkflow, when, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
import { createRemoteLinkStep, dismissRemoteLinkStep, useRemoteQueryStep } from "@medusajs/medusa/core-flows"
import { createRemoteLinkStep, dismissRemoteLinkStep, useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { createCustomStep } from "../create-custom-from-customer/steps/create-custom"
import { Modules } from "@medusajs/framework/utils"
import { HELLO_MODULE } from "../../modules/hello"
@@ -521,15 +521,12 @@ export type UpdateCustomFromCustomerStepInput = {
export const updateCustomFromCustomerWorkflow = createWorkflow(
"update-custom-from-customer",
(input: UpdateCustomFromCustomerStepInput) => {
const customerData = useRemoteQueryStep({
entry_point: "customer",
const { data: customers } = useQueryGraphStep({
entity: "customer",
fields: ["custom.*"],
variables: {
filters: {
id: input.customer.id,
},
},
list: false,
filters: {
id: input.customer.id,
}
})
// TODO create, update, or delete Custom record
@@ -546,9 +543,9 @@ Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-customer/index.ts"
const created = when({
input,
customerData,
customers,
}, (data) =>
!data.customerData.custom &&
!data.customers[0].custom &&
data.input.additional_data?.custom_name?.length > 0
)
.then(() => {
@@ -580,25 +577,25 @@ Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-customer/index.ts"
const deleted = when({
input,
customerData,
customers,
}, (data) =>
data.customerData.custom && (
data.customers[0].custom && (
data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
)
.then(() => {
deleteCustomStep({
custom: customerData.custom,
custom: customers[0].custom,
})
dismissRemoteLinkStep({
[HELLO_MODULE]: {
custom_id: customerData.custom.id,
custom_id: customers[0].custom.id,
},
})
return customerData.custom.id
return customers[0].custom.id
})
// TODO delete Custom record
@@ -611,11 +608,11 @@ Finally, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-customer/index.ts"
const updated = when({
input,
customerData,
}, (data) => data.customerData.custom && data.input.additional_data?.custom_name?.length > 0)
customers,
}, (data) => data.customers[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => {
const custom = updateCustomStep({
id: customerData.custom.id,
id: customers[0].custom.id,
custom_name: input.additional_data.custom_name,
})
@@ -510,7 +510,7 @@ Finally, you'll create the workflow. Create the file `src/workflows/update-custo
```ts title="src/workflows/update-custom-from-product/index.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports"
import { ProductDTO } from "@medusajs/framework/types"
import { createWorkflow, when, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
import { createRemoteLinkStep, dismissRemoteLinkStep, useRemoteQueryStep } from "@medusajs/medusa/core-flows"
import { createRemoteLinkStep, dismissRemoteLinkStep, useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { createCustomStep } from "../create-custom-from-cart/steps/create-custom"
import { Modules } from "@medusajs/framework/utils"
import { HELLO_MODULE } from "../../modules/hello"
@@ -527,15 +527,12 @@ export type UpdateCustomFromProductStepInput = {
export const updateCustomFromProductWorkflow = createWorkflow(
"update-custom-from-product",
(input: UpdateCustomFromProductStepInput) => {
const productData = useRemoteQueryStep({
entry_point: "product",
const { data: products } = useQueryGraphStep({
entity: "product",
fields: ["custom.*"],
variables: {
filters: {
id: input.product.id
}
},
list: false
filters: {
id: input.product.id,
}
})
// TODO create, update, or delete Custom record
@@ -552,9 +549,9 @@ Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-product/index.ts"
const created = when({
input,
productData
products
}, (data) =>
!data.productData.custom &&
!data.products[0].custom &&
data.input.additional_data?.custom_name?.length > 0
)
.then(() => {
@@ -586,25 +583,25 @@ Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-product/index.ts"
const deleted = when({
input,
productData
products
}, (data) =>
data.productData.custom && (
data.products[0].custom && (
data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
)
.then(() => {
deleteCustomStep({
custom: productData.custom
custom: products[0].custom
})
dismissRemoteLinkStep({
[HELLO_MODULE]: {
custom_id: productData.custom.id
custom_id: products[0].custom.id
}
})
return productData.custom.id
return products[0].custom.id
})
// TODO delete Custom record
@@ -617,11 +614,11 @@ Finally, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-product/index.ts"
const updated = when({
input,
productData
}, (data) => data.productData.custom && data.input.additional_data?.custom_name?.length > 0)
products
}, (data) => data.products[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => {
const custom = updateCustomStep({
id: productData.custom.id,
id: products[0].custom.id,
custom_name: input.additional_data.custom_name
})
@@ -516,7 +516,7 @@ Finally, you'll create the workflow. Create the file `src/workflows/update-custo
```ts title="src/workflows/update-custom-from-promotion/index.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports"
import { PromotionDTO } from "@medusajs/framework/types"
import { createWorkflow, when, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
import { createRemoteLinkStep, dismissRemoteLinkStep, useRemoteQueryStep } from "@medusajs/medusa/core-flows"
import { createRemoteLinkStep, dismissRemoteLinkStep, useQueryGraphStep } from "@medusajs/medusa/core-flows"
import { createCustomStep } from "../create-custom-from-cart/steps/create-custom"
import { Modules } from "@medusajs/framework/utils"
import { HELLO_MODULE } from "../../modules/hello"
@@ -533,15 +533,12 @@ export type UpdateCustomFromPromotionStepInput = {
export const updateCustomFromPromotionWorkflow = createWorkflow(
"update-custom-from-promotion",
(input: UpdateCustomFromPromotionStepInput) => {
const promotionData = useRemoteQueryStep({
entry_point: "promotion",
const { data: promotions } = useQueryGraphStep({
entity: "promotion",
fields: ["custom.*"],
variables: {
filters: {
id: input.promotion.id
}
},
list: false
filters: {
id: input.promotion.id,
}
})
// TODO create, update, or delete Custom record
@@ -558,9 +555,9 @@ Next, replace the `TODO` with the following:
```ts title="src/workflows/update-custom-from-promotion/index.ts"
const created = when({
input,
promotionData
promotions
}, (data) =>
!data.promotionData.custom &&
!data.promotions[0].custom &&
data.input.additional_data?.custom_name?.length > 0
)
.then(() => {
@@ -592,25 +589,25 @@ Next, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-promotion/index.ts"
const deleted = when({
input,
promotionData
promotions
}, (data) =>
data.promotionData.custom && (
data.promotions[0].custom && (
data.input.additional_data?.custom_name === null ||
data.input.additional_data?.custom_name.length === 0
)
)
.then(() => {
deleteCustomStep({
custom: promotionData.custom
custom: promotions[0].custom
})
dismissRemoteLinkStep({
[HELLO_MODULE]: {
custom_id: promotionData.custom.id
custom_id: promotions[0].custom.id
}
})
return promotionData.custom.id
return promotions[0].custom.id
})
// TODO delete Custom record
@@ -623,11 +620,11 @@ Finally, replace the new `TODO` with the following:
```ts title="src/workflows/update-custom-from-promotion/index.ts"
const updated = when({
input,
promotionData
}, (data) => data.promotionData.custom && data.input.additional_data?.custom_name?.length > 0)
promotions
}, (data) => data.promotions[0].custom && data.input.additional_data?.custom_name?.length > 0)
.then(() => {
const custom = updateCustomStep({
id: promotionData.custom.id,
id: promotions[0].custom.id,
custom_name: input.additional_data.custom_name
})
@@ -1567,8 +1567,8 @@ To customize the cart completion flow, youll create a workflow and then use t
```mermaid
graph TD
completeCartWorkflow["completeCartWorkflow (Medusa)"] --> useRemoteQueryStep["useRemoteQueryStep (Medusa)"]
useRemoteQueryStep --> when{order has digital products?}
completeCartWorkflow["completeCartWorkflow (Medusa)"] --> useQueryGraphStep["useQueryGraphStep (Medusa)"]
useQueryGraphStep --> when{order has digital products?}
when -->|Yes| createDigitalProductOrderStep
createDigitalProductOrderStep --> createRemoteLinkStep["createRemoteLinkStep (Medusa)"]
createRemoteLinkStep --> createOrderFulfillmentWorkflow["createOrderFulfillmentWorkflow (Medusa)"]
@@ -1580,7 +1580,7 @@ graph TD
The workflow has the following steps:
1. `completeCartWorkflow` to create a Medusa order from the cart. Medusa provides this workflow through the `@medusajs/medusa/core-flows` package and you can use it as a step.
2. `useRemoteQueryStep` to retrieve the orders items with the digital products associated with the purchased product variants. Medusa provides this step through the `@medusajs/medusa/core-flows` package.
2. `useQueryGraphStep` to retrieve the orders items with the digital products associated with the purchased product variants. Medusa provides this step through the `@medusajs/medusa/core-flows` package.
3. If the order has digital products, you:
1. create the digital product order.
2. link the digital product order with the Medusa order. Medusa provides a `createRemoteLinkStep` in the `@medusajs/medusa/core-flows` package that can be used here.
@@ -1665,14 +1665,14 @@ In the compensation function, you delete the digital product order.
Create the file `src/workflows/create-digital-product-order/index.ts` with the following content:
export const createDpoWorkflowHighlights = [
["25", "completeCartWorkflow", "Create an order for the cart."],
["31", "useRemoteQueryStep", "Retrieve the order's items and their associated variants and linked digital products."],
["56", "when", "Check whether the order has any digital products."],
["61", "then", "Perform the callback function if an order has digital products."],
["64", "createDigitalProductOrderStep", "Create the digital product order."],
["66", "createRemoteLinkStep", "Link the digital product order to the Medusa order."],
["75", "createOrderFulfillmentWorkflow", "Create a fulfillment for the digital products in the order."],
["89", "emitEventStep", "Emit the `digital_product_order.created` event."]
["27", "completeCartWorkflow", "Create an order for the cart."],
["33", "useQueryGraphStep", "Retrieve the order's items and their associated variants and linked digital products."],
["57", "when", "Check whether the order has any digital products."],
["60", "then", "Perform the callback function if an order has digital products."],
["63", "createDigitalProductOrderStep", "Create the digital product order."],
["67", "createRemoteLinkStep", "Link the digital product order to the Medusa order."],
["76", "createOrderFulfillmentWorkflow", "Create a fulfillment for the digital products in the order."],
["90", "emitEventStep", "Emit the `digital_product_order.created` event."]
]
```ts title="src/workflows/create-digital-product-order/index.ts" highlights={createDpoWorkflowHighlights} collapsibleLines="1-17" expandMoreLabel="Show Imports"
@@ -1680,16 +1680,18 @@ import {
createWorkflow,
transform,
when,
WorkflowResponse,
WorkflowResponse
} from "@medusajs/framework/workflows-sdk"
import {
completeCartWorkflow,
useRemoteQueryStep,
useQueryGraphStep,
createRemoteLinkStep,
createOrderFulfillmentWorkflow,
emitEventStep,
emitEventStep
} from "@medusajs/medusa/core-flows"
import { Modules } from "@medusajs/framework/utils"
import {
Modules
} from "@medusajs/framework/utils"
import createDigitalProductOrderStep from "./steps/create-digital-product-order"
import { DIGITAL_PRODUCT_MODULE } from "../../modules/digital-product"
@@ -1700,35 +1702,34 @@ type WorkflowInput = {
const createDigitalProductOrderWorkflow = createWorkflow(
"create-digital-product-order",
(input: WorkflowInput) => {
const order = completeCartWorkflow.runAsStep({
const { id } = completeCartWorkflow.runAsStep({
input: {
id: input.cart_id,
},
id: input.cart_id
}
})
const { items } = useRemoteQueryStep({
entry_point: "order",
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: [
"*",
"items.*",
"items.variant.*",
"items.variant.digital_product.*",
"items.variant.digital_product.*"
],
variables: {
filters: {
id: order.id,
},
filters: {
id
},
throw_if_key_not_found: true,
list: false,
options: {
throwIfKeyNotFound: true
}
})
const itemsWithDigitalProducts = transform({
items,
orders
},
(data) => {
return data.items.filter((item) => item.variant.digital_product !== undefined)
}
return data.orders[0].items.filter((item) => item.variant.digital_product !== undefined)
}
)
const digital_product_order = when(itemsWithDigitalProducts, (itemsWithDigitalProducts) => {
@@ -1737,44 +1738,46 @@ const createDigitalProductOrderWorkflow = createWorkflow(
.then(() => {
const {
digital_product_order,
} = createDigitalProductOrderStep({ items })
} = createDigitalProductOrderStep({
items: orders[0].items
})
createRemoteLinkStep([{
[DIGITAL_PRODUCT_MODULE]: {
digital_product_order_id: digital_product_order.id,
digital_product_order_id: digital_product_order.id
},
[Modules.ORDER]: {
order_id: order.id,
},
order_id: id
}
}])
createOrderFulfillmentWorkflow.runAsStep({
input: {
order_id: order.id,
order_id: id,
items: transform({
itemsWithDigitalProducts,
itemsWithDigitalProducts
}, (data) => {
return data.itemsWithDigitalProducts.map((item) => ({
id: item.id,
quantity: item.quantity,
quantity: item.quantity
}))
}),
},
})
}
})
emitEventStep({
eventName: "digital_product_order.created",
data: {
id: digital_product_order.id,
},
id: digital_product_order.id
}
})
return digital_product_order
})
return new WorkflowResponse({
order,
digital_product_order,
order: orders[0],
digital_product_order
})
}
)
@@ -1785,7 +1788,7 @@ export default createDigitalProductOrderWorkflow
This creates the workflow `createDigitalProductOrderWorkflow`. It runs the following steps:
1. `completeCartWorkflow` as a step to create the Medusa order.
2. `useRemoteQueryStep` to retrieve the orders items with their associated variants and linked digital products.
2. `useQueryGraphStep` to retrieve the orders items with their associated variants and linked digital products.
3. Use `when` to check whether the order has digital products. If so:
1. Use the `createDigitalProductOrderStep` to create the digital product order.
2. Use the `createRemoteLinkStep` to link the digital product order to the Medusa order.
@@ -1842,7 +1845,7 @@ In this step, you'll create a workflow that fulfills a digital order by sending
The workflow has the following steps:
1. Retrieve the digital product order's details. For this, you'll use the `useRemoteQueryStep` imported from `@medusajs/medusa/core-flows`.
1. Retrieve the digital product order's details. For this, you'll use the `useQueryGraphStep` imported from `@medusajs/medusa/core-flows`.
2. Send a notification to the customer with the digital products to download.
So, you only need to implement the second step.
@@ -1959,17 +1962,17 @@ You use the `createNotifications` method of the Notification Module's main servi
Create the workflow in the file `src/workflows/fulfill-digital-order/index.ts`:
export const fulfillWorkflowHighlights = [
["17", "useRemoteQueryStep", "Retrieve the digital product order's details."],
["17", "useQueryGraphStep", "Retrieve the digital product order's details."],
["33", "sendDigitalOrderNotificationStep", "Send a notification to the customer."]
]
```ts title="src/workflows/fulfill-digital-order/index.ts" highlights={fulfillWorkflowHighlights} collapsibleLines="1-10" expandMoreLabel="Show Imports"
import {
createWorkflow,
WorkflowResponse,
WorkflowResponse
} from "@medusajs/framework/workflows-sdk"
import {
useRemoteQueryStep,
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
import { sendDigitalOrderNotificationStep } from "./steps/send-digital-order-notification"
@@ -1980,29 +1983,28 @@ type FulfillDigitalOrderWorkflowInput = {
export const fulfillDigitalOrderWorkflow = createWorkflow(
"fulfill-digital-order",
({ id }: FulfillDigitalOrderWorkflowInput) => {
const digitalProductOrder = useRemoteQueryStep({
entry_point: "digital_product_order",
const { data: digitalProductOrders } = useQueryGraphStep({
entity: "digital_product_order",
fields: [
"*",
"products.*",
"products.medias.*",
"order.*",
"order.*"
],
variables: {
filters: {
id,
},
filters: {
id,
},
list: false,
throw_if_key_not_found: true,
options: {
throwIfKeyNotFound: true
}
})
sendDigitalOrderNotificationStep({
digital_product_order: digitalProductOrder,
digital_product_order: digitalProductOrders[0]
})
return new WorkflowResponse(
digitalProductOrder
digitalProductOrders[0]
)
}
)
@@ -2010,7 +2012,7 @@ export const fulfillDigitalOrderWorkflow = createWorkflow(
In the workflow, you:
1. Retrieve the digital product order's details using the `useRemoteQueryStep` imported from `@medusajs/medusa/core-flows`.
1. Retrieve the digital product order's details using the `useQueryGraphStep` imported from `@medusajs/medusa/core-flows`.
2. Send a notification to the customer with the digital product download links using the `sendDigitalOrderNotificationStep`.
### Configure Notification Module Provider
@@ -1119,7 +1119,7 @@ import {
} from "@medusajs/framework/workflows-sdk"
import {
setAuthAppMetadataStep,
useRemoteQueryStep,
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
import { deleteRestaurantAdminStep } from "../steps/delete-restaurant-admin"
@@ -1144,14 +1144,12 @@ So far, you only use the `deleteRestaurantAdminStep` in the workflow, which dele
Replace the `TODO` with the following:
```ts title="restaurant-marketplace/src/workflows/restaurant/workflows/delete-restaurant-admin.ts"
const authIdentities = useRemoteQueryStep({
entry_point: "auth_identity",
const { data: authIdentities } = useQueryGraphStep({
entity: "auth_identity",
fields: ["id"],
variables: {
filters: {
app_metadata: {
restaurant_id: input.id,
},
filters: {
app_metadata: {
restaurant_id: input.id,
},
},
})
@@ -803,14 +803,14 @@ In this step, youll create a workflow thats executed when the customer pla
```mermaid
graph TD
retrieveCartStep["Retrieve Cart (useRemoteQueryStep from Medusa)"] --> completeCartWorkflow["completeCartWorkflow (Medusa)"]
retrieveCartStep["Retrieve Cart (useQueryGraphStep from Medusa)"] --> completeCartWorkflow["completeCartWorkflow (Medusa)"]
completeCartWorkflow["completeCartWorkflow (Medusa)"] --> groupVendorItemsStep
groupVendorItemsStep --> getOrderDetailWorkflow
getOrderDetailWorkflow --> createVendorOrdersStep
createVendorOrdersStep --> createRemoteLinkStep["Create Links (createRemoteLinkStep from Medusa)"]
```
1. Retrieve the cart using its ID. Medusa provides a `useRemoteQueryStep` in the `@medusajs/medusa/core-flows` package that you can use.
1. Retrieve the cart using its ID. Medusa provides a `useQueryGraphStep` in the `@medusajs/medusa/core-flows` package that you can use.
2. Create a parent order for the cart and its items. Medusa also has a `completeCartWorkflow` in the `@medusajs/medusa/core-flows` package that you can use as a step.
3. Group the cart items by their products associated vendor.
4. Retrieve the order's details using Medusa's `getOrderDetailWorkflow` exported by the `@medusajs/medusa/core-flows` package.
@@ -1135,25 +1135,24 @@ The compensation function cancels all child orders received from the step. It us
Finally, create the workflow at the file `src/workflows/marketplace/create-vendor-orders/index.ts`:
export const createVendorOrdersWorkflowHighlights = [
["21", "useRemoteQueryStep", "Retrieve the cart's details."],
["29", "completeCartWorkflow", "Create the parent order from the cart."],
["35", "groupVendorItemsStep", "Group the items by their vendor."],
["42", "createVendorOrdersStep", "Create child orders for each vendor"],
["47", "createRemoteLinkStep", "Create the links returned by the previous step."]
["21", "useQueryGraphStep", "Retrieve the cart's details."],
["30", "completeCartWorkflow", "Create the parent order from the cart."],
["36", "groupVendorItemsStep", "Group the items by their vendor."],
["59", "createVendorOrdersStep", "Create child orders for each vendor"],
["64", "createRemoteLinkStep", "Create the links returned by the previous step."]
]
```ts title="src/workflows/marketplace/create-vendor-orders/index.ts" collapsibleLines="1-13" expandMoreLabel="Show Imports"
import {
createWorkflow,
WorkflowResponse,
WorkflowResponse
} from "@medusajs/framework/workflows-sdk"
import {
useRemoteQueryStep,
useQueryGraphStep,
createRemoteLinkStep,
completeCartWorkflow,
getOrderDetailWorkflow
} from "@medusajs/medusa/core-flows"
import { CartDTO } from "@medusajs/framework/types"
import groupVendorItemsStep from "./steps/group-vendor-items"
import createVendorOrdersStep from "./steps/create-vendor-orders"
@@ -1164,24 +1163,25 @@ type WorkflowInput = {
const createVendorOrdersWorkflow = createWorkflow(
"create-vendor-order",
(input: WorkflowInput) => {
const cart = useRemoteQueryStep({
entry_point: "cart",
fields: ["items.*"],
variables: { id: input.cart_id },
list: false,
throw_if_key_not_found: true,
}) as CartDTO
const { data: carts } = useQueryGraphStep({
entity: "cart",
fields: ['items.*'],
filters: { id: input.cart_id },
options: {
throwIfKeyNotFound: true
}
})
const { id: orderId } = completeCartWorkflow.runAsStep({
input: {
id: cart.id
id: carts[0].id
}
})
const { vendorsItems } = groupVendorItemsStep({
cart,
cart: carts[0].id
})
const order = getOrderDetailWorkflow.runAsStep({
input: {
order_id: orderId,
@@ -1200,17 +1200,17 @@ const createVendorOrdersWorkflow = createWorkflow(
const {
orders: vendorOrders,
linkDefs,
linkDefs
} = createVendorOrdersStep({
parentOrder: order,
vendorsItems,
vendorsItems
})
createRemoteLinkStep(linkDefs)
return new WorkflowResponse({
parent_order: order,
vendor_orders: vendorOrders,
vendor_orders: vendorOrders
})
}
)
@@ -1220,11 +1220,12 @@ export default createVendorOrdersWorkflow
In the workflow, you run the following steps:
1. `useRemoteQueryStep` to retrieve the cart's details.
1. `useQueryGraphStep` to retrieve the cart's details.
2. `completeCartWorkflow` to complete the cart and create a parent order.
3. `groupVendorItemsStep` to group the order's items by their vendor.
4. `createVendorOrdersStep` to create child orders for each vendor's items.
5. `createRemoteLinkStep` to create the links returned by the previous step.
4. `getOrderDetailWorkflow` to retrieve an order's details.
5. `createVendorOrdersStep` to create child orders for each vendor's items.
6. `createRemoteLinkStep` to create the links returned by the previous step.
You return the parent and vendor orders.
@@ -592,23 +592,23 @@ Create the file `src/workflows/create-subscription/index.ts` with the following
export const createSubscriptionWorkflowHighlights = [
["26", "completeCartWorkflow", "Complete the cart and create the order."],
["32", "useRemoteQueryStep", "Retrieve the order's details."],
["44", "createSubscriptionStep", "Create the subscription."],
["51", "createRemoteLinkStep", "Create the links returned by the previous step."]
["32", "useQueryGraphStep", "Retrieve the order's details."],
["43", "createSubscriptionStep", "Create the subscription."],
["50", "createRemoteLinkStep", "Create the links returned by the previous step."]
]
```ts title="src/workflows/create-subscription/index.ts" highlights={createSubscriptionWorkflowHighlights} collapsibleLines="1-13" expandMoreLabel="Show Imports"
import {
createWorkflow,
WorkflowResponse,
WorkflowResponse
} from "@medusajs/framework/workflows-sdk"
import {
createRemoteLinkStep,
completeCartWorkflow,
useRemoteQueryStep
useQueryGraphStep
} from "@medusajs/medusa/core-flows"
import {
SubscriptionInterval,
SubscriptionInterval
} from "../../modules/subscription/types"
import createSubscriptionStep from "./steps/create-subscription"
@@ -629,30 +629,29 @@ const createSubscriptionWorkflow = createWorkflow(
}
})
const order = useRemoteQueryStep({
entry_point: "order",
const { data: orders } = useQueryGraphStep({
entity: "order",
fields: ["*", "id", "customer_id"],
variables: {
filters: {
id
}
filters: {
id
},
list: false,
throw_if_key_not_found: true
options: {
throwIfKeyNotFound: true
}
})
const { subscription, linkDefs } = createSubscriptionStep({
cart_id: input.cart_id,
order_id: order.id,
customer_id: order.customer_id,
subscription_data: input.subscription_data,
order_id: orders[0].id,
customer_id: orders[0].customer_id,
subscription_data: input.subscription_data
})
createRemoteLinkStep(linkDefs)
return new WorkflowResponse({
subscription: subscription,
order: order,
order: orders[0]
})
}
)
@@ -663,7 +662,7 @@ export default createSubscriptionWorkflow
This workflow accepts the carts ID, along with the subscription details. It executes the following steps:
1. `completeCartWorkflow` from `@medusajs/medusa/core-flows` that completes a cart and creates an order.
2. `useRemoteQueryStep` from `@medusajs/medusa/core-flows` to retrieve the order's details.
2. `useQueryGraphStep` from `@medusajs/medusa/core-flows` to retrieve the order's details.
3. `createSubscriptionStep`, which is the step you created previously.
4. `createRemoteLinkStep` from `@medusajs/medusa/core-flows`, which accepts links to create. These links are in the `linkDefs` array returned by the previous step.
@@ -1478,7 +1477,7 @@ The workflow has eight steps:
```mermaid
graph TD
useRemoteQueryStep["Retrieve Cart (useRemoteQueryStep by Medusa)"] --> createPaymentCollectionStep["createPaymentCollectionStep (Medusa)"]
useQueryGraphStep["Retrieve Cart (useQueryGraphStep by Medusa)"] --> createPaymentCollectionStep["createPaymentCollectionStep (Medusa)"]
createPaymentCollectionStep["createPaymentCollectionStep (Medusa)"] --> createPaymentSessionsWorkflow["createPaymentSessionsWorkflow (Medusa)"]
createPaymentSessionsWorkflow["createPaymentSessionsWorkflow (Medusa)"] --> authorizePaymentSessionStep["authorizePaymentSessionStep (Medusa)"]
authorizePaymentSessionStep["authorizePaymentSessionStep (Medusa)"] --> createSubscriptionOrderStep
@@ -1487,7 +1486,7 @@ graph TD
capturePaymentStep["capturePaymentStep (Medusa)"] --> updateSubscriptionStep
```
1. Retrieve the subscriptions linked cart. Medusa provides a `useRemoteQueryStep` in the `@medusajs/medusa/core-flows` package that can be used as a step.
1. Retrieve the subscriptions linked cart. Medusa provides a `useQueryGraphStep` in the `@medusajs/medusa/core-flows` package that can be used as a step.
2. Create a payment collection for the new order. Medusa provides a `createPaymentCollectionsStep` in the `@medusajs/medusa/core-flows` package that you can use.
3. Create payment sessions in the payment collection. Medusa provides a `createPaymentSessionsWorkflow` in the `@medusajs/medusa/core-flows` package that can be used as a step.
4. Authorize the payment session. Medusa also provides the `authorizePaymentSessionStep` in the `@medusajs/medusa/core-flows` package, which can be used.
@@ -1771,38 +1770,30 @@ This updates the subscriptions `last_order_date` and `next_order_date` proper
Finally, create the file `src/workflows/create-subscription-order/index.ts` with the following content:
export const createSubscriptionOrderWorkflowHighlights = [
["33", "useRemoteQueryStep", "Retrieve the cart linked to the subscription."],
["60", "createPaymentCollectionsStep", "Create a payment collection using the same information in the cart."],
["67", "createPaymentSessionsWorkflow", "Create a payment session in the payment collection from the previous step."],
["76", "authorizePaymentSessionStep", "Authorize the payment session created from the first step."],
["81", "createSubscriptionOrderStep", "Create the new order for the subscription."],
["87", "createRemoteLinkStep", "Create links returned by the previous step."],
["89", "capturePaymentStep", "Capture the orders payment."],
["94", "updateSubscriptionStep", "Update the subscriptions `last_order_date` and `next_order_date`."]
["25", "useQueryGraphStep", "Retrieve the cart linked to the subscription."],
["49", "createPaymentCollectionsStep", "Create a payment collection using the same information in the cart."],
["56", "createPaymentSessionsWorkflow", "Create a payment session in the payment collection from the previous step."],
["65", "authorizePaymentSessionStep", "Authorize the payment session created from the first step."],
["70", "createSubscriptionOrderStep", "Create the new order for the subscription."],
["76", "createRemoteLinkStep", "Create links returned by the previous step."],
["78", "capturePaymentStep", "Capture the orders payment."],
["83", "updateSubscriptionStep", "Update the subscriptions `last_order_date` and `next_order_date`."]
]
```ts title="src/workflows/create-subscription-order/index.ts" highlights={createSubscriptionOrderWorkflowHighlights} collapsibleLines="1-25" expandMoreLabel="Show Imports"
import { createWorkflow, WorkflowResponse } from "@medusajs/framework/workflows-sdk"
import {
createWorkflow,
WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"
import {
useRemoteQueryStep,
useQueryGraphStep,
createPaymentSessionsWorkflow,
createRemoteLinkStep,
capturePaymentStep,
capturePaymentStep
} from "@medusajs/medusa/core-flows"
import {
CartWorkflowDTO,
} from "@medusajs/framework/types"
import {
SubscriptionData,
SubscriptionData
} from "../../modules/subscription/types"
import {
authorizePaymentSessionStep,
} from "@medusajs/medusa/core-flows"
import {
createPaymentCollectionsStep,
createPaymentCollectionsStep
} from "@medusajs/medusa/core-flows"
import createSubscriptionOrderStep from "./steps/create-subscription-order"
import updateSubscriptionStep from "./steps/update-subscription"
@@ -1814,8 +1805,8 @@ type WorkflowInput = {
const createSubscriptionOrderWorkflow = createWorkflow(
"create-subscription-order",
(input: WorkflowInput) => {
const { cart } = useRemoteQueryStep({
entry_point: "subscription",
const { data: carts } = useQueryGraphStep({
entity: "subscription",
fields: [
"*",
"cart.*",
@@ -1828,59 +1819,56 @@ const createSubscriptionOrderWorkflow = createWorkflow(
"cart.shipping_methods.tax_lines.*",
"cart.shipping_methods.adjustments.*",
"cart.payment_collection.*",
"cart.payment_collection.payment_sessions.*",
"cart.payment_collection.payment_sessions.*"
],
variables: {
filters: {
id: [input.subscription.id],
},
filters: {
id: [input.subscription.id]
},
list: false,
throw_if_key_not_found: true,
}) as {
cart: CartWorkflowDTO
}
options: {
throwIfKeyNotFound: true
}
})
const payment_collection = createPaymentCollectionsStep([{
region_id: cart.region_id,
currency_code: cart.currency_code,
amount: cart.payment_collection.amount,
metadata: cart.payment_collection.metadata,
region_id: carts[0].region_id,
currency_code: carts[0].currency_code,
amount: carts[0].payment_collection.amount,
metadata: carts[0].payment_collection.metadata
}])[0]
const paymentSession = createPaymentSessionsWorkflow.runAsStep({
input: {
payment_collection_id: payment_collection.id,
provider_id: cart.payment_collection.payment_sessions[0].provider_id,
data: cart.payment_collection.payment_sessions[0].data,
context: cart.payment_collection.payment_sessions[0].context,
},
provider_id: carts[0].payment_collection.payment_sessions[0].provider_id,
data: carts[0].payment_collection.payment_sessions[0].data,
context: carts[0].payment_collection.payment_sessions[0].context
}
})
const payment = authorizePaymentSessionStep({
id: paymentSession.id,
context: paymentSession.context,
context: paymentSession.context
})
const { order, linkDefs } = createSubscriptionOrderStep({
subscription: input.subscription,
cart,
payment_collection,
cart: carts[0],
payment_collection
})
createRemoteLinkStep(linkDefs)
capturePaymentStep({
payment_id: payment.id,
amount: payment.amount,
amount: payment.amount
})
updateSubscriptionStep({
subscription_id: input.subscription.id,
subscription_id: input.subscription.id
})
return new WorkflowResponse({
order,
order
})
}
)
@@ -1890,7 +1878,7 @@ export default createSubscriptionOrderWorkflow
The workflow runs the following steps:
1. `useRemoteQueryStep` to retrieve the details of the cart linked to the subscription.
1. `useQueryGraphStep` to retrieve the details of the cart linked to the subscription.
2. `createPaymentCollectionsStep` to create a payment collection using the same information in the cart.
3. `createPaymentSessionsWorkflow` to create a payment session in the payment collection from the previous step.
4. `authorizePaymentSessionStep` to authorize the payment session created from the first step.