Skip to content

Commit

Permalink
feat: Add useQueryStep (#9384)
Browse files Browse the repository at this point in the history
* feat: Query step replacement

* fix

* fix types
  • Loading branch information
adrien2p authored Oct 7, 2024
1 parent 2d8ce6f commit ad3524f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/core/core-flows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down
1 change: 1 addition & 0 deletions packages/core/core-flows/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions packages/core/core-flows/src/common/steps/use-query-graph.ts
Original file line number Diff line number Diff line change
@@ -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>>>
5 changes: 0 additions & 5 deletions packages/core/core-flows/tsconfig.spec.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/workflows-sdk/src/utils/composer/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5246,6 +5246,7 @@ __metadata:
"@swc/core": ^1.7.28
"@swc/jest": ^0.2.36
awilix: ^8.0.1
expect-type: ^0.20.0
jest: ^29.7.0
json-2-csv: ^5.5.4
pg: ^8.13.0
Expand Down

0 comments on commit ad3524f

Please sign in to comment.