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
11 changes: 10 additions & 1 deletion cli/src/commands/graph/monograph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { BaseCommandOptions } from '../../../../core/types/types.js';
import { verifyGitHubIntegration } from '../../../../github.js';
import { handleCheckResult } from '../../../../handle-check-result.js';

const maxLimit = 10_000;

export default (opts: BaseCommandOptions) => {
const command = new Command('check');
command.description('Checks for breaking changes and errors.');
Expand All @@ -19,6 +21,7 @@ export default (opts: BaseCommandOptions) => {
'--skip-traffic-check',
'This will skip checking for client traffic and any breaking change will fail the run.',
);
command.option('-l, --limit [number]', 'The amount of entries shown in the schema checks output.', '50');

command.action(async (name, options) => {
const schemaFile = resolve(options.schema);
Expand All @@ -32,6 +35,11 @@ export default (opts: BaseCommandOptions) => {
return;
}

const limit = Number(options.limit);
if (Number.isNaN(limit) || limit <= 0 || limit > maxLimit) {
program.error(pc.red(`The limit must be a valid number between 1 and ${maxLimit}. Received: '${options.limit}'`));
}

const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client);

const graphResp = await opts.client.platform.getFederatedGraphByName(
Expand Down Expand Up @@ -63,13 +71,14 @@ export default (opts: BaseCommandOptions) => {
gitInfo,
delete: false,
skipTrafficCheck: options.skipTrafficCheck,
limit,
},
{
headers: getBaseHeaders(),
},
);

const success = handleCheckResult(resp);
const success = handleCheckResult(resp, limit);

if (!success && !ignoreErrorsDueToGitHubIntegration) {
process.exitCode = 1;
Expand Down
11 changes: 10 additions & 1 deletion cli/src/commands/subgraph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { BaseCommandOptions } from '../../../core/types/types.js';
import { verifyGitHubIntegration } from '../../../github.js';
import { handleCheckResult } from '../../../handle-check-result.js';

const maxLimit = 10_000;

export default (opts: BaseCommandOptions) => {
const command = new Command('check');
command.description('Checks for breaking changes and composition errors with all connected federated graphs.');
Expand All @@ -31,6 +33,7 @@ export default (opts: BaseCommandOptions) => {
'--disable-resolvability-validation',
'This flag will disable the validation for whether all nodes of the federated graph are resolvable. Do NOT use unless troubleshooting.',
);
command.option('-l, --limit [number]', 'The amount of entries shown in the schema checks output.', '50');

command.action(async (name, options) => {
let schemaFile;
Expand All @@ -50,6 +53,11 @@ export default (opts: BaseCommandOptions) => {
}
}

const limit = Number(options.limit);
if (Number.isNaN(limit) || limit <= 0 || limit > maxLimit) {
program.error(pc.red(`The limit must be a valid number between 1 and ${maxLimit}. Received: '${options.limit}'`));
}

const { gitInfo, ignoreErrorsDueToGitHubIntegration } = await verifyGitHubIntegration(opts.client);
let vcsContext: VCSContext | undefined;

Expand All @@ -74,14 +82,15 @@ export default (opts: BaseCommandOptions) => {
schema: new Uint8Array(schema),
skipTrafficCheck: options.skipTrafficCheck,
subgraphName: name,
limit,
vcsContext,
},
{
headers: getBaseHeaders(),
},
);

const success = handleCheckResult(resp);
const success = handleCheckResult(resp, limit);

if (!success && !ignoreErrorsDueToGitHubIntegration) {
process.exitCode = 1;
Expand Down
23 changes: 21 additions & 2 deletions cli/src/handle-check-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pc from 'picocolors';
import { config } from './core/config.js';

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

let moreEntriesAvailableMessage = '';
if (resp.counts) {
const hasExceeded =
resp.counts.lintWarnings + resp.counts.lintErrors > rowLimit ||
resp.counts.breakingChanges + resp.counts.nonBreakingChanges > rowLimit ||
resp.counts.graphPruneErrors + resp.counts.graphPruneWarnings > rowLimit ||
resp.counts.compositionErrors > rowLimit ||
resp.counts.compositionWarnings > rowLimit;

if (hasExceeded) {
moreEntriesAvailableMessage = `\n\nSome results were truncated due to exceeding the limit of ${rowLimit} rows.`
// If the studio link is present
if (studioCheckDestination != '') {

Check failure on line 264 in cli/src/handle-check-result.ts

View workflow job for this annotation

GitHub Actions / build_test_node_matrix (20.x)

Expected '!==' and instead saw '!='

Check failure on line 264 in cli/src/handle-check-result.ts

View workflow job for this annotation

GitHub Actions / build_test_node_matrix (22.x)

Expected '!==' and instead saw '!='
moreEntriesAvailableMessage += ` They can be viewed in the studio dashboard.`;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

if (success) {
console.log(
'\n' +
logSymbols.success +
pc.green(` Schema check passed. ${finalStatement}`) +
'\n\n' +
studioCheckDestination +
moreEntriesAvailableMessage +
'\n',
);
} else {
program.error(
'\n' +
logSymbols.error +
pc.red(
` Schema check failed. ${finalStatement}\nSee https://cosmo-docs.wundergraph.com/studio/schema-checks for more information on resolving operation check errors.\n${studioCheckDestination}\n`,
` 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`,
) +
'\n',
);
Expand Down
Loading
Loading