Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ The version headers in this history reflect the versions of Apollo Server itself
- [__CHANGELOG for `@apollo/gateway`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-gateway/CHANGELOG.md)
- [__CHANGELOG for `@apollo/federation`__](https://github.com/apollographql/apollo-server/blob/master/packages/apollo-federation/CHANGELOG.md)

### vNEXT

- Deprecate the `ENGINE_API_KEY` environment variable in favor of a newly introduced `APOLLO_KEY`. Continued use of `ENGINE_API_KEY` will result in deprecation warnings and support for it will be removed in a future major version.
[#3923](https://github.com/apollographql/apollo-server/pull/3923)

### v2.11.0

- The range of accepted `peerDepedencies` versions for `graphql` has been widened to include `graphql@^15.0.0-rc.2` so as to accommodate the latest release-candidate of the `graphql@15` package, and an intention to support it when it is finally released on the `latest` npm tag. While this change will subdue peer dependency warnings for Apollo Server packages, many dependencies from outside of this repository will continue to raise similar warnings until those packages own `peerDependencies` are updated. It is unlikely that all of those packages will update their ranges prior to the final version of `graphql@15` being released, but if everything is working as expected, the warnings can be safely ignored. [PR #3825](https://github.com/apollographql/apollo-server/pull/3825)
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { GraphQLRequestContext } from 'apollo-server-types';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { defaultEngineReportingSignature } from 'apollo-graphql';

let warnedOnDeprecatedApiKey = false;

export interface ClientInfo {
clientName?: string;
clientVersion?: string;
Expand Down Expand Up @@ -45,6 +47,23 @@ export type GenerateClientInfo<TContext> = (
requestContext: GraphQLRequestContext<TContext>,
) => ClientInfo;

export function getEngineApiKey(engine: EngineReportingOptions<any> | boolean | undefined) {
if (typeof engine === 'object' && engine.apiKey) {
return engine.apiKey;
}
const legacyApiKeyFromEnv = process.env.ENGINE_API_KEY;
const apiKeyFromEnv = process.env.APOLLO_KEY;

if(legacyApiKeyFromEnv && apiKeyFromEnv) {
throw new Error(`Cannot set both APOLLO_KEY and ENGINE_API_KEY. Please only set APOLLO_KEY.`);
}
if(legacyApiKeyFromEnv && !warnedOnDeprecatedApiKey) {
console.warn(`[Deprecation warning] Setting the key via ENGINE_API_KEY is deprecated and will not be supported in future versions.`);
warnedOnDeprecatedApiKey = true;
}
return apiKeyFromEnv || legacyApiKeyFromEnv || ''
}

export interface EngineReportingOptions<TContext> {
/**
* API key for the service. Get this from
Expand Down Expand Up @@ -212,8 +231,8 @@ const serviceHeaderDefaults = {
// EngineReportingExtensions for each request and sends batches of trace reports
// to the Engine server.
export class EngineReportingAgent<TContext = any> {
private options: EngineReportingOptions<TContext>;
private apiKey: string;
private readonly options: EngineReportingOptions<TContext>;
private readonly apiKey: string;
private reports: { [schemaHash: string]: FullTracesReport } = Object.create(
null,
);
Expand All @@ -230,10 +249,11 @@ export class EngineReportingAgent<TContext = any> {

public constructor(options: EngineReportingOptions<TContext> = {}) {
this.options = options;
this.apiKey = options.apiKey || process.env.ENGINE_API_KEY || '';

this.apiKey = getEngineApiKey(this.options);
if (!this.apiKey) {
throw new Error(
'To use EngineReportingAgent, you must specify an API key via the apiKey option or the ENGINE_API_KEY environment variable.',
`To use EngineReportingAgent, you must specify an API key via the apiKey option or the APOLLO_KEY environment variable.`,
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/apollo-gateway/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## vNEXT

- Fix Typescript generic typing for datasource contexts [#3865](https://github.com/apollographql/apollo-server/pull/3865) This is a fix for the `TContext` typings of the gateway's exposed `GraphQLDataSource` implementations. In their current form, they don't work as intended, or in any manner that's useful for typing the `context` property throughout the class methods. This introduces a type argument `TContext` to the class itself (which defaults to `Record<string, any>` for existing implementations) and removes the non-operational type arguments on the class methods themselves.
- Deprecate the `ENGINE_API_KEY` environment variable in favor of a newly introduced `APOLLO_KEY`. Continued use of `ENGINE_API_KEY` will result in deprecation warnings and support for it will be removed in a future major version. [#3923](https://github.com/apollographql/apollo-server/pull/3923)

## 0.13.2

Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-azure-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-azure-functions",
"version": "2.11.0",
"version": "2.12.0",
"description": "Production-ready Node.js GraphQL server for Azure Functions",
"keywords": [
"GraphQL",
Expand Down Expand Up @@ -36,6 +36,6 @@
"apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite"
},
"peerDependencies": {
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0-rc.2"
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
}
}
4 changes: 2 additions & 2 deletions packages/apollo-server-cloud-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-server-cloud-functions",
"version": "2.11.0",
"version": "2.12.0",
"description": "Production-ready Node.js GraphQL server for Google Cloud Functions",
"keywords": [
"GraphQL",
Expand Down Expand Up @@ -35,6 +35,6 @@
"apollo-server-integration-testsuite": "file:../apollo-server-integration-testsuite"
},
"peerDependencies": {
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0-rc.2"
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
}
}
13 changes: 1 addition & 12 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {

import { Headers } from 'apollo-server-env';
import { buildServiceDefinition } from '@apollographql/apollo-tools';
import {getEngineApiKey} from "apollo-engine-reporting/dist/agent";

const NoIntrospection = (context: ValidationContext) => ({
Field(node: FieldDefinitionNode) {
Expand All @@ -82,18 +83,6 @@ const NoIntrospection = (context: ValidationContext) => ({
},
});

function getEngineApiKey(engine: Config['engine']): string | undefined {
const keyFromEnv = process.env.ENGINE_API_KEY || '';
if (engine === false) {
return;
} else if (typeof engine === 'object' && engine.apiKey) {
return engine.apiKey;
} else if (keyFromEnv) {
return keyFromEnv;
}
return;
}

function getEngineGraphVariant(engine: Config['engine']): string | undefined {
if (engine === false) {
return;
Expand Down
39 changes: 39 additions & 0 deletions packages/apollo-server-core/src/__tests__/ApolloServerBase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,42 @@ describe('ApolloServerBase construction', () => {
);
});
});

describe('environment variables', () => {
const OLD_ENV = process.env;

beforeEach(() => {
jest.resetModules();
process.env = { ...OLD_ENV };
delete process.env.ENGINE_API_KEY;
delete process.env.APOLLO_KEY;
});

afterEach(() => {
process.env = OLD_ENV;
});

it('constructs a reporting agent with the legacy env var and warns', async () => {
Comment thread
zionts marked this conversation as resolved.
Outdated
// set the variables
process.env.ENGINE_API_KEY = 'just:fake:stuff';
const spyConsoleWarn = jest.spyOn(console, 'warn').mockImplementation();

const server = new ApolloServerBase({
schema: buildServiceDefinition([{ typeDefs, resolvers }]).schema,
});

await server.stop();
expect(spyConsoleWarn).toHaveBeenCalledTimes(1);
spyConsoleWarn.mockReset();
});

it('throws an error with both the legacy env var and new env var set', async () => {
// set the variables
process.env.ENGINE_API_KEY = 'just:fake:stuff';
process.env.APOLLO_KEY = 'also:fake:stuff';

expect( () => new ApolloServerBase({
schema: buildServiceDefinition([{ typeDefs, resolvers }]).schema,
})).toThrow();
});
});
6 changes: 0 additions & 6 deletions packages/apollo-server-lambda/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export class ApolloServer extends ApolloServerBase {
// another place, since the documentation becomes much more complicated when
// the constructor is not longer shared between all integration
constructor(options: Config) {
if (process.env.ENGINE_API_KEY || options.engine) {
options.engine = {
sendReportsImmediately: true,
...(typeof options.engine !== 'boolean' ? options.engine : {}),
};
}
super(options);
}

Expand Down