feat: Application types generation from project GQL schema's (#8995)
This commit is contained in:
@@ -31,7 +31,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
@@ -79,7 +78,6 @@ export const DELETE = async (
|
||||
},
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export const POST = async (
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderClaim] = await remoteQuery(queryObject, undefined, {
|
||||
const [orderClaim] = await remoteQuery(queryObject, {
|
||||
throwIfKeyNotFound: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
-2
@@ -30,7 +30,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
@@ -79,7 +78,6 @@ export const DELETE = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export const POST = async (
|
||||
},
|
||||
fields: ["return_id"],
|
||||
}),
|
||||
undefined,
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ export const POST = async (
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderExchange] = await remoteQuery(queryObject, undefined, {
|
||||
const [orderExchange] = await remoteQuery(queryObject, {
|
||||
throwIfKeyNotFound: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -140,7 +140,6 @@ export const refetchBatchProducts = async (
|
||||
fields: remapKeysForProduct(fields ?? []),
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
created = remoteQuery(createdQuery)
|
||||
}
|
||||
|
||||
@@ -153,7 +152,6 @@ export const refetchBatchProducts = async (
|
||||
fields: remapKeysForProduct(fields ?? []),
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
updated = remoteQuery(updatedQuery)
|
||||
}
|
||||
|
||||
@@ -187,7 +185,6 @@ export const refetchBatchVariants = async (
|
||||
fields: remapKeysForVariant(fields ?? []),
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
created = remoteQuery(createdQuery)
|
||||
}
|
||||
|
||||
@@ -200,7 +197,6 @@ export const refetchBatchVariants = async (
|
||||
fields: remapKeysForVariant(fields ?? []),
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
updated = remoteQuery(updatedQuery)
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ export const refetchBatchRules = async (
|
||||
fields: fields,
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
created = remoteQuery(createdQuery)
|
||||
}
|
||||
|
||||
@@ -55,7 +54,6 @@ export const refetchBatchRules = async (
|
||||
fields: fields,
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
updated = remoteQuery(updatedQuery)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export const GET = async (
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
const [orderReturn] = await remoteQuery(queryObject, undefined, {
|
||||
const [orderReturn] = await remoteQuery(queryObject, {
|
||||
throwIfKeyNotFound: true,
|
||||
})
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ export const refetchBatchRules = async (
|
||||
fields: fields,
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
created = remoteQuery(createdQuery)
|
||||
}
|
||||
|
||||
@@ -58,7 +57,6 @@ export const refetchBatchRules = async (
|
||||
fields: fields,
|
||||
})
|
||||
|
||||
// @ts-expect-error "Remote query can return null"
|
||||
updated = remoteQuery(updatedQuery)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ export async function getVariantInventoryItems({
|
||||
"inventory.*",
|
||||
"inventory.location_levels.*",
|
||||
],
|
||||
})
|
||||
} as any)
|
||||
|
||||
const links = await remoteQuery(linkQuery)
|
||||
|
||||
|
||||
@@ -4,13 +4,14 @@ import {
|
||||
isString,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { MedusaRequest } from "../../types/routing"
|
||||
|
||||
export const refetchEntities = async (
|
||||
entryPoint: string,
|
||||
idOrFilter: string | object,
|
||||
scope: MedusaContainer,
|
||||
fields: string[],
|
||||
pagination: object = {}
|
||||
pagination: MedusaRequest["remoteQueryConfig"]["pagination"] = {}
|
||||
) => {
|
||||
const remoteQuery = scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
const filters = isString(idOrFilter) ? { id: idOrFilter } : idOrFilter
|
||||
|
||||
@@ -13,7 +13,7 @@ const defaultConfig = {
|
||||
borderStyle: `double`,
|
||||
} as boxen.Options
|
||||
|
||||
export default async function ({ port, directory }) {
|
||||
export default async function ({ types, directory }) {
|
||||
const args = process.argv
|
||||
|
||||
const argv =
|
||||
@@ -25,6 +25,10 @@ export default async function ({ port, directory }) {
|
||||
args.shift()
|
||||
args.shift()
|
||||
|
||||
if (types) {
|
||||
args.push("--types")
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-constructing the path to Medusa CLI to execute the
|
||||
* start command.
|
||||
@@ -95,6 +99,7 @@ export default async function ({ port, directory }) {
|
||||
"static",
|
||||
"private",
|
||||
"src/admin/**/*",
|
||||
".medusa/**/*",
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@@ -2,25 +2,35 @@ import express from "express"
|
||||
import { track } from "medusa-telemetry"
|
||||
import { scheduleJob } from "node-schedule"
|
||||
|
||||
import { logger } from "@medusajs/framework"
|
||||
import { gqlSchemaToTypes, logger } from "@medusajs/framework"
|
||||
import { GracefulShutdownServer } from "@medusajs/utils"
|
||||
import loaders from "../loaders"
|
||||
import path from "path"
|
||||
|
||||
const EVERY_SIXTH_HOUR = "0 */6 * * *"
|
||||
const CRON_SCHEDULE = EVERY_SIXTH_HOUR
|
||||
|
||||
export default async function ({ port, directory }) {
|
||||
export default async function ({ port, directory, types }) {
|
||||
async function start() {
|
||||
track("CLI_START")
|
||||
|
||||
const app = express()
|
||||
|
||||
try {
|
||||
const { shutdown } = await loaders({
|
||||
const { shutdown, gqlSchema } = await loaders({
|
||||
directory,
|
||||
expressApp: app,
|
||||
})
|
||||
|
||||
if (gqlSchema && types) {
|
||||
const outputDirGeneratedTypes = path.join(directory, ".medusa")
|
||||
await gqlSchemaToTypes({
|
||||
outputDir: outputDirGeneratedTypes,
|
||||
schema: gqlSchema,
|
||||
})
|
||||
logger.info("Geneated modules types")
|
||||
}
|
||||
|
||||
const serverActivity = logger.activity(`Creating server`)
|
||||
const server = GracefulShutdownServer.create(
|
||||
app.listen(port).on("listening", () => {
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
container,
|
||||
expressLoader,
|
||||
featureFlagsLoader,
|
||||
GraphQLSchema,
|
||||
JobLoader,
|
||||
LinkLoader,
|
||||
logger,
|
||||
@@ -133,6 +134,7 @@ export default async ({
|
||||
container: MedusaContainer
|
||||
app: Express
|
||||
shutdown: () => Promise<void>
|
||||
gqlSchema?: GraphQLSchema
|
||||
}> => {
|
||||
const container = await initializeContainer(rootDirectory)
|
||||
const configModule = container.resolve(
|
||||
@@ -149,6 +151,7 @@ export default async ({
|
||||
onApplicationStart,
|
||||
onApplicationShutdown,
|
||||
onApplicationPrepareShutdown,
|
||||
gqlSchema,
|
||||
} = await new MedusaAppLoader().load()
|
||||
|
||||
const workflowsSourcePaths = plugins.map((p) => join(p.resolve, "workflows"))
|
||||
@@ -184,5 +187,6 @@ export default async ({
|
||||
container,
|
||||
app: expressApp,
|
||||
shutdown,
|
||||
gqlSchema,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user