-
Notifications
You must be signed in to change notification settings - Fork 469
/
delete.ts
116 lines (101 loc) · 3.36 KB
/
delete.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import cli from "cli-ux";
import { flags } from "@oclif/command";
import { ProjectCommand } from "../../Command";
import { graphUndefinedError } from "../../utils/sharedMessages";
export default class ServiceDelete extends ProjectCommand {
static description =
"[DEPRECATED] Delete a federated service from Apollo and recompose remaining services" +
ProjectCommand.DEPRECATION_MSG;
static flags = {
...ProjectCommand.flags,
tag: flags.string({
char: "t",
description:
"[Deprecated: please use --variant instead] The variant to delete the implementing service from",
hidden: true,
exclusive: ["variant"],
}),
variant: flags.string({
char: "v",
description: "The variant to delete the implementing service from",
exclusive: ["tag"],
}),
graph: flags.string({
char: "g",
description:
"The ID of the graph in Apollo for which to delete an implementing service. Overrides config file if set.",
}),
federated: flags.boolean({
char: "f",
default: false,
hidden: true,
description:
"[Deprecated: use --serviceName to indicate federation] Indicates that the schema is a partial schema from a federated service",
}),
serviceName: flags.string({
required: true,
description:
"Provides the name of the implementing service for a federated graph",
}),
yes: flags.boolean({
char: "y",
required: false,
description: "Bypass confirmation when deleting a service",
}),
};
async run() {
this.printDeprecationWarning();
let result;
const { flags } = this.parse(ServiceDelete);
// if the yes flag is set we don't need a confirmation, the yes flag is needed for CI or programmatic use.
const confirmed =
flags.yes ||
(await cli.confirm(
"Are you sure you want to delete this service? THIS IS NOT REVERSIBLE! (y/N)"
));
if (!confirmed) {
this.log("You have chosen to not delete this service. Exiting...");
this.exit(0);
}
await this.runTasks(({ flags, project, config }) => [
{
title: "Removing service from Apollo",
task: async () => {
if (!config.graph) {
throw graphUndefinedError;
}
if (flags.federated) {
this.log(
"The --federated flag is no longer required when running federated commands. Use of the flag will not be supported in future versions of the CLI."
);
}
const graphVariant = config.variant;
const { errors, updatedGateway } =
await project.engine.removeServiceAndCompose({
id: config.graph,
graphVariant,
name: flags.serviceName,
});
result = {
serviceName: flags.serviceName,
graphVariant,
graphName: config.graph,
errors,
updatedGateway,
};
return;
},
},
]);
this.log("\n");
if (result.errors && result.errors.length) {
this.error(result.errors.map((error) => error.message).join("\n"));
}
if (result.updatedGateway) {
this.log(
`The ${result.serviceName} service was removed from ${result.graphName}@${result.graphVariant}. Remaining services were composed.`
);
this.log("\n");
}
}
}