MCPcopy
hub / github.com/ardatan/graphql-tools / toJSONDeep

Function toJSONDeep

packages/executor/src/__testUtils__/expectJSON.ts:25–41  ·  view source on GitHub ↗

* Deeply transforms an arbitrary value to a JSON-safe value by calling toJSON * on any nested value which defines it.

(value: unknown)

Source from the content-addressed store, hash-verified

23 * on any nested value which defines it.
24 */
25function toJSONDeep(value: unknown): unknown {
26 if (!isObjectLike(value)) {
27 return value;
28 }
29
30 // @ts-expect-error: toJSON is not defined on all objects
31 if (typeof value.toJSON === 'function') {
32 // @ts-expect-error: toJSON is not defined on all objects
33 return value.toJSON();
34 }
35
36 if (Array.isArray(value)) {
37 return value.map(toJSONDeep);
38 }
39
40 return mapValue(value, toJSONDeep);
41}
42
43export function expectJSON(actual: unknown) {
44 const actualJSON = toJSONDeep(actual);

Callers 3

expectJSONFunction · 0.85
toDeepEqualFunction · 0.85
toDeepNestedPropertyFunction · 0.85

Calls 2

isObjectLikeFunction · 0.90
mapValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…