fix: Generated types interface name (#9307)
**What** Fix interface name in the output generated types
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { FileSystem, toCamelCase } from "@medusajs/utils"
|
import { FileSystem } from "@medusajs/utils"
|
||||||
import { GraphQLSchema } from "graphql/type"
|
import { GraphQLSchema } from "graphql/type"
|
||||||
import { parse, printSchema } from "graphql"
|
import { parse, printSchema } from "graphql"
|
||||||
import { codegen } from "@graphql-codegen/core"
|
import { codegen } from "@graphql-codegen/core"
|
||||||
@@ -43,11 +43,13 @@ function buildEntryPointsTypeMap({
|
|||||||
async function generateTypes({
|
async function generateTypes({
|
||||||
outputDir,
|
outputDir,
|
||||||
filename,
|
filename,
|
||||||
|
interfaceName,
|
||||||
config,
|
config,
|
||||||
joinerConfigs,
|
joinerConfigs,
|
||||||
}: {
|
}: {
|
||||||
outputDir: string
|
outputDir: string
|
||||||
filename: string
|
filename: string
|
||||||
|
interfaceName: string
|
||||||
config: Parameters<typeof codegen>[0]
|
config: Parameters<typeof codegen>[0]
|
||||||
joinerConfigs: ModuleJoinerConfig[]
|
joinerConfigs: ModuleJoinerConfig[]
|
||||||
}) {
|
}) {
|
||||||
@@ -56,8 +58,6 @@ async function generateTypes({
|
|||||||
let output = await codegen(config)
|
let output = await codegen(config)
|
||||||
const entryPoints = buildEntryPointsTypeMap({ schema: output, joinerConfigs })
|
const entryPoints = buildEntryPointsTypeMap({ schema: output, joinerConfigs })
|
||||||
|
|
||||||
const interfaceName = toCamelCase(filename)
|
|
||||||
|
|
||||||
const remoteQueryEntryPoints = `
|
const remoteQueryEntryPoints = `
|
||||||
declare module '@medusajs/types' {
|
declare module '@medusajs/types' {
|
||||||
interface ${interfaceName} {
|
interface ${interfaceName} {
|
||||||
@@ -92,11 +92,13 @@ export async function gqlSchemaToTypes({
|
|||||||
outputDir,
|
outputDir,
|
||||||
filename,
|
filename,
|
||||||
joinerConfigs,
|
joinerConfigs,
|
||||||
|
interfaceName,
|
||||||
}: {
|
}: {
|
||||||
schema: GraphQLSchema
|
schema: GraphQLSchema
|
||||||
outputDir: string
|
outputDir: string
|
||||||
filename: string
|
filename: string
|
||||||
joinerConfigs: ModuleJoinerConfig[]
|
joinerConfigs: ModuleJoinerConfig[]
|
||||||
|
interfaceName: string
|
||||||
}) {
|
}) {
|
||||||
const config = {
|
const config = {
|
||||||
documents: [],
|
documents: [],
|
||||||
@@ -122,5 +124,11 @@ export async function gqlSchemaToTypes({
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
await generateTypes({ outputDir, filename, config, joinerConfigs })
|
await generateTypes({
|
||||||
|
outputDir,
|
||||||
|
filename,
|
||||||
|
config,
|
||||||
|
joinerConfigs,
|
||||||
|
interfaceName,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ async function start({ port, directory, types }) {
|
|||||||
await gqlSchemaToTypes({
|
await gqlSchemaToTypes({
|
||||||
outputDir: outputDirGeneratedTypes,
|
outputDir: outputDirGeneratedTypes,
|
||||||
filename: "remote-query-entry-points",
|
filename: "remote-query-entry-points",
|
||||||
|
interfaceName: "RemoteQueryEntryPoints",
|
||||||
schema: gqlSchema,
|
schema: gqlSchema,
|
||||||
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
|
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export async function gqlSchemaToTypes(schema: string) {
|
|||||||
await ModulesSdkGqlSchemaToTypes({
|
await ModulesSdkGqlSchemaToTypes({
|
||||||
schema: executableSchema,
|
schema: executableSchema,
|
||||||
filename,
|
filename,
|
||||||
|
interfaceName: "IndexServiceEntryPoints",
|
||||||
outputDir: dir,
|
outputDir: dir,
|
||||||
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
|
joinerConfigs: MedusaModule.getAllJoinerConfigs(),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user