Skip to content

Commit 275945d

Browse files
ziontsAdam Zionts
andauthored
Support engine.graphVariant and APOLLO_GRAPH_VARIANT. (#3924)
Co-authored-by: Adam Zionts <adam@meteor.com>
1 parent e076e7d commit 275945d

6 files changed

Lines changed: 77 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ The version headers in this history reflect the versions of Apollo Server itself
66
- [__CHANGELOG for `@apollo/federation`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/CHANGELOG.md)
77

88
### vNEXT
9-
109
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.
1110
11+
- `apollo-engine-reporting`: Deprecated the `APOLLO_SCHEMA_TAG` environment variable in favor of its new name, `APOLLO_GRAPH_VARIANT`. Similarly, within the `engine` configuration object, the `schemaTag` property has been renamed `graphVariant`. The functionality remains otherwise unchanged, but their new names mirror the name used within Apollo Graph Manager. Continued use of the now-deprecated names will result in deprecation warnings and support will be dropped completely in the next "major" update. To avoid misconfiguration, a runtime error will be thrown if _both_ new and deprecated names are set. [PR #3855](https://github.com/apollographql/apollo-server/pull/3855)
1212
- Allow passing a `WebSocket.Server` to `ApolloServer.installSubscriptionHandlers`. [PR #2314](https://github.com/apollographql/apollo-server/pull/2314)
1313

1414
### v2.12.0

docs/source/federation/metrics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Ensure that all dependencies on `apollo-server` are at version `2.7.0` or higher
2020

2121
These options will cause the Apollo gateway to collect tracing information from the underlying federated services and pass them on, along with the query plan, to the Apollo metrics ingress. Currently, only Apollo Server supports detailed metrics insights as an implementing service, but we would love to work with you to implement the protocol in other languages!
2222

23-
> NOTE: By default, metrics will be reported to the `current` variant. To change the variant for reporting, set the `ENGINE_GRAPH_VARIANT` environment variable.
23+
> NOTE: By default, metrics will be reported to the `current` variant. To change the variant for reporting, set the `APOLLO_GRAPH_VARIANT` environment variable.
2424
2525
## How tracing data is exposed from a federated service
2626

packages/apollo-engine-reporting/src/agent.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,29 @@ export type GenerateClientInfo<TContext> = (
4545
requestContext: GraphQLRequestContext<TContext>,
4646
) => ClientInfo;
4747

48+
// AS3: Drop support for deprecated bits.
49+
export function getEngineGraphVariant(engine: EngineReportingOptions<any> | boolean | undefined, logger: Logger = console): string | undefined {
50+
if (engine === false) {
51+
return;
52+
} else if (typeof engine === 'object' && (engine.graphVariant || engine.schemaTag)) {
53+
if (engine.graphVariant && engine.schemaTag) {
54+
throw new Error('Cannot set both engine.graphVariant and engine.schemaTag. Please use engine.graphVariant.');
55+
}
56+
if (engine.schemaTag) {
57+
logger.warn('[Deprecation warning] Usage of engine.schemaTag is deprecated. Please use engine.graphVariant instead.');
58+
}
59+
return engine.graphVariant || engine.schemaTag;
60+
} else {
61+
if (process.env.ENGINE_SCHEMA_TAG) {
62+
logger.warn('[Deprecation warning] Usage of ENGINE_SCHEMA_TAG is deprecated. Please use APOLLO_GRAPH_VARIANT instead.');
63+
}
64+
if (process.env.ENGINE_SCHEMA_TAG && process.env.APOLLO_GRAPH_VARIANT) {
65+
throw new Error('Cannot set both ENGINE_SCHEMA_TAG and APOLLO_GRAPH_VARIANT. Please use APOLLO_GRAPH_VARIANT.')
66+
}
67+
return process.env.APOLLO_GRAPH_VARIANT || process.env.ENGINE_SCHEMA_TAG;
68+
}
69+
}
70+
4871
export interface EngineReportingOptions<TContext> {
4972
/**
5073
* API key for the service. Get this from
@@ -222,6 +245,7 @@ export class EngineReportingAgent<TContext = any> {
222245
private options: EngineReportingOptions<TContext>;
223246
private logger: Logger = console;
224247
private apiKey: string;
248+
private graphVariant: string;
225249
private reports: { [schemaHash: string]: FullTracesReport } = Object.create(
226250
null,
227251
);
@@ -240,6 +264,7 @@ export class EngineReportingAgent<TContext = any> {
240264
this.options = options;
241265
if (options.logger) this.logger = options.logger;
242266
this.apiKey = options.apiKey || process.env.ENGINE_API_KEY || '';
267+
this.graphVariant = getEngineGraphVariant(options, this.logger) || '';
243268
if (!this.apiKey) {
244269
throw new Error(
245270
'To use EngineReportingAgent, you must specify an API key via the apiKey option or the ENGINE_API_KEY environment variable.',
@@ -303,12 +328,7 @@ export class EngineReportingAgent<TContext = any> {
303328
this.reportHeaders[schemaHash] = new ReportHeader({
304329
...serviceHeaderDefaults,
305330
schemaHash,
306-
schemaTag:
307-
this.options.graphVariant
308-
|| this.options.schemaTag
309-
|| process.env.APOLLO_GRAPH_VARIANT
310-
|| process.env.ENGINE_SCHEMA_TAG
311-
|| '',
331+
schemaTag: this.graphVariant,
312332
});
313333
// initializes this.reports[reportHash]
314334
this.resetReport(schemaHash);

packages/apollo-gateway/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section.
66
7+
- Deprecated the `APOLLO_SCHEMA_TAG` environment variable in favor of its new name, `APOLLO_GRAPH_VARIANT`. The functionality remains otherwise identical, but the new name mirrors the name used within Apollo Graph Manager. Use of the now-deprecated name will result in a deprecation warning and support will be dropped completely in a future "major" update. To avoid misconfiguration, runtime errors will be thrown if the new and deprecated name are _both_ set. [#3855](https://github.com/apollographql/apollo-server/pull/3855)
78
- Cache stringified representations of downstream query bodies within the query plan to address performance implications incurred by repeatedly `print`ing the same`DocumentNode`s with the `graphql` printer. This improvement is more pronounced on larger documents. [PR #4018](https://github.com/apollographql/apollo-server/pull/4018)
89
- Add inadvertently excluded `apollo-server-errors` runtime dependency. [#3927](https://github.com/apollographql/apollo-server/pull/3927)
910

packages/apollo-server-core/src/ApolloServer.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171

7272
import { Headers } from 'apollo-server-env';
7373
import { buildServiceDefinition } from '@apollographql/apollo-tools';
74+
import {getEngineGraphVariant} from "apollo-engine-reporting/dist/agent";
7475
import { Logger } from "apollo-server-types";
7576

7677
const NoIntrospection = (context: ValidationContext) => ({
@@ -98,22 +99,6 @@ function getEngineApiKey(engine: Config['engine']): string | undefined {
9899
return;
99100
}
100101

101-
function getEngineGraphVariant(engine: Config['engine']): string | undefined {
102-
if (engine === false) {
103-
return;
104-
} else if (typeof engine === 'object' && (engine.graphVariant || engine.schemaTag)) {
105-
return engine.graphVariant || engine.schemaTag;
106-
} else {
107-
if (process.env.ENGINE_SCHEMA_TAG) {
108-
console.warn('[Deprecation warning] Usage of ENGINE_SCHEMA_TAG is deprecated. Please use APOLLO_GRAPH_VARIANT instead.');
109-
}
110-
if (process.env.ENGINE_SCHEMA_TAG && process.env.APOLLO_GRAPH_VARIANT) {
111-
throw new Error('Cannot set both ENGINE_SCHEMA_TAG and APOLLO_GRAPH_VARIANT. Please use APOLLO_GRAPH_VARIANT.')
112-
}
113-
return process.env.APOLLO_GRAPH_VARIANT || process.env.ENGINE_SCHEMA_TAG;
114-
}
115-
}
116-
117102
function getEngineServiceId(engine: Config['engine']): string | undefined {
118103
const engineApiKey = getEngineApiKey(engine);
119104
if (engineApiKey) {
@@ -446,7 +431,7 @@ export class ApolloServerBase {
446431
),
447432
);
448433

449-
const graphVariant = getEngineGraphVariant(engine);
434+
const graphVariant = getEngineGraphVariant(engine, this.logger);
450435
const engineConfig =
451436
this.engineApiKeyHash && this.engineServiceId
452437
? {

packages/apollo-server-core/src/__tests__/ApolloServerBase.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,52 @@ describe('ApolloServerBase construction', () => {
3030
).not.toThrow();
3131
});
3232

33+
it('succeeds when passed a graphVariant in construction', () => {
34+
let serverBase;
35+
expect(
36+
() =>
37+
new ApolloServerBase({
38+
typeDefs,
39+
resolvers,
40+
engine: {
41+
graphVariant: 'foo',
42+
apiKey: 'not:real:key',
43+
},
44+
}).stop()
45+
).not.toThrow();
46+
});
47+
48+
it('spits out a deprecation warning when passed a schemaTag in construction', () => {
49+
const spyConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();
50+
expect(
51+
() =>
52+
new ApolloServerBase({
53+
typeDefs,
54+
resolvers,
55+
engine: {
56+
schemaTag: 'foo',
57+
apiKey: 'not:real:key',
58+
},
59+
}).stop()
60+
).not.toThrow();
61+
expect(spyConsoleWarn).toBeCalled();
62+
spyConsoleWarn.mockRestore();
63+
});
64+
65+
it('throws when passed a schemaTag and graphVariant in construction', () => {
66+
expect(
67+
() =>
68+
new ApolloServerBase({
69+
schema: buildServiceDefinition([{ typeDefs, resolvers }]).schema,
70+
engine: {
71+
schemaTag: 'foo',
72+
graphVariant: 'heck',
73+
apiKey: 'not:real:key',
74+
},
75+
}),
76+
).toThrow();
77+
});
78+
3379
it('throws when a GraphQLSchema is not provided to the schema configuration option', () => {
3480
expect(() => {
3581
new ApolloServerBase({

0 commit comments

Comments
 (0)