Skip to content

Commit 04bf842

Browse files
ziontsAdam Zionts
andauthored
Create --variant flag, deprecate --tag flag (#1849)
* Make newlines (optional commit) * Change references of Apollo Engine in flags These default flags were still referencing Apollo Engine instead of Graph Manager (even though some were hidden). Additionally, this updates the docs to be more accurate. Happy to take this commit into another PR if you'd like! * Support variant flag in service:list command This change supports the variant flag (with character -v) in addition to the "tag" flag, which allows us to start using the new terminology. The '--tag' flag is still supported, and there is verification that the two sibling flags cannot be used together. * Give deprecation warning to --tag users * Rename errors util to sharedMessages * Move tag flag deprecation warning to sharedMessages * Support the variant flag in service:check Also remove an unused variable in service:list * Update service:delete to use variant flag Also update description of the flags * Add support to service:download to use --variant Also simplify an import in apollo-language-server Also add a XXX comment to service:download to illustrate a problem * Change magical config tag to use variant Additionally, this updates the text output in the service:check command to consistently use graph@variant everywhere * Rename magical config.tag to config.variant This is a find and replace all, and I verified every command still works after this (both with --tag and --variant). Will post screenshots of how everything looks in the PR :) * Update snapshots A previous commit added `@variant` everywhere, and these snapshot updates should be ONLY that. * Put all handling into the magical config.variant * Replace all flags.tag references to config.variant * Add variant to the client: commands All of the client commands share common flags, so no further changes are required. Also, all of them use config.variant, so yay! :) * Warn about deprecation at magical config.variant Remove the deprecation warning from specific callsites and rely on the deprecation warning appearing when the config.variant value is set * Support for service:push variant Also, this changes the default value of the flag, but it does NOT change the behaviour, since `config.variant` always defaults to "current" if flags and configuration are not set. The reason this was done is because flags.tag will be non-null if there is a default, which causes the deprecation message to always print * Changes word "tag" in some user-facing messages * Some small tweaks in wording Mainly renaming service to graph and "schema" to service, which felt a little meh, but more in line with the name of the command * Update changelog * Updates snapshots to match new messaging This should only include changes to some minor message changes in service:check Co-authored-by: Adam Zionts <adam@meteor.com>
1 parent 227a3e7 commit 04bf842

17 files changed

Lines changed: 169 additions & 98 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
## Upcoming
44

55
- `apollo`
6-
- <First `apollo` related entry goes here>
6+
- https://github.com/apollographql/apollo-tooling/pull/1849
7+
- Update all commands that supported --tag to prefer --variant and indicate a deprecation warning for --tag
8+
- All usages of --tag will continue to work
9+
- The two flags cannot be used in tandem (i.e. --variant replaces --tag)
10+
- --tag will no longer appear in help messages
11+
- Updates of --help messages
12+
- Bug fix of some apollo commands that did not work with `graph@variant` parsing within the apollo.config.js
13+
- Improved error messaging when a graph is not specified in either `apollo.config.js` or within the API key.
714
- `apollo-codegen-flow`
815
- <First `apollo-codegen-flow` related entry goes here>
916
- `apollo-codegen-scala`

packages/apollo-language-server/src/config/__tests__/config.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,21 @@ describe("ApolloConfig", () => {
5555
});
5656
});
5757

58-
describe("tag", () => {
59-
it("gets default tag when none is set", () => {
58+
describe("variant", () => {
59+
it("gets default variant when none is set", () => {
6060
const config = new ApolloConfig({ client: { service: "hai" } });
61-
expect(config.tag).toEqual("current");
61+
expect(config.variant).toEqual("current");
6262
});
6363

64-
it("gets tag from service specifier", () => {
64+
it("gets variant from service specifier", () => {
6565
const config = new ApolloConfig({ client: { service: "hai@master" } });
66-
expect(config.tag).toEqual("master");
66+
expect(config.variant).toEqual("master");
6767
});
6868

69-
it("can set and override tags", () => {
69+
it("can set and override variants", () => {
7070
const config = new ApolloConfig({ client: { service: "hai@master" } });
71-
config.tag = "new";
72-
expect(config.tag).toEqual("new");
71+
config.variant = "new";
72+
expect(config.variant).toEqual("new");
7373
});
7474
});
7575

packages/apollo-language-server/src/config/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class ApolloConfig {
135135
public name?: string;
136136
public service?: ServiceConfigFormat;
137137
public client?: ClientConfigFormat;
138-
private _tag?: string;
138+
private _variant?: string;
139139

140140
constructor(public rawConfig: ApolloConfigFormat, public configURI?: URI) {
141141
this.isService = !!rawConfig.service;
@@ -162,12 +162,12 @@ export class ApolloConfig {
162162
return configs;
163163
}
164164

165-
set tag(tag: string) {
166-
this._tag = tag;
165+
set variant(tag: string) {
166+
this._variant = tag;
167167
}
168168

169-
get tag(): string {
170-
if (this._tag) return this._tag;
169+
get variant(): string {
170+
if (this._variant) return this._variant;
171171
let tag: string = "current";
172172
if (this.client && typeof this.client.service === "string") {
173173
const specifierTag = parseServiceSpecifier(this.client

packages/apollo-language-server/src/project/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class GraphQLClientProject extends GraphQLProject {
177177
client: totalTypes - serviceTypes,
178178
total: totalTypes
179179
},
180-
tag: this.config.tag,
180+
tag: this.config.variant,
181181
loaded: Boolean(this.schema || this.serviceSchema),
182182
lastFetch: this.lastLoadDate
183183
};
@@ -202,7 +202,7 @@ export class GraphQLClientProject extends GraphQLProject {
202202
(async () => {
203203
this.serviceSchema = augmentSchemaWithGeneratedSDLIfNeeded(
204204
await this.schemaProvider.resolveSchema({
205-
tag: tag || this.config.tag,
205+
tag: tag || this.config.variant,
206206
force: true
207207
})
208208
);

packages/apollo-language-server/src/providers/schema/engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import gql from "graphql-tag";
44
import { GraphQLSchema, buildClientSchema } from "graphql";
55
import { ApolloEngineClient, ClientIdentity } from "../../engine";
66
import { ClientConfig, parseServiceSpecifier } from "../../config";
7-
import { getServiceFromKey, isServiceKey } from "../../config/utils";
7+
import { getServiceFromKey, isServiceKey } from "../../config";
88
import {
99
GraphQLSchemaProvider,
1010
SchemaChangeUnsubscribeHandler,

packages/apollo/src/Command.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
import { WithRequired, DeepPartial } from "apollo-env";
1818
import { OclifLoadingHandler } from "./OclifLoadingHandler";
1919
import URI from "vscode-uri";
20+
import { tagFlagDeprecatedWarning } from "./utils/sharedMessages";
2021

2122
const { version, referenceID } = require("../package.json");
2223

@@ -36,6 +37,7 @@ export interface Flags {
3637
engine?: string;
3738
frontend?: string;
3839
tag?: string;
40+
variant?: string;
3941
skipSSLValidation?: boolean;
4042
}
4143

@@ -76,18 +78,19 @@ export abstract class ProjectCommand extends Command {
7678
"Additional header to send to server for introspectionQuery. May be used multiple times to add multiple headers. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag."
7779
}),
7880
endpoint: flags.string({
79-
description: "The url of your service"
81+
description: "The URL for the CLI use to introspect your service"
8082
}),
8183
key: flags.string({
82-
description: "The API key for the Apollo Engine service",
84+
description:
85+
"The API key to use for authentication to Apollo Graph Manager",
8386
default: () => process.env.ENGINE_API_KEY
8487
}),
8588
engine: flags.string({
86-
description: "Reporting URL for a custom Apollo Engine deployment",
89+
description: "URL for a custom Apollo Graph Manager deployment",
8790
hidden: true
8891
}),
8992
frontend: flags.string({
90-
description: "URL for a custom Apollo Engine frontend",
93+
description: "URL for a custom Apollo Graph Manager frontend",
9194
hidden: true
9295
})
9396
};
@@ -143,7 +146,10 @@ export abstract class ProjectCommand extends Command {
143146
return;
144147
}
145148

146-
config.tag = flags.tag || config.tag || "current";
149+
config.variant = flags.variant || flags.tag || config.variant;
150+
if (flags.tag) {
151+
console.warn(tagFlagDeprecatedWarning);
152+
}
147153
// flag overrides
148154
config.setDefaults({
149155
engine: {
@@ -281,7 +287,16 @@ export abstract class ClientCommand extends ProjectCommand {
281287
}),
282288
tag: flags.string({
283289
char: "t",
284-
description: "The published service tag for this client"
290+
description:
291+
"[Deprecated: please use --variant instead] The tag (AKA variant) of the graph in Apollo Graph Manager to associate this client to",
292+
hidden: true,
293+
exclusive: ["variant"]
294+
}),
295+
variant: flags.string({
296+
char: "v",
297+
description:
298+
"The variant of the graph in Apollo Graph Manager to associate this client to",
299+
exclusive: ["tag"]
285300
}),
286301
queries: flags.string({
287302
description: "Deprecated in favor of the includes flag"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { relative } from "path";
88
import { graphqlTypes } from "apollo-language-server";
99
import chalk from "chalk";
1010
import envCi from "env-ci";
11-
import { graphUndefinedError } from "../../utils/errors";
11+
import { graphUndefinedError } from "../../utils/sharedMessages";
1212

1313
const { ValidationErrorType } = graphqlTypes;
1414
type ValidationResult = graphqlTypes.ValidateOperations_service_validateOperations_validationResults;
@@ -60,7 +60,7 @@ export default class ClientCheck extends ClientCommand {
6060

6161
ctx.validationResults = await project.engine.validateOperations({
6262
id: config.name,
63-
tag: config.tag,
63+
tag: config.variant,
6464
operations: ctx.operations.map(({ body, name }) => ({
6565
body,
6666
name

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default class Generate extends ClientCommand {
132132

133133
let write;
134134
const run = () =>
135-
this.runTasks(({ flags, args, project }) => {
135+
this.runTasks(({ flags, args, project, config }) => {
136136
let inferredTarget: TargetType = "" as TargetType;
137137
if (
138138
["json", "swift", "typescript", "flow", "scala"].includes(
@@ -172,7 +172,7 @@ export default class Generate extends ClientCommand {
172172
task: async (ctx, task) => {
173173
task.title = `Generating query files with '${inferredTarget}' target`;
174174
const schema = await project.resolveSchema({
175-
tag: flags.tag
175+
tag: config.variant
176176
});
177177

178178
if (!schema) throw new Error("Error loading schema");

packages/apollo/src/commands/client/download-schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ export default class SchemaDownload extends ClientCommand {
2323
];
2424

2525
async run() {
26-
await this.runTasks(({ args, project, flags }) => {
26+
await this.runTasks(({ args, project, flags, config }) => {
2727
const extension = args.output.split(".").pop();
2828
const isSDLFormat = ["graphql", "graphqls", "gql"].includes(extension);
2929
return [
3030
{
3131
title: `Saving schema to ${args.output}`,
3232
task: async () => {
33-
const schema = await project.resolveSchema({ tag: flags.tag });
33+
const schema = await project.resolveSchema({ tag: config.variant });
3434
const formattedSchema = isSDLFormat
3535
? printSchema(schema)
3636
: JSON.stringify(introspectionFromSchema(schema), null, 2);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ApolloConfig,
1515
graphqlTypes
1616
} from "apollo-language-server";
17-
import { graphUndefinedError } from "../../utils/errors";
17+
import { graphUndefinedError } from "../../utils/sharedMessages";
1818

1919
export default class ClientPush extends ClientCommand {
2020
static description =
@@ -53,7 +53,7 @@ export default class ClientPush extends ClientCommand {
5353
},
5454
{
5555
title: `Checked operations against ${chalk.cyan(
56-
config.name + "@" + config.tag
56+
config.name + "@" + config.variant
5757
)}`,
5858
task: async () => {}
5959
},
@@ -87,7 +87,7 @@ export default class ClientPush extends ClientCommand {
8787
id: config.name,
8888
operations: operationManifest,
8989
manifestVersion: 2,
90-
graphVariant: config.tag
90+
graphVariant: config.variant
9191
};
9292
const { operations: _op, ...restVariables } = variables;
9393
this.debug("Variables sent to Apollo");

0 commit comments

Comments
 (0)