diff --git a/.changeset/stale-onions-check.md b/.changeset/stale-onions-check.md new file mode 100644 index 0000000000..733b757af2 --- /dev/null +++ b/.changeset/stale-onions-check.md @@ -0,0 +1,5 @@ +--- +'@urql/core': patch +--- + +Fix stringifyVariables breaking on x.toJSON scalars. diff --git a/packages/core/src/utils/stringifyVariables.test.ts b/packages/core/src/utils/stringifyVariables.test.ts index 6e6c6ae486..2d592e4e86 100644 --- a/packages/core/src/utils/stringifyVariables.test.ts +++ b/packages/core/src/utils/stringifyVariables.test.ts @@ -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', () => { diff --git a/packages/core/src/utils/stringifyVariables.ts b/packages/core/src/utils/stringifyVariables.ts index 493cb42c08..d8ce554e69 100644 --- a/packages/core/src/utils/stringifyVariables.ts +++ b/packages/core/src/utils/stringifyVariables.ts @@ -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++) {