Skip to content

Commit 2a2cd52

Browse files
authored
fix: limit the number of entries shown in the table for schema checks on the cli (#2417)
1 parent b9a0c7b commit 2a2cd52

File tree

15 files changed

+10457
-9388
lines changed

15 files changed

+10457
-9388
lines changed

cli/src/commands/graph/federated-graph/commands/check.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Table from 'cli-table3';
2-
import { Command } from 'commander';
2+
import { Command, program } from 'commander';
33
import logSymbols from 'log-symbols';
44
import pc from 'picocolors';
55
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
66
import { joinLabel } from '@wundergraph/cosmo-shared';
77
import { BaseCommandOptions } from '../../../../core/types/types.js';
88
import { getBaseHeaders } from '../../../../core/config.js';
9+
import { limitMaxValue } from '../../../../constants.js';
910

1011
export default (opts: BaseCommandOptions) => {
1112
const command = new Command('check');
@@ -24,15 +25,25 @@ export default (opts: BaseCommandOptions) => {
2425
'--disable-resolvability-validation',
2526
'This flag will disable the validation for whether all nodes of the federated graph are resolvable. Do NOT use unless troubleshooting.',
2627
);
28+
command.option('-l, --limit [number]', 'The amount of entries shown in the schema checks output.', '50');
2729

2830
command.action(async (name, options) => {
2931
let success = false;
32+
33+
const limit = Number(options.limit);
34+
if (Number.isNaN(limit) || limit <= 0 || limit > limitMaxValue) {
35+
program.error(
36+
pc.red(`The limit must be a valid number between 1 and ${limitMaxValue}. Received: '${options.limit}'`),
37+
);
38+
}
39+
3040
const resp = await opts.client.platform.checkFederatedGraph(
3141
{
3242
disableResolvabilityValidation: options.disableResolvabilityValidation,
3343
labelMatchers: options.labelMatcher,
3444
name,
3545
namespace: options.namespace,
46+
limit,
3647
},
3748
{
3849
headers: getBaseHeaders(),
@@ -95,6 +106,9 @@ export default (opts: BaseCommandOptions) => {
95106
}
96107
console.log(compositionErrorsTable.toString());
97108
console.log(logSymbols.error + pc.red(' Schema check failed.'));
109+
if (resp.counts && resp.counts.compositionErrors > limit) {
110+
console.log(pc.red(`Some results were truncated due to exceeding the limit of ${limit} rows.`));
111+
}
98112
break;
99113
}
100114
default: {
@@ -112,6 +126,9 @@ export default (opts: BaseCommandOptions) => {
112126
compositionWarningsTable.push([compositionWarning.message]);
113127
}
114128
console.log(compositionWarningsTable.toString());
129+
if (resp.counts && resp.counts.compositionWarnings > limit) {
130+
console.log(pc.red(`Some results were truncated due to exceeding the limit of ${limit} rows.`));
131+
}
115132
}
116133

117134
if (!success) {

cli/src/commands/graph/monograph/commands/check.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getBaseHeaders } from '../../../../core/config.js';
88
import { BaseCommandOptions } from '../../../../core/types/types.js';
99
import { verifyGitHubIntegration } from '../../../../github.js';
1010
import { handleCheckResult } from '../../../../handle-check-result.js';
11+
import { limitMaxValue } from '../../../../constants.js';
1112

1213
export default (opts: BaseCommandOptions) => {
1314
const command = new Command('check');
@@ -19,6 +20,7 @@ export default (opts: BaseCommandOptions) => {
1920
'--skip-traffic-check',
2021
'This will skip checking for client traffic and any breaking change will fail the run.',
2122
);
23+
command.option('-l, --limit [number]', 'The amount of entries shown in the schema checks output.', '50');
2224

2325
command.action(async (name, options) => {
2426
const schemaFile = resolve(options.schema);
@@ -32,6 +34,13 @@ export default (opts: BaseCommandOptions) => {
3234
return;
3335
}
3436

37+
const limit = Number(options.limit);
38+
if (Number.isNaN(limit) || limit <= 0 || limit > limitMaxValue) {
39+
program.error(
40+
pc.red(`The limit must be a valid number between 1 and ${limitMaxValue}. Received: '${options.limit}'`),
41+
);
42+
}
43+
3544
const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client);
3645

3746
const graphResp = await opts.client.platform.getFederatedGraphByName(
@@ -63,13 +72,14 @@ export default (opts: BaseCommandOptions) => {
6372
gitInfo,
6473
delete: false,
6574
skipTrafficCheck: options.skipTrafficCheck,
75+
limit,
6676
},
6777
{
6878
headers: getBaseHeaders(),
6979
},
7080
);
7181

72-
const success = handleCheckResult(resp);
82+
const success = handleCheckResult(resp, limit);
7383

7484
if (!success && !ignoreErrorsDueToGitHubIntegration) {
7585
process.exitCode = 1;

cli/src/commands/subgraph/commands/check.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { config, getBaseHeaders } from '../../../core/config.js';
99
import { BaseCommandOptions } from '../../../core/types/types.js';
1010
import { verifyGitHubIntegration } from '../../../github.js';
1111
import { handleCheckResult } from '../../../handle-check-result.js';
12+
import { limitMaxValue } from '../../../constants.js';
1213

1314
export default (opts: BaseCommandOptions) => {
1415
const command = new Command('check');
@@ -31,6 +32,7 @@ export default (opts: BaseCommandOptions) => {
3132
'--disable-resolvability-validation',
3233
'This flag will disable the validation for whether all nodes of the federated graph are resolvable. Do NOT use unless troubleshooting.',
3334
);
35+
command.option('-l, --limit [number]', 'The amount of entries shown in the schema checks output.', '50');
3436

3537
command.action(async (name, options) => {
3638
let schemaFile;
@@ -50,6 +52,13 @@ export default (opts: BaseCommandOptions) => {
5052
}
5153
}
5254

55+
const limit = Number(options.limit);
56+
if (Number.isNaN(limit) || limit <= 0 || limit > limitMaxValue) {
57+
program.error(
58+
pc.red(`The limit must be a valid number between 1 and ${limitMaxValue}. Received: '${options.limit}'`),
59+
);
60+
}
61+
5362
const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client);
5463
let vcsContext: VCSContext | undefined;
5564

@@ -74,14 +83,15 @@ export default (opts: BaseCommandOptions) => {
7483
schema: new Uint8Array(schema),
7584
skipTrafficCheck: options.skipTrafficCheck,
7685
subgraphName: name,
86+
limit,
7787
vcsContext,
7888
},
7989
{
8090
headers: getBaseHeaders(),
8191
},
8292
);
8393

84-
const success = handleCheckResult(resp);
94+
const success = handleCheckResult(resp, limit);
8595

8696
if (!success && !ignoreErrorsDueToGitHubIntegration) {
8797
process.exitCode = 1;

cli/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ export const websocketSubprotocolDescription =
33
' The supported protocols are auto (default), graphql-ws, and graphql-transport-ws.' +
44
' Should be used only if the subscription protocol is ws.' +
55
' For more information see https://cosmo-docs.wundergraph.com/router/subscriptions/websocket-subprotocols.';
6+
7+
export const limitMaxValue = 10_000;

cli/src/handle-check-result.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import logSymbols from 'log-symbols';
66
import pc from 'picocolors';
77
import { config } from './core/config.js';
88

9-
export const handleCheckResult = (resp: CheckSubgraphSchemaResponse) => {
9+
export const handleCheckResult = (resp: CheckSubgraphSchemaResponse, rowLimit: number) => {
1010
const changesTable = new Table({
1111
head: [pc.bold(pc.white('CHANGE')), pc.bold(pc.white('TYPE')), pc.bold(pc.white('DESCRIPTION'))],
1212
wordWrap: true,
@@ -249,21 +249,44 @@ export const handleCheckResult = (resp: CheckSubgraphSchemaResponse) => {
249249
finalStatement += `\n${logSymbols.error} Subgraph extension check failed with message: ${resp.checkExtensionErrorMessage}`;
250250
}
251251

252+
let moreEntriesAvailableMessage = '';
253+
if (resp.counts) {
254+
const hasExceeded =
255+
resp.counts.lintWarnings + resp.counts.lintErrors > rowLimit ||
256+
resp.counts.breakingChanges + resp.counts.nonBreakingChanges > rowLimit ||
257+
resp.counts.graphPruneErrors + resp.counts.graphPruneWarnings > rowLimit ||
258+
resp.counts.compositionErrors > rowLimit ||
259+
resp.counts.compositionWarnings > rowLimit;
260+
261+
if (hasExceeded) {
262+
if (studioCheckDestination !== '') {
263+
moreEntriesAvailableMessage += `\n\n`;
264+
}
265+
moreEntriesAvailableMessage += pc.red(
266+
`Some results were truncated due to exceeding the limit of ${rowLimit} rows.`,
267+
);
268+
if (studioCheckDestination !== '') {
269+
moreEntriesAvailableMessage += ` They can be viewed in the studio dashboard.`;
270+
}
271+
}
272+
}
273+
252274
if (success) {
253275
console.log(
254276
'\n' +
255277
logSymbols.success +
256278
pc.green(` Schema check passed. ${finalStatement}`) +
257279
'\n\n' +
258280
studioCheckDestination +
281+
moreEntriesAvailableMessage +
259282
'\n',
260283
);
261284
} else {
262285
program.error(
263286
'\n' +
264287
logSymbols.error +
265288
pc.red(
266-
` Schema check failed. ${finalStatement}\nSee https://cosmo-docs.wundergraph.com/studio/schema-checks for more information on resolving operation check errors.\n${studioCheckDestination}\n`,
289+
` Schema check failed. ${finalStatement}\nSee https://cosmo-docs.wundergraph.com/studio/schema-checks for more information on resolving operation check errors.\n${studioCheckDestination}${moreEntriesAvailableMessage}\n`,
267290
) +
268291
'\n',
269292
);

0 commit comments

Comments
 (0)