@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
135 lines • 5.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@oclif/core");
const base_command_1 = tslib_1.__importDefault(require("../../base-command"));
const gql_1 = require("../../gql");
const config_1 = require("../../helpers/config");
const errors_1 = require("../../helpers/errors");
const TargetInput = tslib_1.__importStar(require("../../helpers/target-input"));
class AppRetire extends base_command_1.default {
async run() {
var _a;
const { flags } = await this.parse(AppRetire);
let endpoint, accessToken;
try {
endpoint = this.ensure({
key: 'registry.endpoint',
args: flags,
defaultValue: config_1.graphqlEndpoint,
env: 'HIVE_REGISTRY',
description: AppRetire.flags['registry.endpoint'].description,
});
}
catch (e) {
this.logDebug(e);
throw new errors_1.MissingEndpointError();
}
try {
accessToken = this.ensure({
key: 'registry.accessToken',
args: flags,
env: 'HIVE_TOKEN',
description: AppRetire.flags['registry.accessToken'].description,
});
}
catch (e) {
this.logDebug(e);
throw new errors_1.MissingRegistryTokenError();
}
let target = null;
if (flags.target) {
const result = TargetInput.parse(flags.target);
if (result.type === 'error') {
throw new errors_1.InvalidTargetError();
}
target = result.data;
}
const result = await this.registryApi(endpoint, accessToken).request({
operation: RetireAppDeploymentMutation,
variables: {
input: {
target,
appName: flags['name'],
appVersion: flags['version'],
force: flags['force'] || undefined,
},
},
});
if (result.retireAppDeployment.error) {
const error = result.retireAppDeployment.error;
if (error.protectionDetails) {
const details = error.protectionDetails;
this.log('\nRetirement blocked by protection rules:');
this.log(` Last used: ${(_a = details.lastUsed) !== null && _a !== void 0 ? _a : 'Never'}`);
if (details.daysSinceLastUsed !== null && details.daysSinceLastUsed !== undefined) {
this.log(` Days since last used: ${details.daysSinceLastUsed}`);
}
this.log(` Required inactive days: ${details.requiredMinDaysInactive}`);
if (details.currentTrafficPercentage !== null &&
details.currentTrafficPercentage !== undefined) {
this.log(` Current traffic: ${details.currentTrafficPercentage.toFixed(2)}%`);
}
this.log(` Max traffic threshold: ${details.maxTrafficPercentage}%`);
this.log('\nUse --force to bypass protection.\n');
}
throw new errors_1.APIError(error.message);
}
if (result.retireAppDeployment.ok) {
const name = `${result.retireAppDeployment.ok.retiredAppDeployment.name}@${result.retireAppDeployment.ok.retiredAppDeployment.version}`;
this.log(`App deployment "${name}" retired successfully.`);
}
}
}
AppRetire.description = 'retire an app deployment';
AppRetire.flags = {
'registry.endpoint': core_1.Flags.string({
description: 'registry endpoint',
}),
'registry.accessToken': core_1.Flags.string({
description: 'registry access token',
}),
name: core_1.Flags.string({
description: 'app name',
required: true,
}),
version: core_1.Flags.string({
description: 'app version',
required: true,
}),
target: core_1.Flags.string({
description: 'The target in which the app deployment will be retired (slug or ID).' +
' This can either be a slug following the format "$organizationSlug/$projectSlug/$targetSlug" (e.g "the-guild/graphql-hive/staging")' +
' or an UUID (e.g. "a0f4c605-6541-4350-8cfe-b31f21a4bf80").',
}),
force: core_1.Flags.boolean({
description: 'Force retirement even if protection rules would block it',
default: false,
}),
};
exports.default = AppRetire;
const RetireAppDeploymentMutation = (0, gql_1.graphql)(/* GraphQL */ `
mutation RetireAppDeployment($input: RetireAppDeploymentInput!) {
retireAppDeployment(input: $input) {
ok {
retiredAppDeployment {
id
name
version
status
}
}
error {
message
protectionDetails {
lastUsed
daysSinceLastUsed
requiredMinDaysInactive
currentTrafficPercentage
maxTrafficPercentage
}
}
}
}
`);
//# sourceMappingURL=retire.js.map