Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid extensions override #3342

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "graphql",
"version": "15.7.1",
"version": "15.7.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert version bump, this is done in a separate flow.

"description": "A Query Language and Runtime which can target any service.",
"license": "MIT",
"private": true,
Expand Down
5 changes: 4 additions & 1 deletion src/error/GraphQLError.js
Expand Up @@ -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 };
}

Expand Down
43 changes: 43 additions & 0 deletions src/error/__tests__/GraphQLError-test.js
Expand Up @@ -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' },
});
});
});
4 changes: 2 additions & 2 deletions src/version.js
Expand Up @@ -6,14 +6,14 @@
/**
* A string containing the version of the GraphQL.js library
*/
export const version = '15.7.1';
export const version = '15.7.2';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert please :)


/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
major: 15,
minor: 7,
patch: 1,
patch: 2,
preReleaseTag: null,
});