Skip to content

Commit

Permalink
feat: list only contracts for monographs (wundergraph#1154)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin authored Sep 9, 2024
1 parent ecbb399 commit 06fd0e9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands/graph/federated-graph/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type OutputFile = {
routingURL: string;
isComposable: boolean;
lastUpdatedAt: string;
contract: {
contract?: {
sourceFederatedGraphId: string;
excludeTags: string[];
};
Expand Down Expand Up @@ -77,7 +77,7 @@ export default (opts: BaseCommandOptions) => {
isComposable: g.isComposable,
lastUpdatedAt: g.lastUpdatedAt,
contract: g.contract,
}) as OutputFile[number],
}) satisfies OutputFile[number],
);
await writeFile(resolve(options.out), JSON.stringify(output));
process.exit(0);
Expand Down
43 changes: 34 additions & 9 deletions cli/src/commands/graph/monograph/commands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import pc from 'picocolors';
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import Table from 'cli-table3';
import { resolve } from 'pathe';
import logSymbols from 'log-symbols';
import { BaseCommandOptions } from '../../../../core/types/types.js';
import { getBaseHeaders } from '../../../../core/config.js';
import program from '../../../index.js';
Expand All @@ -13,6 +14,10 @@ type OutputFile = {
namespace: string;
routingURL: string;
lastUpdatedAt: string;
contract?: {
sourceFederatedGraphId: string;
excludeTags: string[];
};
}[];

export default (opts: BaseCommandOptions) => {
Expand All @@ -22,6 +27,7 @@ export default (opts: BaseCommandOptions) => {
command.option('-o, --out [string]', 'Destination file for the json output.');
command.option('-r, --raw', 'Prints to the console in json format instead of table');
command.option('-j, --json', 'Prints to the console in json format instead of table');
command.option('--only-contracts', 'Filter to show contracts only');
command.action(async (options) => {
const resp = await opts.client.platform.getFederatedGraphs(
{
Expand All @@ -42,20 +48,32 @@ export default (opts: BaseCommandOptions) => {
program.error(pc.red('Could not fetch the monographs.'));
}

if (resp.graphs.length === 0) {
console.log('No monographs found');
const filteredGraphs = [];
if (options.onlyContracts) {
filteredGraphs.push(...resp.graphs.filter((g) => !!g.contract));
} else {
filteredGraphs.push(...resp.graphs);
}

if (filteredGraphs.length === 0) {
if (options.onlyContracts) {
console.log('No contracts found');
} else {
console.log('No monographs found');
}
process.exit(0);
}

if (options.out) {
const output = resp.graphs.map(
const output = filteredGraphs.map(
(g) =>
({
name: g.name,
namespace: g.namespace,
routingURL: g.routingURL,
lastUpdatedAt: g.lastUpdatedAt,
}) as OutputFile[number],
contract: g.contract,
}) satisfies OutputFile[number],
);
await writeFile(resolve(options.out), JSON.stringify(output));
process.exit(0);
Expand All @@ -66,7 +84,7 @@ export default (opts: BaseCommandOptions) => {
}

if (options.raw || options.json) {
console.log(resp.graphs);
console.log(filteredGraphs);
process.exit(0);
}

Expand All @@ -76,14 +94,21 @@ export default (opts: BaseCommandOptions) => {
pc.bold(pc.white('NAMESPACE')),
pc.bold(pc.white('ROUTING_URL')),
pc.bold(pc.white('UPDATED_AT')),
pc.bold(pc.white('IS_CONTRACT')),
],
colAligns: ['left', 'left', 'left', 'left'],
colWidths: [25, 25, 70, 30],
colAligns: ['left', 'left', 'left', 'left', 'center'],
colWidths: [25, 25, 70, 30, 15],
wordWrap: true,
});

for (const graph of resp.graphs) {
graphsTable.push([graph.name, graph.namespace, graph.routingURL, graph.lastUpdatedAt]);
for (const graph of filteredGraphs) {
graphsTable.push([
graph.name,
graph.namespace,
graph.routingURL,
graph.lastUpdatedAt,
graph.contract ? logSymbols.success : logSymbols.error,
]);
}
console.log(graphsTable.toString());
});
Expand Down

0 comments on commit 06fd0e9

Please sign in to comment.