From 07e685634bbde1011a625f70d225b455c5bb070f Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Fri, 28 Jun 2019 00:51:36 -0400 Subject: [PATCH 1/4] Ensure formatError callback is set for subscriptions --- packages/apollo-server-core/src/ApolloServer.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/apollo-server-core/src/ApolloServer.ts b/packages/apollo-server-core/src/ApolloServer.ts index cc2de5e248c..1daad980239 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -460,9 +460,9 @@ export class ApolloServerBase { onDisconnect: onDisconnect, onOperation: async ( message: { payload: any }, - connection: ExecutionParams, + params: ExecutionParams, ) => { - connection.formatResponse = (value: ExecutionResult) => ({ + params.formatResponse = (value: ExecutionResult) => ({ ...value, errors: value.errors && @@ -471,6 +471,9 @@ export class ApolloServerBase { debug: this.requestOptions.debug, }), }); + + params.formatError = this.requestOptions.formatError; + let context: Context = this.context ? this.context : { connection }; try { @@ -485,7 +488,7 @@ export class ApolloServerBase { })[0]; } - return { ...connection, context }; + return { ...params, context }; }, keepAlive, }, From 135589ad334c2ff77496bde61e3f534d31af4699 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Fri, 28 Jun 2019 00:58:34 -0400 Subject: [PATCH 2/4] Revert rename of variable --- packages/apollo-server-core/src/ApolloServer.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/apollo-server-core/src/ApolloServer.ts b/packages/apollo-server-core/src/ApolloServer.ts index 1daad980239..66ba27bfd72 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -460,9 +460,9 @@ export class ApolloServerBase { onDisconnect: onDisconnect, onOperation: async ( message: { payload: any }, - params: ExecutionParams, + connection: ExecutionParams, ) => { - params.formatResponse = (value: ExecutionResult) => ({ + connection.formatResponse = (value: ExecutionResult) => ({ ...value, errors: value.errors && @@ -472,7 +472,7 @@ export class ApolloServerBase { }), }); - params.formatError = this.requestOptions.formatError; + connection.formatError = this.requestOptions.formatError; let context: Context = this.context ? this.context : { connection }; @@ -488,7 +488,7 @@ export class ApolloServerBase { })[0]; } - return { ...params, context }; + return { ...connection, context }; }, keepAlive, }, From 36b1ff25be22f9280f3853e6e4ee95c5c3d4b984 Mon Sep 17 00:00:00 2001 From: Greg Beaty Date: Wed, 21 Aug 2019 15:30:31 -0400 Subject: [PATCH 3/4] Fix lint issue --- 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 ca32f2e123c..e819b83d72b 100644 --- a/packages/apollo-server-core/src/ApolloServer.ts +++ b/packages/apollo-server-core/src/ApolloServer.ts @@ -631,9 +631,9 @@ export class ApolloServerBase { debug: this.requestOptions.debug, }), }); - + connection.formatError = this.requestOptions.formatError; - + let context: Context = this.context ? this.context : { connection }; try { From bcc2eaf2277885cc558cb8309f0724b5d5cec692 Mon Sep 17 00:00:00 2001 From: Jesse Rosenberger Date: Thu, 22 Aug 2019 19:07:46 +0300 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd132d08fcc..45dff730b18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The version headers in this history reflect the versions of Apollo Server itself > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section. -- _Nothing yet!_ +- `apollo-server-core`: Make `formatError` available to subscriptions in the same spirit as the existing `formatResponse`. [PR #2942](https://github.com/apollographql/apollo-server/pull/2942) ### v2.8.2