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 d9f0d8e commit f7d857d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
10 changes: 5 additions & 5 deletions packages/apollo-engine-reporting/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('schema reporting', () => {
{
startSchemaReporting,
executableSchemaIdGenerator,
}
},
);

await pluginTestHarness({
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('schema reporting', () => {
{
startSchemaReporting,
executableSchemaIdGenerator,
}
},
);

await pluginTestHarness({
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('schema reporting', () => {
{
startSchemaReporting,
executableSchemaIdGenerator,
}
},
);

await pluginTestHarness({
Expand Down Expand Up @@ -208,7 +208,7 @@ it('trace construction', async () => {
{
startSchemaReporting,
executableSchemaIdGenerator,
}
},
);

await pluginTestHarness({
Expand All @@ -222,7 +222,7 @@ it('trace construction', async () => {
},
http: new Request('http://localhost:123/foo'),
},
executor: async ({ request: { query: source }}) => {
executor: async ({ request: { query: source } }) => {
return await graphql({
schema,
source,
Expand Down
64 changes: 45 additions & 19 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
GraphQLSchema,
lexicographicSortSchema,
printSchema,
stripIgnoredCharacters
} from "graphql";
stripIgnoredCharacters,
} from 'graphql';
import {
ReportHeader,
Trace,
Expand All @@ -27,7 +27,6 @@ import { reportingLoop, SchemaReporter } from './schemaReporter';
import { v4 as uuidv4 } from 'uuid';
import { isString } from 'util';


let warnedOnDeprecatedApiKey = false;

export interface ClientInfo {
Expand Down Expand Up @@ -60,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 @@ -72,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 @@ -358,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 f7d857d

Please sign in to comment.