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

GraphQLError: Add test to check order of fields in JSON.stringify #3336

Merged
merged 1 commit into from Oct 26, 2021
Merged
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
58 changes: 38 additions & 20 deletions src/error/__tests__/GraphQLError-test.ts
Expand Up @@ -144,29 +144,47 @@ describe('GraphQLError', () => {
});
});

it('serializes to include message', () => {
const e = new GraphQLError('msg');
expect(JSON.stringify(e)).to.equal('{"message":"msg"}');
});
it('serializes to include all standard fields', () => {
const eShort = new GraphQLError('msg');
expect(JSON.stringify(eShort, null, 2)).to.equal(dedent`
{
"message": "msg"
}
`);

it('serializes to include message and locations', () => {
const e = new GraphQLError('msg', fieldNode);
expect(JSON.stringify(e)).to.equal(
'{"message":"msg","locations":[{"line":2,"column":3}]}',
const path = ['path', 2, 'field'];
const extensions = { foo: 'bar' };
const eFull = new GraphQLError(
'msg',
fieldNode,
undefined,
undefined,
path,
undefined,
extensions,
);
});

it('serializes to include path', () => {
const e = new GraphQLError('msg', null, null, null, [
'path',
3,
'to',
'field',
]);
expect(e).to.have.deep.property('path', ['path', 3, 'to', 'field']);
expect(JSON.stringify(e)).to.equal(
'{"message":"msg","path":["path",3,"to","field"]}',
);
// We should try to keep order of fields stable
// Changing it wouldn't be breaking change but will fail some tests in other libraries.
expect(JSON.stringify(eFull, null, 2)).to.equal(dedent`
{
"message": "msg",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"path",
2,
"field"
],
"extensions": {
"foo": "bar"
}
}
`);
});
});

Expand Down