Skip to content

Commit 0ea3e7d

Browse files
authored
feat: issue subgraph check extensions for proposals (#2615)
1 parent 251f1ef commit 0ea3e7d

File tree

4 files changed

+324
-86
lines changed

4 files changed

+324
-86
lines changed

controlplane/src/core/repositories/SchemaCheckRepository.ts

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
CompositionWarning,
77
GraphPruningIssue,
88
LintIssue,
9+
LintSeverity,
910
ProposalSubgraph,
1011
SchemaChange,
1112
VCSContext,
@@ -744,8 +745,13 @@ export class SchemaCheckRepository {
744745
const compositionErrors: PlainMessage<CompositionError>[] = [];
745746
const compositionWarnings: PlainMessage<CompositionWarning>[] = [];
746747

748+
type ExtendedCheckSubgraph = CheckSubgraph & {
749+
lintIssues: SchemaLintIssues;
750+
pruneIssues: SchemaGraphPruningIssues;
751+
};
752+
747753
const federatedGraphs: FederatedGraphDTO[] = [];
748-
const checkSubgraphs: Map<string, CheckSubgraph> = new Map();
754+
const checkSubgraphs: Map<string, ExtendedCheckSubgraph> = new Map();
749755
const fedGraphIdToCheckFedGraphId = new Map<string, string>();
750756

751757
const changeRetention = await orgRepo.getFeature({
@@ -943,6 +949,8 @@ export class SchemaCheckRepository {
943949
checkSubgraphId: schemaCheckSubgraphId,
944950
routerCompatibilityVersion,
945951
labels: s.isNew ? s.labels : undefined,
952+
lintIssues: { warnings: [], errors: [] },
953+
pruneIssues: { warnings: [], errors: [] },
946954
});
947955
}
948956

@@ -1029,13 +1037,6 @@ export class SchemaCheckRepository {
10291037
storedBreakingChanges,
10301038
);
10311039

1032-
checkSubgraphs.set(subgraphName, {
1033-
...checkSubgraph,
1034-
inspectorChanges,
1035-
storedBreakingChanges,
1036-
checkSubgraphId: schemaCheckSubgraphId,
1037-
});
1038-
10391040
const lintIssues: SchemaLintIssues = await schemaLintRepo.performSchemaLintCheck({
10401041
schemaCheckID,
10411042
newSchemaSDL,
@@ -1119,6 +1120,15 @@ export class SchemaCheckRepository {
11191120
}),
11201121
),
11211122
);
1123+
1124+
checkSubgraphs.set(subgraphName, {
1125+
...checkSubgraph,
1126+
inspectorChanges,
1127+
storedBreakingChanges,
1128+
checkSubgraphId: schemaCheckSubgraphId,
1129+
lintIssues,
1130+
pruneIssues: graphPruningIssues,
1131+
});
11221132
}
11231133

11241134
const { composedGraphs } = await composer.composeWithProposedSchemas({
@@ -1322,13 +1332,63 @@ export class SchemaCheckRepository {
13221332
}
13231333
}
13241334

1335+
// Execute the subgraph check extension webhook
1336+
const sceResult = await webhookService.sendSubgraphCheckExtension({
1337+
actorId,
1338+
schemaCheckID,
1339+
blobStorage,
1340+
admissionConfig,
1341+
organization: { id: organizationId, slug: organizationSlug },
1342+
namespace,
1343+
vcsContext,
1344+
subgraphs: [...checkSubgraphs.entries()].map(([subgraphName, { subgraph, ...check }]) => ({
1345+
id: subgraph?.id ?? '',
1346+
name: subgraphName,
1347+
labels: subgraph?.labels ?? check.labels ?? [],
1348+
schemaSDL: subgraph?.schemaSDL ?? '',
1349+
schemaChanges: check.schemaChanges,
1350+
lintIssues: check.lintIssues,
1351+
pruneIssues: check.pruneIssues,
1352+
newSchemaSDL: check.newSchemaSDL,
1353+
isDeleted: check.newSchemaSDL === '',
1354+
})),
1355+
affectedGraphs: federatedGraphs,
1356+
composedGraphs,
1357+
inspectedOperations,
1358+
});
1359+
1360+
if (sceResult?.lintIssuesBySubgraph) {
1361+
for (const [subgraphName, check] of checkSubgraphs.entries()) {
1362+
const sceLintIssues = sceResult.lintIssuesBySubgraph.get(subgraphName);
1363+
if (sceLintIssues && sceLintIssues.length > 0) {
1364+
const sceLintWarnings = sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn);
1365+
const sceLintErrors = sceLintIssues.filter((issue) => issue.severity === LintSeverity.error);
1366+
1367+
check.lintIssues.warnings.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn));
1368+
check.lintIssues.errors.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.error));
1369+
1370+
lintWarnings.push(...sceLintWarnings.map((issue) => new LintIssue({ ...issue, subgraphName })));
1371+
lintErrors.push(...sceLintErrors.map((issue) => new LintIssue({ ...issue, subgraphName })));
1372+
1373+
// Then, we need to add the overwritten lint issues
1374+
await schemaLintRepo.addSchemaCheckLintIssues({
1375+
schemaCheckId: schemaCheckID,
1376+
lintIssues: sceLintIssues,
1377+
schemaCheckSubgraphId: check.checkSubgraphId,
1378+
});
1379+
}
1380+
}
1381+
}
1382+
13251383
// Update the overall schema check with the results
13261384
await this.update({
13271385
schemaCheckID,
13281386
hasClientTraffic,
13291387
hasBreakingChanges: breakingChanges.length > 0 || composedSchemaBreakingChanges.length > 0,
13301388
hasLintErrors: lintErrors.length > 0,
13311389
hasGraphPruningErrors: graphPruneErrors.length > 0,
1390+
checkExtensionDeliveryId: sceResult?.deliveryInfo?.id,
1391+
checkExtensionErrorMessage: sceResult?.deliveryInfo?.errorMessage ?? undefined,
13321392
});
13331393

13341394
let isLinkedTrafficCheckFailed = false;

controlplane/src/core/repositories/SubgraphRepository.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,32 +2299,38 @@ export class SubgraphRepository {
22992299
organization: { id: this.organizationId, slug: organizationSlug },
23002300
namespace,
23012301
vcsContext,
2302-
subgraph,
2303-
newSchemaSDL,
2304-
isDeleted,
2302+
subgraphs: [
2303+
{
2304+
id: subgraph?.id ?? '',
2305+
name: subgraph?.name ?? subgraphName,
2306+
labels: subgraph?.labels ?? labels ?? [],
2307+
schemaSDL: subgraph?.schemaSDL ?? '',
2308+
schemaChanges,
2309+
lintIssues,
2310+
pruneIssues: graphPruningIssues,
2311+
newSchemaSDL,
2312+
isDeleted,
2313+
},
2314+
],
23052315
affectedGraphs: federatedGraphs,
23062316
composedGraphs,
2307-
schemaChanges,
2308-
lintIssues,
2309-
pruneIssues: graphPruningIssues,
23102317
inspectedOperations,
23112318
});
23122319

2313-
if (sceResult && sceResult.additionalLintIssues.length > 0) {
2314-
const additionalLintIssues: SchemaLintIssues = {
2315-
warnings: sceResult.additionalLintIssues.filter((issue) => issue.severity === LintSeverity.warn),
2316-
errors: sceResult.additionalLintIssues.filter((issue) => issue.severity === LintSeverity.error),
2317-
};
2320+
if (sceResult?.lintIssuesBySubgraph) {
2321+
const sceLintIssues = sceResult.lintIssuesBySubgraph.get(subgraph?.name ?? subgraphName);
23182322

2319-
lintIssues.warnings.push(...additionalLintIssues.warnings);
2320-
lintIssues.errors.push(...additionalLintIssues.errors);
2323+
if (sceLintIssues && sceLintIssues.length > 0) {
2324+
lintIssues.warnings.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn));
2325+
lintIssues.errors.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.error));
23212326

2322-
// Then, we need to add the overwritten lint issues
2323-
await schemaLintRepo.addSchemaCheckLintIssues({
2324-
schemaCheckId: schemaCheckID,
2325-
lintIssues: sceResult.additionalLintIssues,
2326-
schemaCheckSubgraphId,
2327-
});
2327+
// Then, we need to add the overwritten lint issues
2328+
await schemaLintRepo.addSchemaCheckLintIssues({
2329+
schemaCheckId: schemaCheckID,
2330+
lintIssues: sceLintIssues,
2331+
schemaCheckSubgraphId,
2332+
});
2333+
}
23282334
}
23292335

23302336
// Update the overall schema check with the results

0 commit comments

Comments
 (0)