feat: Add useQueryStep (#9384)
* feat: Query step replacement * fix * fix types
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
"expect-type": "^0.20.0",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
"rimraf": "^5.0.1",
|
||||
|
||||
@@ -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>>>
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"]
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
} from "@medusajs/orchestration"
|
||||
import { isString, OrchestrationUtils } from "@medusajs/utils"
|
||||
import { ulid } from "ulid"
|
||||
import { StepResponse, resolveValue } from "./helpers"
|
||||
import { resolveValue, StepResponse } from "./helpers"
|
||||
import { createStepHandler } from "./helpers/create-step-handler"
|
||||
import { proxify } from "./helpers/proxy"
|
||||
import {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { CompensateFn, InvokeFn } from "./create-step"
|
||||
export type StepFunctionResult<TOutput extends unknown | unknown[] = unknown> =
|
||||
(this: CreateWorkflowComposerContext) => WorkflowData<TOutput>
|
||||
|
||||
type StepFunctionReturnConfig<TOutput> = {
|
||||
export type StepFunctionReturnConfig<TOutput> = {
|
||||
config(
|
||||
config: { name?: string } & Omit<
|
||||
TransactionStepsDefinition,
|
||||
|
||||
Reference in New Issue
Block a user