diff --git a/src/common/coding/decorate.js b/src/common/coding/decorate.js index 654d6c5..2bd1bfa 100644 --- a/src/common/coding/decorate.js +++ b/src/common/coding/decorate.js @@ -103,7 +103,7 @@ export default function decorate(rootGraph, rootQuery) { : { ...plumGraph }; graph.$val = true; } else if (Array.isArray(plumGraph)) { - graph = decodeGraph(plumGraph); + graph = deValNull(decodeGraph(plumGraph)); } else { throw Error('decorate.unexpected_graph'); } @@ -180,6 +180,16 @@ export default function decorate(rootGraph, rootQuery) { return result; } +// Replace $val: null produced by +function deValNull(graph) { + if (typeof graph !== 'object' || !graph) return graph; + if ('$val' in graph && graph.$val !== true) return graph.$val; + + // Important: update graph in-place to avoid losing non-enumerable props. + for (const prop in graph) graph[prop] = deValNull(graph[prop]); + return graph; +} + function addPageMeta(graph, args) { if (args.$all) { Object.assign(graph, { $page: args, $prev: null, $next: null }); diff --git a/src/common/coding/test/decorate.test.js b/src/common/coding/test/decorate.test.js index b5bc1d5..fd95f8b 100644 --- a/src/common/coding/test/decorate.test.js +++ b/src/common/coding/test/decorate.test.js @@ -174,7 +174,7 @@ describe('val_null', () => { ], { foo: 1 }, ); - expect(result).toEqual({ foo: { bar: { $val: null } } }); + expect(result).toEqual({ foo: { bar: null } }); }); test('explicit', () => {