From e062e17bf6e6bea11e5753f2960c970694308656 Mon Sep 17 00:00:00 2001 From: Ludwig Bedacht Date: Mon, 4 Aug 2025 14:52:31 +0200 Subject: [PATCH 1/2] fix: use input file location for gRPC subgraphs --- cli/src/commands/router/commands/compose.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/src/commands/router/commands/compose.ts b/cli/src/commands/router/commands/compose.ts index ec1baae3f2..0277a76891 100644 --- a/cli/src/commands/router/commands/compose.ts +++ b/cli/src/commands/router/commands/compose.ts @@ -281,20 +281,20 @@ function toSubgraphMetadata( } if ('grpc' in subgraphConfig) { - return toSubgraphMetadataGRPC(subgraphConfig); + return toSubgraphMetadataGRPC(inputFileLocation, subgraphConfig); } return toSubgraphMetadataStandard(inputFileLocation, index, subgraphConfig, subgraphs); } -async function toSubgraphMetadataGRPC(s: GRPCSubgraphConfig): Promise { - validateGRPCSubgraph(s); +async function toSubgraphMetadataGRPC(inputFileLocation: string, s: GRPCSubgraphConfig): Promise { + validateGRPCSubgraph(inputFileLocation,s); - const mappingFileContent = await readFile(s.grpc.mapping_file, 'utf8'); + const mappingFileContent = await readFile(resolve(inputFileLocation, s.grpc.mapping_file), 'utf8'); const mapping = GRPCMapping.fromJsonString(mappingFileContent); - const protoSchemaFileContent = await readFile(s.grpc.proto_file, 'utf8'); - const sdl = await readFile(s.grpc.schema_file, 'utf8'); + const protoSchemaFileContent = await readFile(resolve(inputFileLocation, s.grpc.proto_file), 'utf8'); + const sdl = await readFile(resolve(inputFileLocation, s.grpc.schema_file), 'utf8'); return { kind: SubgraphKind.GRPC, @@ -405,7 +405,7 @@ async function toSubgraphMetadataStandard( }; } -function validateGRPCSubgraph(s: GRPCSubgraphConfig) { +function validateGRPCSubgraph(inputFileLocation: string, s: GRPCSubgraphConfig) { if (!s.name) { program.error( pc.red(pc.bold(`The subgraph name is missing in the input file. Please check the name and try again.`)), @@ -436,7 +436,7 @@ function validateGRPCSubgraph(s: GRPCSubgraphConfig) { ); } - if (!existsSync(s.grpc.schema_file)) { + if (!existsSync(resolve(inputFileLocation, s.grpc.schema_file))) { program.error( pc.red( pc.bold( @@ -446,7 +446,7 @@ function validateGRPCSubgraph(s: GRPCSubgraphConfig) { ); } - if (!existsSync(s.grpc.proto_file)) { + if (!existsSync(resolve(inputFileLocation, s.grpc.proto_file))) { program.error( pc.red( pc.bold(`The proto file '${pc.bold(s.grpc.proto_file)}' does not exist. Please check the path and try again.`), @@ -454,7 +454,7 @@ function validateGRPCSubgraph(s: GRPCSubgraphConfig) { ); } - if (!existsSync(s.grpc.mapping_file)) { + if (!existsSync(resolve(inputFileLocation, s.grpc.mapping_file))) { program.error( pc.red( pc.bold( From 875bdf32fb4bd25dd46d94c02b36c4ce4384bc4d Mon Sep 17 00:00:00 2001 From: Ludwig Bedacht Date: Mon, 4 Aug 2025 14:56:04 +0200 Subject: [PATCH 2/2] fix: use input file location for plugin paths --- cli/src/commands/router/commands/compose.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cli/src/commands/router/commands/compose.ts b/cli/src/commands/router/commands/compose.ts index 0277a76891..0005724e22 100644 --- a/cli/src/commands/router/commands/compose.ts +++ b/cli/src/commands/router/commands/compose.ts @@ -277,7 +277,7 @@ function toSubgraphMetadata( subgraphs: SubgraphMetadata[], ): Promise { if ('plugin' in subgraphConfig) { - return toSubgraphMetadataPlugin(subgraphConfig, subgraphs); + return toSubgraphMetadataPlugin(inputFileLocation, subgraphConfig, subgraphs); } if ('grpc' in subgraphConfig) { @@ -288,7 +288,7 @@ function toSubgraphMetadata( } async function toSubgraphMetadataGRPC(inputFileLocation: string, s: GRPCSubgraphConfig): Promise { - validateGRPCSubgraph(inputFileLocation,s); + validateGRPCSubgraph(inputFileLocation, s); const mappingFileContent = await readFile(resolve(inputFileLocation, s.grpc.mapping_file), 'utf8'); const mapping = GRPCMapping.fromJsonString(mappingFileContent); @@ -307,6 +307,7 @@ async function toSubgraphMetadataGRPC(inputFileLocation: string, s: GRPCSubgraph } async function toSubgraphMetadataPlugin( + inputFileLocation: string, s: SubgraphPluginConfig, subgraphs: SubgraphMetadata[], ): Promise { @@ -319,14 +320,14 @@ async function toSubgraphMetadataPlugin( ); } - validateSubgraphPlugin(s); + validateSubgraphPlugin(inputFileLocation, s); // Check if a plugin with the same name already exists - const mappingFilePath = resolve(s.plugin.path, 'generated', 'mapping.json'); + const mappingFilePath = resolve(inputFileLocation, s.plugin.path, 'generated', 'mapping.json'); const mappingFile = await readFile(mappingFilePath, 'utf8'); - const schemaFilePath = resolve(s.plugin.path, 'src', 'schema.graphql'); + const schemaFilePath = resolve(inputFileLocation, s.plugin.path, 'src', 'schema.graphql'); const sdl = await readFile(schemaFilePath, 'utf8'); - const protoSchemaFilePath = resolve(s.plugin.path, 'generated', 'service.proto'); + const protoSchemaFilePath = resolve(inputFileLocation, s.plugin.path, 'generated', 'service.proto'); const protoSchema = await readFile(protoSchemaFilePath, 'utf8'); return { @@ -465,13 +466,13 @@ function validateGRPCSubgraph(inputFileLocation: string, s: GRPCSubgraphConfig) } } -function validateSubgraphPlugin(s: SubgraphPluginConfig) { +function validateSubgraphPlugin(inputFileLocation: string, s: SubgraphPluginConfig) { if (!s.plugin.path) { program.error( pc.red(pc.bold(`The plugin path is missing in the input file. Please check the path and try again.`)), ); } - if (!existsSync(s.plugin.path)) { + if (!existsSync(resolve(inputFileLocation, s.plugin.path))) { program.error( pc.red( pc.bold(`The plugin path '${pc.bold(s.plugin.path)}' does not exist. Please check the path and try again.`),