UNPKG

@multiplatform.one/typegraphql

Version:
68 lines (65 loc) 2.15 kB
import { createResolvers } from "./chunk-OMA7YBML.js"; import { __name } from "./chunk-SHUYVCID.js"; // src/buildSchema.ts import path from "node:path"; import { buildSchema as typeGraphqlBuildSchema } from "type-graphql"; var logger = console; async function _buildSchemaBin() { const bundlePath = process.argv[2]; const emitPath = process.argv.length > 3 ? path.resolve(process.cwd(), process.argv[3]) : void 0; if (!bundlePath || !emitPath) { if (!bundlePath) logger.error("missing bundle path"); if (!emitPath) logger.error("missing emit path"); process.exit(1); } const { options } = await import(path.resolve(process.cwd(), bundlePath)); await buildSchema(options, emitPath); logger.info(`schema emitted to ${emitPath}`); } __name(_buildSchemaBin, "_buildSchemaBin"); async function buildSchema(options, emit) { return typeGraphqlBuildSchema({ ...createBuildSchemaOptions(options), emitSchemaFile: emit === true ? path.resolve(process.cwd(), "schema.graphql") : emit }); } __name(buildSchema, "buildSchema"); function createBuildSchemaOptions(options) { const validate = { forbidUnknownValues: false }; const buildSchemaOptions = { ...options.buildSchema, container: /* @__PURE__ */ __name(({ context: ctx }) => ({ get: /* @__PURE__ */ __name((resolver) => ctx.container.resolve(resolver), "get") }), "container"), pubSub: options.pubSub, resolvers: createResolvers(options), validate: typeof options.buildSchema?.validate === "object" ? { ...validate, ...options.buildSchema?.validate } : validate }; options.addons?.forEach((addon) => { if (addon.register) { const addonResult = addon.register(options); if (addonResult.buildSchemaOptions?.globalMiddlewares) { buildSchemaOptions.globalMiddlewares = [ ...buildSchemaOptions.globalMiddlewares || [], ...addonResult.buildSchemaOptions.globalMiddlewares ]; } } }); return buildSchemaOptions; } __name(createBuildSchemaOptions, "createBuildSchemaOptions"); export { _buildSchemaBin, buildSchema, createBuildSchemaOptions };