Skip to content

Commit 6104d84

Browse files
Add support for queries, includes, and excludes flags for codegen (#733)
* Add support for queries, includes, and excludes flags for codegen After the overhaul, support for the queries flag in codegen was altered. Restore previous behavior and add includes and excludes flags. Note: excludes patterns don't work in watch mode due to a limitation with Gaze, the filewatcher we're using. * Remove unused imports
1 parent 3380d9d commit 6104d84

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

packages/apollo/src/Command.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
loadConfig,
1111
isClientConfig,
1212
isServiceConfig,
13-
ApolloConfig,
14-
LoadingHandler,
15-
ApolloConfigFormat,
16-
ClientConfig
13+
ApolloConfig
1714
} from "apollo-language-server";
1815
import { OclifLoadingHandler } from "./OclifLoadingHandler";
1916

@@ -231,6 +228,16 @@ export abstract class ClientCommand extends ProjectCommand {
231228
char: "t",
232229
description: "The published service tag for this client",
233230
default: "current"
231+
}),
232+
queries: flags.string({
233+
description: "Deprecated in favor of the includes flag"
234+
}),
235+
includes: flags.string({
236+
description: "Glob of files to search for GraphQL operations"
237+
}),
238+
excludes: flags.string({
239+
description:
240+
"Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently work in watch mode"
234241
})
235242
};
236243
public project!: GraphQLClientProject;
@@ -251,6 +258,15 @@ export abstract class ClientCommand extends ProjectCommand {
251258
headers: headersArrayToObject(flags.headers)
252259
};
253260
}
261+
262+
if (flags.includes || flags.queries) {
263+
config.client.includes = [flags.includes || flags.queries];
264+
}
265+
266+
if (flags.excludes) {
267+
config.client.excludes = [flags.excludes];
268+
}
269+
254270
return config;
255271
};
256272
}

packages/apollo/src/commands/client/codegen.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export default class Generate extends ClientCommand {
3232
static flags = {
3333
...ClientCommand.flags,
3434

35-
queries: flags.string({
36-
description: "Glob of files to watch for recompilation"
37-
}),
3835
watch: flags.boolean({
3936
description: "Watch for file changes and reload codegen"
4037
}),
@@ -116,7 +113,7 @@ export default class Generate extends ClientCommand {
116113

117114
async run() {
118115
const {
119-
flags: { watch, queries }
116+
flags: { watch }
120117
} = this.parse(Generate);
121118

122119
const run = () =>
@@ -221,7 +218,7 @@ export default class Generate extends ClientCommand {
221218

222219
if (watch) {
223220
await run().catch(() => {});
224-
const watcher = new Gaze(queries!);
221+
const watcher = new Gaze(this.project.config.client.includes);
225222
watcher.on("all", (event, file) => {
226223
// console.log("\nChange detected, generating types...");
227224
this.project.fileDidChange(Uri.file(file).toString());

0 commit comments

Comments
 (0)