From 1a5cfdf50d06b096510e55dff9b50e25e239e0d6 Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 17 Dec 2024 19:45:00 +0200 Subject: [PATCH] fix(core-flows): use useQueryGraphStep instead of useQueryStep --- .changeset/heavy-spies-thank.md | 5 +++++ .../src/cart/workflows/complete-cart.ts | 4 ++-- .../core-flows/src/common/steps/use-query.ts | 21 ------------------- .../src/payment/workflows/process-payment.ts | 8 +++---- 4 files changed, 11 insertions(+), 27 deletions(-) create mode 100644 .changeset/heavy-spies-thank.md delete mode 100644 packages/core/core-flows/src/common/steps/use-query.ts diff --git a/.changeset/heavy-spies-thank.md b/.changeset/heavy-spies-thank.md new file mode 100644 index 0000000000000..dbfa3b0872264 --- /dev/null +++ b/.changeset/heavy-spies-thank.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix(core-flows): use useQueryGraphStep instead of useQueryStep diff --git a/packages/core/core-flows/src/cart/workflows/complete-cart.ts b/packages/core/core-flows/src/cart/workflows/complete-cart.ts index 42c28e1b5bdf7..219f6fa8e7e3c 100644 --- a/packages/core/core-flows/src/cart/workflows/complete-cart.ts +++ b/packages/core/core-flows/src/cart/workflows/complete-cart.ts @@ -18,9 +18,9 @@ import { import { createRemoteLinkStep, emitEventStep, + useQueryGraphStep, useRemoteQueryStep, } from "../../common" -import { useQueryStep } from "../../common/steps/use-query" import { createOrdersStep } from "../../order/steps/create-orders" import { authorizePaymentSessionStep } from "../../payment/steps/authorize-payment-session" import { registerUsageStep } from "../../promotion/steps/register-usage" @@ -54,7 +54,7 @@ export const completeCartWorkflow = createWorkflow( ( input: WorkflowData ): WorkflowResponse<{ id: string }> => { - const orderCart = useQueryStep({ + const orderCart = useQueryGraphStep({ entity: "order_cart", fields: ["cart_id", "order_id"], filters: { cart_id: input.id }, diff --git a/packages/core/core-flows/src/common/steps/use-query.ts b/packages/core/core-flows/src/common/steps/use-query.ts deleted file mode 100644 index 6d28317d79b30..0000000000000 --- a/packages/core/core-flows/src/common/steps/use-query.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { ContainerRegistrationKeys } from "@medusajs/utils" -import { createStep, StepResponse } from "@medusajs/workflows-sdk" - -interface QueryInput { - entity: string - fields: string[] - filters?: Record - context?: any -} - -export const useQueryStepId = "use-query" -export const useQueryStep = createStep( - useQueryStepId, - async (data: QueryInput, { container }) => { - const query = container.resolve(ContainerRegistrationKeys.QUERY) - - const result = await query.graph(data) - - return new StepResponse(result) - } -) diff --git a/packages/core/core-flows/src/payment/workflows/process-payment.ts b/packages/core/core-flows/src/payment/workflows/process-payment.ts index 5cfdf5ee82caf..c2af91e8c1ca5 100644 --- a/packages/core/core-flows/src/payment/workflows/process-payment.ts +++ b/packages/core/core-flows/src/payment/workflows/process-payment.ts @@ -2,9 +2,9 @@ import { WebhookActionResult } from "@medusajs/types" import { PaymentActions } from "@medusajs/utils" import { createWorkflow, when } from "@medusajs/workflows-sdk" import { completeCartWorkflow } from "../../cart/workflows/complete-cart" -import { useQueryStep } from "../../common/steps/use-query" import { authorizePaymentSessionStep } from "../steps" import { capturePaymentWorkflow } from "./capture-payment" +import { useQueryGraphStep } from "../../common" interface ProcessPaymentWorkflowInput extends WebhookActionResult {} @@ -12,7 +12,7 @@ export const processPaymentWorkflowId = "process-payment-workflow" export const processPaymentWorkflow = createWorkflow( processPaymentWorkflowId, (input: ProcessPaymentWorkflowInput) => { - const paymentData = useQueryStep({ + const paymentData = useQueryGraphStep({ entity: "payment", fields: ["id"], filters: { payment_session_id: input.data?.session_id }, @@ -20,7 +20,7 @@ export const processPaymentWorkflow = createWorkflow( name: "payment-query", }) - const paymentSessionResult = useQueryStep({ + const paymentSessionResult = useQueryGraphStep({ entity: "payment_session", fields: ["payment_collection_id"], filters: { id: input.data?.session_id }, @@ -28,7 +28,7 @@ export const processPaymentWorkflow = createWorkflow( name: "payment-session-query", }) - const cartPaymentCollection = useQueryStep({ + const cartPaymentCollection = useQueryGraphStep({ entity: "cart_payment_collection", fields: ["cart_id"], filters: {