docs: change useRemoteQueryStep to useQueryGraphStep (#10051)
* docs: change useRemoteQueryStep to useQueryGraphStep * fix lint errors
This commit is contained in:
@@ -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 cart’s 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 subscription’s linked cart. Medusa provides a `useRemoteQueryStep` in the `@medusajs/medusa/core-flows` package that can be used as a step.
|
||||
1. Retrieve the subscription’s 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 subscription’s `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 order’s payment."],
|
||||
["94", "updateSubscriptionStep", "Update the subscription’s `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 order’s payment."],
|
||||
["83", "updateSubscriptionStep", "Update the subscription’s `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.
|
||||
|
||||
Reference in New Issue
Block a user