-
Notifications
You must be signed in to change notification settings - Fork 470
/
extract.ts
67 lines (63 loc) · 2.19 KB
/
extract.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
import { flags } from "@oclif/command";
import { writeFileSync } from "fs";
import { ClientCommand } from "../../Command";
import {
getOperationManifestFromProject,
ManifestEntry,
} from "../../utils/getOperationManifestFromProject";
import { ClientIdentity } from "apollo-language-server";
export default class ClientExtract extends ClientCommand {
static description = "Extract queries from a client";
static flags = {
...ClientCommand.flags,
preserveStringAndNumericLiterals: flags.boolean({
description:
"Disable redaction of string and numerical literals. Without this flag, these values will be replaced" +
" with empty strings (`''`) and zeroes (`0`) respectively. This redaction is intended to avoid " +
" inadvertently outputting potentially personally identifiable information (e.g. embedded passwords " +
" or API keys) into operation manifests",
default: false,
}),
};
static args = [
{
name: "output",
description: "Path to write the extracted queries to",
required: true,
default: "manifest.json",
},
];
async run() {
const { clientIdentity, operations, filename } = await this.runTasks<{
clientIdentity: ClientIdentity;
operations: ManifestEntry[];
filename: string;
}>(({ flags, project, config, args }) => [
{
title: "Extracting operations from project",
task: async (ctx) => {
ctx.operations = getOperationManifestFromProject(this.project, {
preserveStringAndNumericLiterals:
flags.preserveStringAndNumericLiterals,
});
ctx.clientIdentity = config.client;
},
},
{
title: "Outputing extracted queries",
task: (ctx, task) => {
const filename = args.output;
task.title = "Outputing extracted queries to " + filename;
ctx.filename = filename;
writeFileSync(
filename,
JSON.stringify({ version: 2, operations: ctx.operations }, null, 2)
);
},
},
]);
this.log(
`Successfully wrote ${operations.length} operations from the ${clientIdentity.name} client to ${filename}`
);
}
}