Skip to content

Commit

Permalink
Require apollo-engine-reporting only if EngineReportingAgent used. (#…
Browse files Browse the repository at this point in the history
…2305)

When getEngineServiceId does not return a truthy value, we can save memory
and startup time by avoiding importing apollo-engine-reporting, which
(among its other dependencies) imports the protobuf.js implementation.
  • Loading branch information
benjamn authored Feb 12, 2019
1 parent 96351a4 commit 543b9c8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
DocumentNode,
} from 'graphql';
import { GraphQLExtension } from 'graphql-extensions';
import { EngineReportingAgent } from 'apollo-engine-reporting';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';
import runtimeSupportsUploads from './utils/runtimeSupportsUploads';
Expand Down Expand Up @@ -103,7 +102,7 @@ export class ApolloServerBase {
public requestOptions: Partial<GraphQLOptions<any>> = Object.create(null);

private context?: Context | ContextFunction;
private engineReportingAgent?: EngineReportingAgent;
private engineReportingAgent?: import('apollo-engine-reporting').EngineReportingAgent;
private engineServiceId?: string;
private extensions: Array<() => GraphQLExtension>;
private schemaHash: string;
Expand Down Expand Up @@ -333,6 +332,7 @@ export class ApolloServerBase {
this.engineServiceId = getEngineServiceId(engine);

if (this.engineServiceId) {
const { EngineReportingAgent } = require('apollo-engine-reporting');
this.engineReportingAgent = new EngineReportingAgent(
typeof engine === 'object' ? engine : Object.create(null),
{
Expand Down

0 comments on commit 543b9c8

Please sign in to comment.