Skip to content

Commit

Permalink
Fix stringifyVariables not stringifying toJSON values for scalars (#718)
Browse files Browse the repository at this point in the history
* Fix stringifyVariables not stringifying toJSON values for scalars

Fix #717

* Update stringifyVariables toJSON test
  • Loading branch information
kitten authored Apr 20, 2020
1 parent 77e5825 commit 762a819
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-onions-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@urql/core': patch
---

Fix stringifyVariables breaking on x.toJSON scalars.
2 changes: 1 addition & 1 deletion packages/core/src/utils/stringifyVariables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ it('returns null for circular structures', () => {

it('stringifies dates correctly', () => {
const date = new Date('2019-12-11T04:20:00');
expect(stringifyVariables(date)).toBe(date.toJSON());
expect(stringifyVariables(date)).toBe(`"${date.toJSON()}"`);
});

it('stringifies dictionaries (Object.create(null)) correctly', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/stringifyVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const stringify = (x: any): string => {
} else if (typeof x !== 'object') {
return JSON.stringify(x) || '';
} else if (x.toJSON) {
return x.toJSON();
return stringify(x.toJSON());
} else if (Array.isArray(x)) {
let out = '[';
for (let i = 0, l = x.length; i < l; i++) {
Expand Down

0 comments on commit 762a819

Please sign in to comment.