From 491135486fcbc77ff06c65d852b61a6e8ce36fe4 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Wed, 23 Sep 2020 15:02:21 -0700 Subject: [PATCH] apollo-server-core: Improve a usage reporting misuse error This error generally should arise when people try to use the unexported AS 1.x API instead of the 2.x API. (If we find other cases that trigger this error we can update the linked issue.) Fixes #4588. --- .../apollo-server-core/src/plugin/usageReporting/plugin.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts b/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts index c541c9f54a1..94105762667 100644 --- a/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts +++ b/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts @@ -77,6 +77,13 @@ export function ApolloServerPluginUsageReporting( // this little hack. (Perhaps we should also allow GraphQLServerListener to contain // a requestDidStart?) requestDidStart(requestContext: GraphQLRequestContext) { + if (!requestDidStartHandler) { + throw Error( + 'The usage reporting plugin has been asked to handle a request before the ' + + 'server has started. See https://github.com/apollographql/apollo-server/issues/4588 ' + + 'for more details.', + ); + } return requestDidStartHandler(requestContext); },