Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controlplane/src/core/repositories/SubgraphRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
37 changes: 37 additions & 0 deletions controlplane/test/subgraph/publish-subgraph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading