Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 18 additions & 1 deletion cli/src/commands/graph/federated-graph/commands/check.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Table from 'cli-table3';
import { Command } from 'commander';
import { Command, program } from 'commander';
import logSymbols from 'log-symbols';
import pc from 'picocolors';
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import { joinLabel } from '@wundergraph/cosmo-shared';
import { BaseCommandOptions } from '../../../../core/types/types.js';
import { getBaseHeaders } from '../../../../core/config.js';
import { limitMaxValue } from '../../../../constants.js';

export default (opts: BaseCommandOptions) => {
const command = new Command('check');
Expand All @@ -24,15 +25,25 @@ 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 success = false;

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

const resp = await opts.client.platform.checkFederatedGraph(
{
disableResolvabilityValidation: options.disableResolvabilityValidation,
labelMatchers: options.labelMatcher,
name,
namespace: options.namespace,
limit,
},
{
headers: getBaseHeaders(),
Expand Down Expand Up @@ -95,6 +106,9 @@ export default (opts: BaseCommandOptions) => {
}
console.log(compositionErrorsTable.toString());
console.log(logSymbols.error + pc.red(' Schema check failed.'));
if (resp.counts && resp.counts.compositionErrors > limit) {
console.log(pc.red(`Some results were truncated due to exceeding the limit of ${limit} rows.`));
}
break;
}
default: {
Expand All @@ -112,6 +126,9 @@ export default (opts: BaseCommandOptions) => {
compositionWarningsTable.push([compositionWarning.message]);
}
console.log(compositionWarningsTable.toString());
if (resp.counts && resp.counts.compositionWarnings > limit) {
console.log(pc.red(`Some results were truncated due to exceeding the limit of ${limit} rows.`));
}
}

if (!success) {
Expand Down
12 changes: 11 additions & 1 deletion cli/src/commands/graph/monograph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getBaseHeaders } from '../../../../core/config.js';
import { BaseCommandOptions } from '../../../../core/types/types.js';
import { verifyGitHubIntegration } from '../../../../github.js';
import { handleCheckResult } from '../../../../handle-check-result.js';
import { limitMaxValue } from '../../../../constants.js';

export default (opts: BaseCommandOptions) => {
const command = new Command('check');
Expand All @@ -19,6 +20,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 +34,13 @@ export default (opts: BaseCommandOptions) => {
return;
}

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

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

const graphResp = await opts.client.platform.getFederatedGraphByName(
Expand Down Expand Up @@ -63,13 +72,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
12 changes: 11 additions & 1 deletion cli/src/commands/subgraph/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { config, getBaseHeaders } from '../../../core/config.js';
import { BaseCommandOptions } from '../../../core/types/types.js';
import { verifyGitHubIntegration } from '../../../github.js';
import { handleCheckResult } from '../../../handle-check-result.js';
import { limitMaxValue } from '../../../constants.js';

export default (opts: BaseCommandOptions) => {
const command = new Command('check');
Expand All @@ -31,6 +32,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 +52,13 @@ export default (opts: BaseCommandOptions) => {
}
}

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

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

Expand All @@ -74,14 +83,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
2 changes: 2 additions & 0 deletions cli/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ export const websocketSubprotocolDescription =
' The supported protocols are auto (default), graphql-ws, and graphql-transport-ws.' +
' Should be used only if the subscription protocol is ws.' +
' For more information see https://cosmo-docs.wundergraph.com/router/subscriptions/websocket-subprotocols.';

export const limitMaxValue = 10_000;
27 changes: 25 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 logSymbols from 'log-symbols';
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,44 @@ export const handleCheckResult = (resp: CheckSubgraphSchemaResponse) => {
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) {
if (studioCheckDestination !== '') {
moreEntriesAvailableMessage += `\n\n`;
}
moreEntriesAvailableMessage += pc.red(
`Some results were truncated due to exceeding the limit of ${rowLimit} rows.`,
Comment thread
JivusAyrus marked this conversation as resolved.
);
if (studioCheckDestination !== '') {
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