@graphql-hive/cli
Version:
A CLI util to manage and control your GraphQL Hive
140 lines • 4.26 kB
JavaScript
"use strict";
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 schema_1 = require("../../helpers/schema");
const schemaDeleteMutation = (0, gql_1.graphql)(/* GraphQL */ `
mutation schemaDelete($input: SchemaDeleteInput!) {
schemaDelete(input: $input) {
__typename
... on SchemaDeleteSuccess {
valid
changes {
nodes {
criticality
message
}
total
}
errors {
nodes {
message
}
total
}
}
... on SchemaDeleteError {
valid
errors {
nodes {
message
}
total
}
}
}
}
`);
class SchemaDelete extends base_command_1.default {
async run() {
try {
const { flags, args } = await this.parse(SchemaDelete);
const service = args.service;
if (!flags.confirm) {
const confirmed = await core_1.ux.confirm(`Are you sure you want to delete "${service}" from the registry? (y/n)`);
if (!confirmed) {
this.info('Aborting');
this.exit(0);
}
}
const endpoint = this.ensure({
key: 'registry.endpoint',
args: flags,
legacyFlagName: 'registry',
defaultValue: config_1.graphqlEndpoint,
env: 'HIVE_REGISTRY',
});
const accessToken = this.ensure({
key: 'registry.accessToken',
args: flags,
legacyFlagName: 'token',
env: 'HIVE_TOKEN',
});
const result = await this.registryApi(endpoint, accessToken).request({
operation: schemaDeleteMutation,
variables: {
input: {
serviceName: service,
dryRun: flags.dryRun,
},
},
});
if (result.schemaDelete.__typename === 'SchemaDeleteSuccess') {
this.success(`${service} deleted`);
this.exit(0);
return;
}
this.fail(`Failed to delete ${service}`);
const errors = result.schemaDelete.errors;
if (errors) {
schema_1.renderErrors.call(this, errors);
this.exit(1);
}
}
catch (error) {
if (error instanceof core_1.Errors.ExitError) {
throw error;
}
else {
this.fail(`Failed to complete`);
this.handleFetchError(error);
}
}
}
}
SchemaDelete.description = 'deletes a schema';
SchemaDelete.flags = {
'registry.endpoint': core_1.Flags.string({
description: 'registry endpoint',
}),
/** @deprecated */
registry: core_1.Flags.string({
description: 'registry address',
deprecated: {
message: 'use --registry.accessToken instead',
version: '0.21.0',
},
}),
'registry.accessToken': core_1.Flags.string({
description: 'registry access token',
}),
/** @deprecated */
token: core_1.Flags.string({
description: 'api token',
deprecated: {
message: 'use --registry.accessToken instead',
version: '0.21.0',
},
}),
dryRun: core_1.Flags.boolean({
description: 'Does not delete the service, only reports what it would have done.',
default: false,
}),
confirm: core_1.Flags.boolean({
description: 'Confirm deletion of the service',
default: false,
}),
};
SchemaDelete.args = {
service: core_1.Args.string({
name: 'service',
required: true,
description: 'name of the service',
hidden: false,
}),
};
exports.default = SchemaDelete;
//# sourceMappingURL=delete.js.map