feat: Application types generation from project GQL schema's (#8995)
This commit is contained in:
committed by
GitHub
parent
ac30a989f4
commit
2c5e72d141
@@ -1,6 +1,6 @@
|
||||
import { IPricingModuleService } from "@medusajs/types"
|
||||
import { MedusaError, ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export interface GetVariantPriceSetsStepInput {
|
||||
variantIds: string[]
|
||||
@@ -24,21 +24,13 @@ export const getVariantPriceSetsStep = createStep(
|
||||
|
||||
const remoteQuery = container.resolve("remoteQuery")
|
||||
|
||||
const variantPriceSets = await remoteQuery(
|
||||
{
|
||||
variant: {
|
||||
fields: ["id"],
|
||||
price_set: {
|
||||
fields: ["id"],
|
||||
},
|
||||
},
|
||||
const variantPriceSets = await remoteQuery({
|
||||
entryPoint: "variant",
|
||||
fields: ["id", "price_set.id"],
|
||||
variables: {
|
||||
id: data.variantIds,
|
||||
},
|
||||
{
|
||||
variant: {
|
||||
id: data.variantIds,
|
||||
},
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const notFound: string[] = []
|
||||
const priceSetIds: string[] = []
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
import { CartWorkflowDTO } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
isObject,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, isObject, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export interface RetrieveCartWithLinksStepInput {
|
||||
cart_or_cart_id: string | CartWorkflowDTO
|
||||
@@ -29,12 +24,17 @@ export const retrieveCartWithLinksStep = createStep(
|
||||
const remoteQuery = container.resolve(
|
||||
ContainerRegistrationKeys.REMOTE_QUERY
|
||||
)
|
||||
const query = remoteQueryObjectFromString({
|
||||
const query = {
|
||||
entryPoint: Modules.CART,
|
||||
fields,
|
||||
})
|
||||
variables: {
|
||||
cart: {
|
||||
id,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const [cart] = await remoteQuery(query, { cart: { id } })
|
||||
const [cart] = await remoteQuery(query)
|
||||
|
||||
return new StepResponse(cart)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
Modules,
|
||||
PromotionActions,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export interface UpdateCartPromotionStepInput {
|
||||
id: string
|
||||
@@ -33,9 +33,10 @@ export const updateCartPromotionsStep = createStep(
|
||||
)
|
||||
|
||||
const existingCartPromotionLinks = await remoteQuery({
|
||||
cart_promotion: {
|
||||
__args: { cart_id: [id] },
|
||||
fields: ["cart_id", "promotion_id"],
|
||||
entryPoint: "cart_promotion",
|
||||
fields: ["cart_id", "promotion_id"],
|
||||
variables: {
|
||||
cart_id: [id],
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The remote query's details.
|
||||
@@ -164,7 +164,7 @@ export const useRemoteQueryStep = createStep(
|
||||
: undefined,
|
||||
}
|
||||
|
||||
const entities = await query(queryObject, undefined, config)
|
||||
const entities = await query(queryObjectConfig, config)
|
||||
const result = list ? entities : entities[0]
|
||||
|
||||
return new StepResponse(result)
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
LINKS,
|
||||
Modules,
|
||||
promiseAll,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export type SetShippingOptionsPriceSetsStepInput = {
|
||||
@@ -28,16 +27,14 @@ async function getCurrentShippingOptionPriceSetsLinks(
|
||||
shippingOptionIds: string[],
|
||||
{ remoteQuery }: { remoteQuery: RemoteQueryFunction }
|
||||
): Promise<LinkItems> {
|
||||
const query = remoteQueryObjectFromString({
|
||||
const shippingOptionPriceSetLinks = (await remoteQuery({
|
||||
service: LINKS.ShippingOptionPriceSet,
|
||||
variables: {
|
||||
filters: { shipping_option_id: shippingOptionIds },
|
||||
take: null,
|
||||
},
|
||||
fields: ["shipping_option_id", "price_set_id"],
|
||||
})
|
||||
|
||||
const shippingOptionPriceSetLinks = (await remoteQuery(query)) as {
|
||||
} as any)) as {
|
||||
shipping_option_id: string
|
||||
price_set_id: string
|
||||
}[]
|
||||
|
||||
@@ -10,12 +10,11 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
isDefined,
|
||||
LINKS,
|
||||
ModuleRegistrationName,
|
||||
isDefined,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface PriceRegionId {
|
||||
region_id: string
|
||||
@@ -33,16 +32,14 @@ async function getCurrentShippingOptionPrices(
|
||||
): Promise<
|
||||
{ shipping_option_id: string; price_set_id: string; prices: PriceDTO[] }[]
|
||||
> {
|
||||
const query = remoteQueryObjectFromString({
|
||||
const shippingOptionPrices = (await remoteQuery({
|
||||
service: LINKS.ShippingOptionPriceSet,
|
||||
variables: {
|
||||
filters: { shipping_option_id: shippingOptionIds },
|
||||
take: null,
|
||||
},
|
||||
fields: ["shipping_option_id", "price_set_id", "price_set.prices.*"],
|
||||
})
|
||||
|
||||
const shippingOptionPrices = (await remoteQuery(query)) as {
|
||||
} as any)) as {
|
||||
shipping_option_id: string
|
||||
price_set_id: string
|
||||
price_set: PriceSetDTO
|
||||
|
||||
@@ -3,9 +3,8 @@ import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
ModuleRegistrationName,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export type FulfillmentProviderValidationWorkflowInput = {
|
||||
id?: string
|
||||
@@ -21,7 +20,10 @@ export const validateFulfillmentProvidersStepId =
|
||||
*/
|
||||
export const validateFulfillmentProvidersStep = createStep(
|
||||
validateFulfillmentProvidersStepId,
|
||||
async (input: FulfillmentProviderValidationWorkflowInput[], { container }) => {
|
||||
async (
|
||||
input: FulfillmentProviderValidationWorkflowInput[],
|
||||
{ container }
|
||||
) => {
|
||||
const dataToValidate: {
|
||||
service_zone_id: string
|
||||
provider_id: string
|
||||
@@ -83,7 +85,7 @@ export const validateFulfillmentProvidersStep = createStep(
|
||||
)
|
||||
}
|
||||
|
||||
const serviceZoneQuery = remoteQueryObjectFromString({
|
||||
const serviceZones = await remoteQuery({
|
||||
entryPoint: "service_zone",
|
||||
fields: ["id", "fulfillment_set.locations.fulfillment_providers.id"],
|
||||
variables: {
|
||||
@@ -91,8 +93,6 @@ export const validateFulfillmentProvidersStep = createStep(
|
||||
},
|
||||
})
|
||||
|
||||
const serviceZones = await remoteQuery(serviceZoneQuery)
|
||||
|
||||
const serviceZonesMap = new Map<
|
||||
string,
|
||||
ServiceZoneDTO & {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
arrayDifference,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
@@ -17,13 +16,11 @@ export const validateInventoryItems = createStep(
|
||||
ContainerRegistrationKeys.REMOTE_QUERY
|
||||
)
|
||||
|
||||
const query = remoteQueryObjectFromString({
|
||||
const items = await remoteQuery({
|
||||
entryPoint: "inventory_item",
|
||||
variables: { id },
|
||||
fields: ["id"],
|
||||
})
|
||||
|
||||
const items = await remoteQuery(query)
|
||||
const diff = arrayDifference(
|
||||
id,
|
||||
items.map(({ id }) => id)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
arrayDifference,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { InventoryTypes } from "@medusajs/types"
|
||||
@@ -19,7 +18,7 @@ export const validateInventoryLocationsStep = createStep(
|
||||
ContainerRegistrationKeys.REMOTE_QUERY
|
||||
)
|
||||
|
||||
const locationQuery = remoteQueryObjectFromString({
|
||||
const stockLocations = await remoteQuery({
|
||||
entryPoint: "stock_location",
|
||||
variables: {
|
||||
id: data.map((d) => d.location_id),
|
||||
@@ -27,8 +26,6 @@ export const validateInventoryLocationsStep = createStep(
|
||||
fields: ["id"],
|
||||
})
|
||||
|
||||
const stockLocations = await remoteQuery(locationQuery)
|
||||
|
||||
const diff = arrayDifference(
|
||||
data.map((d) => d.location_id),
|
||||
stockLocations.map((l) => l.id)
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const validateVariantPriceLinksStepId = "validate-variant-price-links"
|
||||
/**
|
||||
@@ -28,13 +24,11 @@ export const validateVariantPriceLinksStep = createStep(
|
||||
.filter(Boolean)
|
||||
.flat(1)
|
||||
|
||||
const variantPricingLinkQuery = remoteQueryObjectFromString({
|
||||
const links = await remoteQuery({
|
||||
entryPoint: "product_variant_price_set",
|
||||
fields: ["variant_id", "price_set_id"],
|
||||
variables: { variant_id: variantIds, take: null },
|
||||
})
|
||||
|
||||
const links = await remoteQuery(variantPricingLinkQuery)
|
||||
const variantPriceSetMap: Record<string, string> = {}
|
||||
|
||||
for (const link of links) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { FilterableProductProps, RemoteQueryFunction } from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export type GetAllProductsStepInput = {
|
||||
@@ -27,7 +24,7 @@ export const getAllProductsStep = createStep(
|
||||
|
||||
// We intentionally fetch the products serially here to avoid putting too much load on the DB
|
||||
while (true) {
|
||||
const remoteQueryObject = remoteQueryObjectFromString({
|
||||
const { rows: products } = await remoteQuery({
|
||||
entryPoint: "product",
|
||||
variables: {
|
||||
filters: data.filter,
|
||||
@@ -36,8 +33,6 @@ export const getAllProductsStep = createStep(
|
||||
},
|
||||
fields: data.select,
|
||||
})
|
||||
|
||||
const { rows: products } = await remoteQuery(remoteQueryObject)
|
||||
allProducts.push(...products)
|
||||
|
||||
if (products.length < pageSize) {
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
import { RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { IPaymentModuleService, RemoteQueryFunction } from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
LINKS,
|
||||
MedusaError,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
arrayDifference,
|
||||
promiseAll,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export interface SetRegionsPaymentProvidersStepInput {
|
||||
input: {
|
||||
@@ -64,16 +63,14 @@ async function getCurrentRegionPaymentProvidersLinks(
|
||||
[Modules.PAYMENT]: { payment_provider_id: string }
|
||||
}[]
|
||||
> {
|
||||
const query = remoteQueryObjectFromString({
|
||||
const regionProviderLinks = (await remoteQuery({
|
||||
service: LINKS.RegionPaymentProvider,
|
||||
variables: {
|
||||
filters: { region_id: regionIds },
|
||||
take: null,
|
||||
},
|
||||
fields: ["region_id", "payment_provider_id"],
|
||||
})
|
||||
|
||||
const regionProviderLinks = (await remoteQuery(query)) as {
|
||||
} as any)) as {
|
||||
region_id: string
|
||||
payment_provider_id: string
|
||||
}[]
|
||||
|
||||
Reference in New Issue
Block a user