Skip to content

Commit

Permalink
Add support for queries, includes, and excludes flags for codegen (#733)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
trevor-scheer authored Nov 21, 2018
1 parent 3380d9d commit 6104d84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 20 additions & 4 deletions packages/apollo/src/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
loadConfig,
isClientConfig,
isServiceConfig,
ApolloConfig,
LoadingHandler,
ApolloConfigFormat,
ClientConfig
ApolloConfig
} from "apollo-language-server";
import { OclifLoadingHandler } from "./OclifLoadingHandler";

Expand Down Expand Up @@ -231,6 +228,16 @@ export abstract class ClientCommand extends ProjectCommand {
char: "t",
description: "The published service tag for this client",
default: "current"
}),
queries: flags.string({
description: "Deprecated in favor of the includes flag"
}),
includes: flags.string({
description: "Glob of files to search for GraphQL operations"
}),
excludes: flags.string({
description:
"Glob of files to exclude for GraphQL operations. Caveat: this doesn't currently work in watch mode"
})
};
public project!: GraphQLClientProject;
Expand All @@ -251,6 +258,15 @@ export abstract class ClientCommand extends ProjectCommand {
headers: headersArrayToObject(flags.headers)
};
}

if (flags.includes || flags.queries) {
config.client.includes = [flags.includes || flags.queries];
}

if (flags.excludes) {
config.client.excludes = [flags.excludes];
}

return config;
};
}
Expand Down
7 changes: 2 additions & 5 deletions packages/apollo/src/commands/client/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ export default class Generate extends ClientCommand {
static flags = {
...ClientCommand.flags,

queries: flags.string({
description: "Glob of files to watch for recompilation"
}),
watch: flags.boolean({
description: "Watch for file changes and reload codegen"
}),
Expand Down Expand Up @@ -116,7 +113,7 @@ export default class Generate extends ClientCommand {

async run() {
const {
flags: { watch, queries }
flags: { watch }
} = this.parse(Generate);

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

if (watch) {
await run().catch(() => {});
const watcher = new Gaze(queries!);
const watcher = new Gaze(this.project.config.client.includes);
watcher.on("all", (event, file) => {
// console.log("\nChange detected, generating types...");
this.project.fileDidChange(Uri.file(file).toString());
Expand Down

0 comments on commit 6104d84

Please sign in to comment.