Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Segaran committed May 18, 2020
1 parent 977a89e commit e00dfe1
Showing 1 changed file with 43 additions and 16 deletions.
59 changes: 43 additions & 16 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ export type GenerateClientInfo<TContext> = (
) => ClientInfo;

// AS3: Drop support for deprecated `ENGINE_API_KEY`.
export function getEngineApiKey(
{engine, skipWarn = false, logger= console }:
{engine: EngineReportingOptions<any> | boolean | undefined, skipWarn?: boolean, logger?: Logger }
) {
export function getEngineApiKey({
engine,
skipWarn = false,
logger = console,
}: {
engine: EngineReportingOptions<any> | boolean | undefined;
skipWarn?: boolean;
logger?: Logger;
}) {
if (typeof engine === 'object') {
if (engine.apiKey) {
return engine.apiKey;
Expand All @@ -71,34 +76,52 @@ export function getEngineApiKey(
const legacyApiKeyFromEnv = process.env.ENGINE_API_KEY;
const apiKeyFromEnv = process.env.APOLLO_KEY;

if(legacyApiKeyFromEnv && apiKeyFromEnv && !skipWarn) {
logger.warn("Using `APOLLO_KEY` since `ENGINE_API_KEY` (deprecated) is also set in the environment.");
if (legacyApiKeyFromEnv && apiKeyFromEnv && !skipWarn) {
logger.warn(
'Using `APOLLO_KEY` since `ENGINE_API_KEY` (deprecated) is also set in the environment.',
);
}
if(legacyApiKeyFromEnv && !warnedOnDeprecatedApiKey && !skipWarn) {
logger.warn("[deprecated] The `ENGINE_API_KEY` environment variable has been renamed to `APOLLO_KEY`.");
if (legacyApiKeyFromEnv && !warnedOnDeprecatedApiKey && !skipWarn) {
logger.warn(
'[deprecated] The `ENGINE_API_KEY` environment variable has been renamed to `APOLLO_KEY`.',
);
warnedOnDeprecatedApiKey = true;
}
return apiKeyFromEnv || legacyApiKeyFromEnv || ''
return apiKeyFromEnv || legacyApiKeyFromEnv || '';
}

// AS3: Drop support for deprecated `ENGINE_SCHEMA_TAG`.
export function getEngineGraphVariant(engine: EngineReportingOptions<any> | boolean | undefined, logger: Logger = console): string | undefined {
export function getEngineGraphVariant(
engine: EngineReportingOptions<any> | boolean | undefined,
logger: Logger = console,
): string | undefined {
if (engine === false) {
return;
} else if (typeof engine === 'object' && (engine.graphVariant || engine.schemaTag)) {
} else if (
typeof engine === 'object' &&
(engine.graphVariant || engine.schemaTag)
) {
if (engine.graphVariant && engine.schemaTag) {
throw new Error('Cannot set both engine.graphVariant and engine.schemaTag. Please use engine.graphVariant.');
throw new Error(
'Cannot set both engine.graphVariant and engine.schemaTag. Please use engine.graphVariant.',
);
}
if (engine.schemaTag) {
logger.warn('[deprecated] The `schemaTag` property within `engine` configuration has been renamed to `graphVariant`.');
logger.warn(
'[deprecated] The `schemaTag` property within `engine` configuration has been renamed to `graphVariant`.',
);
}
return engine.graphVariant || engine.schemaTag;
} else {
if (process.env.ENGINE_SCHEMA_TAG) {
logger.warn('[deprecated] The `ENGINE_SCHEMA_TAG` environment variable has been renamed to `APOLLO_GRAPH_VARIANT`.');
logger.warn(
'[deprecated] The `ENGINE_SCHEMA_TAG` environment variable has been renamed to `APOLLO_GRAPH_VARIANT`.',
);
}
if (process.env.ENGINE_SCHEMA_TAG && process.env.APOLLO_GRAPH_VARIANT) {
throw new Error('`APOLLO_GRAPH_VARIANT` and `ENGINE_SCHEMA_TAG` (deprecated) environment variables must not both be set.')
throw new Error(
'`APOLLO_GRAPH_VARIANT` and `ENGINE_SCHEMA_TAG` (deprecated) environment variables must not both be set.',
);
}
return process.env.APOLLO_GRAPH_VARIANT || process.env.ENGINE_SCHEMA_TAG;
}
Expand Down Expand Up @@ -357,7 +380,11 @@ export class EngineReportingAgent<TContext = any> {

public constructor(options: EngineReportingOptions<TContext> = {}) {
this.options = options;
this.apiKey = getEngineApiKey({engine: this.options, skipWarn: false, logger: this.logger});
this.apiKey = getEngineApiKey({
engine: this.options,
skipWarn: false,
logger: this.logger,
});
if (options.logger) this.logger = options.logger;
this.bootId = uuidv4();
this.graphVariant = getEngineGraphVariant(options, this.logger) || '';
Expand Down

0 comments on commit e00dfe1

Please sign in to comment.