chore: Add import from framework types at the top of ay generated types file (#9389)
This commit is contained in:
committed by
GitHub
parent
9b6d0e9d56
commit
b9e772b530
@@ -1,5 +1,5 @@
|
||||
import { codegen } from "@graphql-codegen/core"
|
||||
import { parse, printSchema, type GraphQLSchema } from "graphql"
|
||||
import { type GraphQLSchema, parse, printSchema } from "graphql"
|
||||
import * as typescriptPlugin from "@graphql-codegen/typescript"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { FileSystem } from "../common"
|
||||
@@ -54,11 +54,12 @@ async function generateTypes({
|
||||
}) {
|
||||
const fileSystem = new FileSystem(outputDir)
|
||||
|
||||
let output = await codegen(config)
|
||||
let output = 'import "@medusajs/framework/types\n'
|
||||
output += await codegen(config)
|
||||
const entryPoints = buildEntryPointsTypeMap({ schema: output, joinerConfigs })
|
||||
|
||||
const remoteQueryEntryPoints = `
|
||||
declare module '@medusajs/types' {
|
||||
declare module '@medusajs/framework/types' {
|
||||
interface ${interfaceName} {
|
||||
${entryPoints
|
||||
.map((entry) => ` ${entry.entryPoint}: ${entry.entityType}`)
|
||||
@@ -68,19 +69,20 @@ ${entryPoints
|
||||
|
||||
output += remoteQueryEntryPoints
|
||||
|
||||
const barrelFileName = "index.d.ts"
|
||||
await fileSystem.create(filename + ".d.ts", output)
|
||||
|
||||
const doesBarrelExists = await fileSystem.exists("index.d.ts")
|
||||
const doesBarrelExists = await fileSystem.exists(barrelFileName)
|
||||
if (!doesBarrelExists) {
|
||||
await fileSystem.create(
|
||||
"index.d.ts",
|
||||
barrelFileName,
|
||||
`export * as ${interfaceName}Types from './${filename}'`
|
||||
)
|
||||
} else {
|
||||
const content = await fileSystem.contents("index.d.ts")
|
||||
const content = await fileSystem.contents(barrelFileName)
|
||||
if (!content.includes(`${interfaceName}Types`)) {
|
||||
const newContent = `export * as ${interfaceName}Types from './${filename}'\n${content}`
|
||||
await fileSystem.create("index.d.ts", newContent)
|
||||
await fileSystem.create(barrelFileName, newContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user