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 1dde2db commit 66559c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
26 changes: 16 additions & 10 deletions packages/apollo-engine-reporting/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ describe('schema reporting', () => {
});
});


it("trace construction", async () => {
it('trace construction', async () => {
const schema = makeExecutableSchema({ typeDefs });
addMockFunctionsToSchema({ schema });

Expand Down Expand Up @@ -477,18 +476,22 @@ function makeTestHTTP(): Trace.HTTP {
describe('tests for the shouldReportQuery reporting option', () => {
const schemaReportingFunctions = {
startSchemaReporting: jest.fn(),
executableSchemaIdGenerator: jest.fn()
}
executableSchemaIdGenerator: jest.fn(),
};
const schema = makeExecutableSchema({ typeDefs });
addMockFunctionsToSchema({ schema });

const addTrace = jest.fn();
beforeEach(() => {
addTrace.mockClear();
})
});

it('report no traces', async () => {
const pluginInstance = plugin({ traceReporting: false }, addTrace, schemaReportingFunctions);
const pluginInstance = plugin(
{ traceReporting: false },
addTrace,
schemaReportingFunctions,
);

const context = await pluginTestHarness({
pluginInstance,
Expand Down Expand Up @@ -517,7 +520,10 @@ describe('tests for the shouldReportQuery reporting option', () => {
traceReporting: async request => {
return request.request.operationName === 'report';
},
}, addTrace, schemaReportingFunctions);
},
addTrace,
schemaReportingFunctions,
);

const context1 = await pluginTestHarness({
pluginInstance,
Expand Down Expand Up @@ -566,17 +572,17 @@ describe('tests for the shouldReportQuery reporting option', () => {
});

it('report traces async based on operation name', async () => {

const pluginInstance = plugin(
{
traceReporting: async (request) => {
traceReporting: async request => {
let shouldTrace = await (async () => {
return request.request.operationName === 'report';
})()
})();
return shouldTrace;
},
},
addTrace,
schemaReportingFunctions
);

const context1 = await pluginTestHarness({
Expand Down
9 changes: 6 additions & 3 deletions packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
GraphQLRequestContext,
GraphQLRequestContextDidResolveOperation,
Logger,
} from "apollo-server-types";
} from 'apollo-server-types';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { defaultEngineReportingSignature } from 'apollo-graphql';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
Expand Down Expand Up @@ -59,7 +59,10 @@ export type VariableValueOptions =
| SendValuesBaseOptions;

export type TraceReportingOptions<TContext> =
((request: GraphQLRequestContextDidResolveOperation<TContext>) => Promise<boolean>) | boolean;
| ((
request: GraphQLRequestContextDidResolveOperation<TContext>,
) => Promise<boolean>)
| boolean;

export type GenerateClientInfo<TContext> = (
requestContext: GraphQLRequestContext<TContext>,
Expand Down Expand Up @@ -246,7 +249,7 @@ export interface EngineReportingOptions<TContext> {
* ```
*
*/
traceReporting?: TraceReportingOptions<TContext>
traceReporting?: TraceReportingOptions<TContext>;
/**
* [DEPRECATED] Use sendVariableValues
* Passing an array into privateVariables is equivalent to passing { exceptNames: array } into
Expand Down
11 changes: 7 additions & 4 deletions packages/apollo-engine-reporting/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,17 @@ export const plugin = <TContext>(

return {
async didResolveOperation(requestContext) {
if (typeof options.traceReporting !== "function") return;
const shouldReportTrace = await options.traceReporting(requestContext);
if (typeof options.traceReporting !== 'function') return;
const shouldReportTrace = await options.traceReporting(
requestContext,
);

// Help the user understand they've returned an unexpected value,
// which might be a subtle mistake.
if (typeof shouldReportTrace !== "boolean") {
if (typeof shouldReportTrace !== 'boolean') {
(requestContext.logger || logger).warn(
"The 'traceReporting' predicate function must return a boolean value.");
"The 'traceReporting' predicate function must return a boolean value.",
);
return;
}

Expand Down

0 comments on commit 66559c8

Please sign in to comment.