Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for queries, includes, and excludes flags for codegen #733

Merged
merged 2 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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