From 2d4cef32dd271c05d4f334e7656ec924f2f1d607 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Mon, 11 Feb 2019 20:14:08 -0500 Subject: [PATCH] Require apollo-engine-reporting only if EngineReportingAgent used. 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. --- packages/apollo-server-core/src/ApolloServer.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/apollo-server-core/src/ApolloServer.ts b/packages/apollo-server-core/src/ApolloServer.ts index 6c58cbd49c3..bfc01a3fdb2 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -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'; @@ -103,7 +102,7 @@ export class ApolloServerBase { public requestOptions: Partial> = 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; @@ -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), {