lukeed / dset

A tiny (194B) utility for safely writing deep Object values~!
MIT License
754 stars 22 forks source link

Merging objects at the root results in a no-op #32

Open kirkbyo opened 2 years ago

kirkbyo commented 2 years ago

👋 I believe I have discovered a bug in this library based on GraphiQL usage of the library. If given:

import { dset } from "dset/merge"
let input = {};
dset(input, [], { hero: { id: "A" }});
console.log(input)
// output: {}
// expected: { hero: { id: "A" } }

In the case of GraphQL, this can happen if a field is deferred at the root level (example test case from the reference implementation).

Example commit with test case and a fix: https://github.com/kirkbyo/dset/commit/ffc84ff8f98121cbf5df590c6917deb7936c4d52

Happy to open that commit as a PR here if you would prefer.