Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dset doesnt deepmerge #1804

Merged
merged 4 commits into from Feb 25, 2021
Merged

fix: dset doesnt deepmerge #1804

merged 4 commits into from Feb 25, 2021

Conversation

maraisr
Copy link
Contributor

@maraisr maraisr commented Feb 14, 2021

Upon testing this feature further, I got aware that dset wouldn't "deep merge" the payloads. Which is only prevalent with the @defer directive. As up until now @stream wouldn't only append to an array—whereas @defer would merge into existing objects.

This would fix the issue, however still some work to be done on e2e's. So will leave in draft till then.

cc @acao

@changeset-bot
Copy link

changeset-bot bot commented Feb 14, 2021

🦋 Changeset detected

Latest commit: 4f2bba3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
graphiql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented Feb 14, 2021

Codecov Report

Merging #1804 (f0f27a9) into main (fed92f9) will not change coverage.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1804   +/-   ##
=======================================
  Coverage   65.66%   65.66%           
=======================================
  Files          85       85           
  Lines        5115     5115           
  Branches     1624     1624           
=======================================
  Hits         3359     3359           
  Misses       1752     1752           
  Partials        4        4           
Impacted Files Coverage Δ
packages/graphiql/src/components/GraphiQL.tsx 57.51% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fed92f9...00a285b. Read the comment docs.

@maraisr maraisr marked this pull request as draft February 14, 2021 10:55
@acao
Copy link
Member

acao commented Feb 14, 2021

@maraisr thanks for this!

looks like theres a bug with the implementation according to the cypress suite, where only two payload items made it through, did you notice that? something seems to be broken

@maraisr maraisr marked this pull request as ready for review February 19, 2021 00:45
keys: string | ArrayLike<string | number>,
value: V,
): void;
export function dset(obj, keys, val) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukeed with your blessing I have in-lined this for now, once dset/merge if/when becomes a think I'll update this.

@imolorhe
Copy link
Contributor

I believe it is very important that this new utility comes with unit tests to cover all the use cases, especially the deep merge use case.

@lukeed
Copy link

lukeed commented Feb 19, 2021

Agreed. At least the bare minimum for utility tests. When I polish this up as a standalone (soon) I'll have extensive coverage.

In summary, arrays and objects are merged. On any positional or key/index conflict, the newer value is taken. For non-object values, the new value is always given preference.

@lukeed
Copy link

lukeed commented Feb 19, 2021

For transparency sake, @maraisr reached out to me about this and I provided the dset-merger implementation to be inlined since I don't have the bandwidth to make it it's own module atm.

If there are any issues with it please let me know

@maraisr
Copy link
Contributor Author

maraisr commented Feb 19, 2021

I believe it is very important that this new utility comes with unit tests to cover all the use cases, especially the deep merge use case.

Ya this is true. But the idea here isnt that external people consume this utility. Its analogous to using an npm package. The use-cases are covered in the e2e. This is a safe bet as it stands now, which once Luke's package drops we should be certain.

Till this is is still 100x better than what's currently in mainline.

But happy for this PR to stagnate till this has dropped—because I still believe we need even more e2e's to cover all of the edge cases. But for this, I need to change the way its tested, and introduce a "unit test" for this multipart stuff, so that yeah we can fire fine-grained events and assert the state.

Waiting for your call on this one @acao

@acao
Copy link
Member

acao commented Feb 20, 2021

ohh i see. this is what you meant by inlining dset. i think at this point a slightly bulkier but more widely used alternative for deep object merge might be in order, that or this PR just needs to wait for review until dset has made the relevant improvements we need

@acao
Copy link
Member

acao commented Feb 20, 2021

I was looking for an alternative, and found deep-set, which also has the same issue dset has
jonschlinkert/set-value#26

dot-prop looks awesome, and the other utilities will provide very useful for working a playground esque settings API that plugins can extend, which was part of the 2.x roadmap

@lukeed
Copy link

lukeed commented Feb 20, 2021

Deep-set, dset, set-value, lodash.set are all the effectively the same thing. They set/assign a value at a nested path.

The difference here is that you guys dont want an assignment. You want to merge/collect values at a nested path. I know of no module that does this, hence the inlined fork of dset here.

Recommend dlv for data retrieval.

@lukeed
Copy link

lukeed commented Feb 24, 2021

Published dset@3.1.0 which contains the new dset/merge submodule.

@maraisr
Copy link
Contributor Author

maraisr commented Feb 24, 2021

@acao @imolorhe I have updated this branch with the new dset version. dset has a comprehensive suite of tests focusing specifically on solving the issues here.

This also means that graphiql will now correctly articulate the results of an Incrementally Delivered response.

Thank you so much for powering through this for us @lukeed

@imolorhe
Copy link
Contributor

Nice! Approved. Looks like changeset is missing?

@maraisr
Copy link
Contributor Author

maraisr commented Feb 25, 2021

@imolorhe
Copy link
Contributor

Oh okay I missed that. My bad.

@imolorhe imolorhe merged commit b538f6e into graphql:main Feb 25, 2021
@github-actions github-actions bot mentioned this pull request Feb 25, 2021
@maraisr maraisr deleted the use-nestie branch February 25, 2021 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants