chore: Allow to fetch remote link using the service name or the alias from the use remote link step (#8140)
* chore: Allow to fetch remote link using the service name or the alias from the use remote link step * revert package.json * fix packages
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
entry_point: string
|
||||
fields: string[]
|
||||
variables?: Record<string, any>
|
||||
throw_if_key_not_found?: boolean
|
||||
@@ -10,18 +12,32 @@ interface StepInput {
|
||||
list?: boolean
|
||||
}
|
||||
|
||||
interface EntryStepInput extends StepInput {
|
||||
entry_point: string
|
||||
}
|
||||
|
||||
interface ServiceStepInput extends StepInput {
|
||||
service: string
|
||||
}
|
||||
|
||||
export const useRemoteQueryStepId = "use-remote-query"
|
||||
export const useRemoteQueryStep = createStep(
|
||||
useRemoteQueryStepId,
|
||||
async (data: StepInput, { container }) => {
|
||||
const { list = true, fields, variables, entry_point: entryPoint } = data
|
||||
const query = container.resolve("remoteQuery")
|
||||
async (data: EntryStepInput | ServiceStepInput, { container }) => {
|
||||
const { list = true, fields, variables } = data
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint,
|
||||
const query = container.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const isUsingEntryPoint = "entry_point" in data
|
||||
|
||||
const queryObjectConfig = {
|
||||
fields,
|
||||
variables,
|
||||
})
|
||||
entryPoint: isUsingEntryPoint ? data.entry_point : undefined,
|
||||
service: !isUsingEntryPoint ? data.service : undefined,
|
||||
} as Parameters<typeof remoteQueryObjectFromString>[0]
|
||||
|
||||
const queryObject = remoteQueryObjectFromString(queryObjectConfig)
|
||||
|
||||
const config = {
|
||||
throwIfKeyNotFound: !!data.throw_if_key_not_found,
|
||||
|
||||
Reference in New Issue
Block a user