From b9e772b530ac77c8e84cef3ce3b0dde4d96b3713 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Tue, 1 Oct 2024 08:53:52 +0200 Subject: [PATCH] chore: Add import from framework types at the top of ay generated types file (#9389) --- .../utils/src/graphql/graphql-to-ts-types.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/utils/src/graphql/graphql-to-ts-types.ts b/packages/core/utils/src/graphql/graphql-to-ts-types.ts index 3e7d425c66..0572c9f200 100644 --- a/packages/core/utils/src/graphql/graphql-to-ts-types.ts +++ b/packages/core/utils/src/graphql/graphql-to-ts-types.ts @@ -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) } } }