diff --git a/controlplane/src/core/repositories/SubgraphRepository.ts b/controlplane/src/core/repositories/SubgraphRepository.ts index 3b08f5e598..15bd99afa9 100644 --- a/controlplane/src/core/repositories/SubgraphRepository.ts +++ b/controlplane/src/core/repositories/SubgraphRepository.ts @@ -421,11 +421,14 @@ export class SubgraphRepository { } // TODO: avoid downloading the schema use hash instead - if (data.schemaSDL && (subgraph.type === 'grpc_plugin' || data.schemaSDL !== subgraph.schemaSDL.trimEnd())) { + if ( + data.schemaSDL && + (subgraph.type === 'grpc_plugin' || data.schemaSDL.trimEnd() !== subgraph.schemaSDL.trimEnd()) + ) { subgraphChanged = true; const updatedSubgraph = await subgraphRepo.addSchemaVersion({ targetId: subgraph.targetId, - subgraphSchema: data.schemaSDL, + subgraphSchema: data.schemaSDL.trimEnd(), isV2Graph: data.isV2Graph, proto: data.proto, }); diff --git a/controlplane/test/subgraph/publish-subgraph.test.ts b/controlplane/test/subgraph/publish-subgraph.test.ts index ad24f88ac1..166c64763a 100644 --- a/controlplane/test/subgraph/publish-subgraph.test.ts +++ b/controlplane/test/subgraph/publish-subgraph.test.ts @@ -81,6 +81,43 @@ describe('Publish subgraph tests', () => { expect(publishFederatedSubgraphResp.response?.code).toBe(EnumStatusCode.OK); }); + test('that newlines do not cause extra compositions', async () => { + const { client, server } = await SetupTest({ dbname }); + onTestFinished(() => server.close()); + + const subgraphName = genID('subgraph'); + + await createSubgraph(client, subgraphName, 'http://localhost:4001'); + let publishFederatedSubgraphResp = await client.publishFederatedSubgraph({ + name: subgraphName, + namespace: 'default', + schema: subgraphSDL, + }); + + expect(publishFederatedSubgraphResp.response?.code).toBe(EnumStatusCode.OK); + expect(publishFederatedSubgraphResp.hasChanged).toBe(true); + + // Multiple newlines should not cause extra composition + publishFederatedSubgraphResp = await client.publishFederatedSubgraph({ + name: subgraphName, + namespace: 'default', + schema: subgraphSDL + '\r\n\r\n\r\n\n\n\n', + }); + + expect(publishFederatedSubgraphResp.response?.code).toBe(EnumStatusCode.OK); + expect(publishFederatedSubgraphResp.hasChanged).toBe(false); + + // Trimmed should not cause extra composition + publishFederatedSubgraphResp = await client.publishFederatedSubgraph({ + name: subgraphName, + namespace: 'default', + schema: subgraphSDL.trimEnd(), + }); + + expect(publishFederatedSubgraphResp.response?.code).toBe(EnumStatusCode.OK); + expect(publishFederatedSubgraphResp.hasChanged).toBe(false); + }); + test.each(['organization-admin', 'organization-developer', 'subgraph-admin', 'subgraph-publisher'])( '%s should be able to publish to existing regular subgraph', async (role) => { diff --git a/controlplane/test/test-data/feature-flags/products-standalone-feature.graphql b/controlplane/test/test-data/feature-flags/products-standalone-feature.graphql index b8d0611902..e9bc25d2df 100644 --- a/controlplane/test/test-data/feature-flags/products-standalone-feature.graphql +++ b/controlplane/test/test-data/feature-flags/products-standalone-feature.graphql @@ -3,7 +3,6 @@ type Product @key(fields: "upc sku") { sku: String! details: String! isPremium: Boolean! @tag(name: "exclude") - newField: String! } type Query {