feat: Add useQueryStep (#9384)

* feat: Query step replacement

* fix

* fix types
This commit is contained in:
Adrien de Peretti
2024-10-07 12:07:06 +02:00
committed by GitHub
parent 2d8ce6fd5b
commit ad3524ffbe
8 changed files with 38 additions and 8 deletions
@@ -1,6 +1,6 @@
import { IPricingModuleService } from "@medusajs/framework/types"
import { MedusaError, Modules } from "@medusajs/framework/utils"
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
import { createStep, StepResponse } from "@medusajs/framework/workflows-sdk"
export interface GetVariantPriceSetsStepInput {
variantIds: string[]
@@ -3,6 +3,7 @@ export * from "./steps/dismiss-remote-links"
export * from "./steps/remove-remote-links"
export * from "./steps/emit-event"
export * from "./steps/update-remote-links"
export * from "./steps/use-query-graph"
export * from "./steps/use-remote-query"
export * from "./workflows/batch-links"
export * from "./workflows/create-links"
@@ -0,0 +1,32 @@
import {
GraphResultSet,
RemoteJoinerOptions,
RemoteQueryFunction,
RemoteQueryInput,
} from "@medusajs/framework/types"
import { createStep, StepFunction, StepResponse } from "@medusajs/workflows-sdk"
import { ContainerRegistrationKeys } from "@medusajs/utils"
type EntryStepInput<TEntry extends string> = RemoteQueryInput<TEntry> & {
options?: RemoteJoinerOptions
}
const useQueryGraphStepId = "use-query-graph-step"
const step = createStep(
useQueryGraphStepId,
async (input: EntryStepInput<any>, { container }) => {
const query = container.resolve<RemoteQueryFunction>(
ContainerRegistrationKeys.QUERY
)
const { options, ...queryConfig } = input
const result = await query.graph(queryConfig as any, options)
return new StepResponse(result)
}
)
export const useQueryGraphStep = <const TEntry extends string>(
input: EntryStepInput<TEntry>
): ReturnType<StepFunction<EntryStepInput<TEntry>, GraphResultSet<TEntry>>> =>
step(input as any) as unknown as ReturnType<StepFunction<EntryStepInput<TEntry>, GraphResultSet<TEntry>>>