feat: Add useQueryStep (#9384)
* feat: Query step replacement * fix * fix types
This commit is contained in:
@@ -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>>>
|
||||
Reference in New Issue
Block a user