From 8be37b23769019b3eb1cb065c4ea765dce4cca6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Cris=C3=B3stomo?= Date: Wed, 27 Oct 2021 22:27:43 +0200 Subject: [PATCH 1/2] Avoid extensions override --- src/error/GraphQLError.js | 5 ++- src/error/__tests__/GraphQLError-test.js | 43 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/error/GraphQLError.js b/src/error/GraphQLError.js index d3068adacb..78169e8970 100644 --- a/src/error/GraphQLError.js +++ b/src/error/GraphQLError.js @@ -105,7 +105,10 @@ export class GraphQLError extends Error { this.extensions = extensions ?? {}; const originalExtensions = originalError?.extensions; - if (isObjectLike(originalExtensions)) { + if ( + Object.keys(this.extensions).length === 0 && + isObjectLike(originalExtensions) + ) { this.extensions = { ...originalExtensions }; } diff --git a/src/error/__tests__/GraphQLError-test.js b/src/error/__tests__/GraphQLError-test.js index 44fb505e12..5d1c71c4a3 100644 --- a/src/error/__tests__/GraphQLError-test.js +++ b/src/error/__tests__/GraphQLError-test.js @@ -233,3 +233,46 @@ describe('printError', () => { `); }); }); + +describe('Graphql error extensions', () => { + it('includes passed extension fields', () => { + const original = new GraphQLError('msgA', null, null, null, null, null, { + foo: 'bar', + }); + const { message, extensions } = new GraphQLError( + 'msgB', + null, + null, + null, + null, + original, + { + baz: 'qux', + }, + ); + + expect({ message, extensions }).to.deep.equal({ + message: 'msgB', + extensions: { baz: 'qux' }, + }); + }); + + it('defaults to original error extension if extensions argument is not passed', () => { + const original = new GraphQLError('msgA', null, null, null, null, null, { + foo: 'bar', + }); + const { message, extensions } = new GraphQLError( + 'msgB', + null, + null, + null, + null, + original, + ); + + expect({ message, extensions }).to.deep.equal({ + message: 'msgB', + extensions: { foo: 'bar' }, + }); + }); +}); From 72ba3753ffe521290d794ff6148216d452cf2823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Cris=C3=B3stomo?= Date: Wed, 27 Oct 2021 22:41:21 +0200 Subject: [PATCH 2/2] 15.7.2 --- package.json | 2 +- src/version.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b1bf9f13bf..4d78ece6fb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "graphql", - "version": "15.7.1", + "version": "15.7.2", "description": "A Query Language and Runtime which can target any service.", "license": "MIT", "private": true, diff --git a/src/version.js b/src/version.js index 1973c0dfb1..2dbd98bda9 100644 --- a/src/version.js +++ b/src/version.js @@ -6,7 +6,7 @@ /** * A string containing the version of the GraphQL.js library */ -export const version = '15.7.1'; +export const version = '15.7.2'; /** * An object containing the components of the GraphQL.js version string @@ -14,6 +14,6 @@ export const version = '15.7.1'; export const versionInfo = Object.freeze({ major: 15, minor: 7, - patch: 1, + patch: 2, preReleaseTag: null, });