Skip to content
76 changes: 68 additions & 8 deletions controlplane/src/core/repositories/SchemaCheckRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CompositionWarning,
GraphPruningIssue,
LintIssue,
LintSeverity,
ProposalSubgraph,
SchemaChange,
VCSContext,
Expand Down Expand Up @@ -744,8 +745,13 @@ export class SchemaCheckRepository {
const compositionErrors: PlainMessage<CompositionError>[] = [];
const compositionWarnings: PlainMessage<CompositionWarning>[] = [];

type ExtendedCheckSubgraph = CheckSubgraph & {
lintIssues: SchemaLintIssues;
pruneIssues: SchemaGraphPruningIssues;
};

const federatedGraphs: FederatedGraphDTO[] = [];
const checkSubgraphs: Map<string, CheckSubgraph> = new Map();
const checkSubgraphs: Map<string, ExtendedCheckSubgraph> = new Map();
const fedGraphIdToCheckFedGraphId = new Map<string, string>();

const changeRetention = await orgRepo.getFeature({
Expand Down Expand Up @@ -943,6 +949,8 @@ export class SchemaCheckRepository {
checkSubgraphId: schemaCheckSubgraphId,
routerCompatibilityVersion,
labels: s.isNew ? s.labels : undefined,
lintIssues: { warnings: [], errors: [] },
pruneIssues: { warnings: [], errors: [] },
});
}

Expand Down Expand Up @@ -1029,13 +1037,6 @@ export class SchemaCheckRepository {
storedBreakingChanges,
);

checkSubgraphs.set(subgraphName, {
...checkSubgraph,
inspectorChanges,
storedBreakingChanges,
checkSubgraphId: schemaCheckSubgraphId,
});

const lintIssues: SchemaLintIssues = await schemaLintRepo.performSchemaLintCheck({
schemaCheckID,
newSchemaSDL,
Expand Down Expand Up @@ -1119,6 +1120,15 @@ export class SchemaCheckRepository {
}),
),
);

checkSubgraphs.set(subgraphName, {
...checkSubgraph,
inspectorChanges,
storedBreakingChanges,
checkSubgraphId: schemaCheckSubgraphId,
lintIssues,
pruneIssues: graphPruningIssues,
});
}

const { composedGraphs } = await composer.composeWithProposedSchemas({
Expand Down Expand Up @@ -1322,13 +1332,63 @@ export class SchemaCheckRepository {
}
}

// Execute the subgraph check extension webhook
const sceResult = await webhookService.sendSubgraphCheckExtension({
actorId,
schemaCheckID,
blobStorage,
admissionConfig,
organization: { id: organizationId, slug: organizationSlug },
namespace,
vcsContext,
subgraphs: [...checkSubgraphs.entries()].map(([subgraphName, { subgraph, ...check }]) => ({
id: subgraph?.id ?? '',
name: subgraphName,
labels: subgraph?.labels ?? check.labels ?? [],
schemaSDL: subgraph?.schemaSDL ?? '',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
schemaChanges: check.schemaChanges,
lintIssues: check.lintIssues,
pruneIssues: check.pruneIssues,
newSchemaSDL: check.newSchemaSDL,
isDeleted: check.newSchemaSDL === '',
})),
affectedGraphs: federatedGraphs,
composedGraphs,
inspectedOperations,
});
Comment thread
wilsonrivera marked this conversation as resolved.

if (sceResult?.lintIssuesBySubgraph) {
for (const [subgraphName, check] of checkSubgraphs.entries()) {
const sceLintIssues = sceResult.lintIssuesBySubgraph.get(subgraphName);
if (sceLintIssues && sceLintIssues.length > 0) {
const sceLintWarnings = sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn);
const sceLintErrors = sceLintIssues.filter((issue) => issue.severity === LintSeverity.error);

check.lintIssues.warnings.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn));
check.lintIssues.errors.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.error));

lintWarnings.push(...sceLintWarnings.map((issue) => new LintIssue({ ...issue, subgraphName })));
lintErrors.push(...sceLintErrors.map((issue) => new LintIssue({ ...issue, subgraphName })));

// Then, we need to add the overwritten lint issues
await schemaLintRepo.addSchemaCheckLintIssues({
schemaCheckId: schemaCheckID,
lintIssues: sceLintIssues,
schemaCheckSubgraphId: check.checkSubgraphId,
});
}
}
}

// Update the overall schema check with the results
await this.update({
schemaCheckID,
hasClientTraffic,
hasBreakingChanges: breakingChanges.length > 0 || composedSchemaBreakingChanges.length > 0,
hasLintErrors: lintErrors.length > 0,
hasGraphPruningErrors: graphPruneErrors.length > 0,
checkExtensionDeliveryId: sceResult?.deliveryInfo?.id,
checkExtensionErrorMessage: sceResult?.deliveryInfo?.errorMessage ?? undefined,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});

let isLinkedTrafficCheckFailed = false;
Expand Down
44 changes: 25 additions & 19 deletions controlplane/src/core/repositories/SubgraphRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2299,32 +2299,38 @@ export class SubgraphRepository {
organization: { id: this.organizationId, slug: organizationSlug },
namespace,
vcsContext,
subgraph,
newSchemaSDL,
isDeleted,
subgraphs: [
{
id: subgraph?.id ?? '',
name: subgraph?.name ?? subgraphName,
labels: subgraph?.labels ?? labels ?? [],
schemaSDL: subgraph?.schemaSDL ?? '',
schemaChanges,
lintIssues,
pruneIssues: graphPruningIssues,
newSchemaSDL,
isDeleted,
},
],
affectedGraphs: federatedGraphs,
composedGraphs,
schemaChanges,
lintIssues,
pruneIssues: graphPruningIssues,
inspectedOperations,
});

if (sceResult && sceResult.additionalLintIssues.length > 0) {
const additionalLintIssues: SchemaLintIssues = {
warnings: sceResult.additionalLintIssues.filter((issue) => issue.severity === LintSeverity.warn),
errors: sceResult.additionalLintIssues.filter((issue) => issue.severity === LintSeverity.error),
};
if (sceResult?.lintIssuesBySubgraph) {
const sceLintIssues = sceResult.lintIssuesBySubgraph.get(subgraph?.name ?? subgraphName);
Comment thread
wilsonrivera marked this conversation as resolved.

lintIssues.warnings.push(...additionalLintIssues.warnings);
lintIssues.errors.push(...additionalLintIssues.errors);
if (sceLintIssues && sceLintIssues.length > 0) {
lintIssues.warnings.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.warn));
lintIssues.errors.push(...sceLintIssues.filter((issue) => issue.severity === LintSeverity.error));

// Then, we need to add the overwritten lint issues
await schemaLintRepo.addSchemaCheckLintIssues({
schemaCheckId: schemaCheckID,
lintIssues: sceResult.additionalLintIssues,
schemaCheckSubgraphId,
});
// Then, we need to add the overwritten lint issues
await schemaLintRepo.addSchemaCheckLintIssues({
schemaCheckId: schemaCheckID,
lintIssues: sceLintIssues,
schemaCheckSubgraphId,
});
}
}

// Update the overall schema check with the results
Expand Down
Loading
Loading