Skip to content

Commit 8c49615

Browse files
authored
add progress log to cli app:create command (#7046)
1 parent 28ccd57 commit 8c49615

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

.changeset/bitter-goats-bow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-hive/cli': patch
3+
---
4+
5+
Add progress log to app:create

packages/libraries/cli/src/commands/app/create.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ export default class AppCreate extends Command<typeof AppCreate> {
119119
return;
120120
}
121121

122+
const totalDocuments = Object.keys(validationResult.data).length;
123+
124+
this.log(
125+
`App deployment "${flags['name']}@${flags['version']}" is created pending document upload. Uploading documents...`,
126+
);
127+
122128
let buffer: Array<{ hash: string; body: string }> = [];
123129

130+
let counter = 0;
131+
124132
const flush = async (force = false) => {
125-
if (buffer.length >= 100 || force) {
133+
if (buffer.length >= 100 || (force && buffer.length > 0)) {
126134
const result = await this.registryApi(endpoint, accessToken).request({
127135
operation: AddDocumentsToAppDeploymentMutation,
128136
variables: {
@@ -159,15 +167,20 @@ export default class AppCreate extends Command<typeof AppCreate> {
159167
throw new APIError(result.addDocumentsToAppDeployment.error.message);
160168
}
161169
buffer = [];
170+
171+
// don't bother showing 100% since there's another log line when it's done. And for deployments with just a few docs, showing this progress is unnecessary.
172+
if (counter !== totalDocuments) {
173+
this.log(
174+
`${counter} / ${totalDocuments} (${Math.round((100.0 * counter) / totalDocuments)}%) documents uploaded...`,
175+
);
176+
}
162177
}
163178
};
164179

165-
let counter = 0;
166-
167180
for (const [hash, body] of Object.entries(validationResult.data)) {
168181
buffer.push({ hash, body });
169-
await flush();
170182
counter++;
183+
await flush();
171184
}
172185

173186
await flush(true);

0 commit comments

Comments
 (0)