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

Merging array in DeepMerger #11704

Open
hartantothio opened this issue Mar 19, 2024 · 3 comments
Open

Merging array in DeepMerger #11704

hartantothio opened this issue Mar 19, 2024 · 3 comments
Labels
ℹ needs-more-info Needs more information to determine root cause

Comments

@hartantothio
Copy link

hartantothio commented Mar 19, 2024

Issue Description

I'm looking at this line and I think it's a problem when I have the following data for source and target:

// New data
source: []

// Previous data
target: [{...}]

My expectation is that the data will be replaced with source, which is the most recent data. But in this case, because Object.keys([]) returns an empty array, it will returns target instead.

Link to Reproduction

n/a

Reproduction Steps

No response

@apollo/client version

3.9.5

@jerelmiller jerelmiller added the 🏓 awaiting-team-response requires input from the apollo team label Mar 25, 2024
@jerelmiller
Copy link
Member

Hey @hartantothio 👋

I'm a bit unclear what you're looking for here. Are you seeing issues with DeepMerger currently that need fixing? Are you using DeepMerger directly in some code that isn't performing correctly? I'd love to get some more context on the outcome you're looking for.

@jerelmiller jerelmiller added ℹ needs-more-info Needs more information to determine root cause 🏓 awaiting-contributor-response requires input from a contributor and removed 🏓 awaiting-team-response requires input from the apollo team labels Mar 25, 2024
@hartantothio
Copy link
Author

Hi @jerelmiller -- sorry about that. Hopefully the following is helpful.

I have a GQL query using the defer directive (doesn't seem to happen if I remove the defer). But, the problematic field isn't part of the the fragment being deferred. It's just the issue seems to be only when I turned on the defer directive on the query.

Example query:

fragment ObjectFragment on Object {
  id
  randomKey {
    someData
  }
}

fragment ObjectSlowFields on Object {
  id
  slowField
}

query TestQuery {
  object {
    ...ObjectFragment
    ...ObjectSlowFields @defer
  }
}

Initially, the returned results might looked like this:

{
    "data": {
        "object": {
            "randomKey": {
                "someData": [1, 2, 3]
            }
        }
    }
}

However, on subsequent fetch, if the server returned an [] for someData, I'd expect the final "merged" data for someData to be [].

@github-actions github-actions bot removed the 🏓 awaiting-contributor-response requires input from a contributor label Mar 26, 2024
@alessbell
Copy link
Member

This sounds like it's related to the failing test in #11374 which I had started investigating. Will take a closer look today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ℹ needs-more-info Needs more information to determine root cause
Projects
None yet
Development

No branches or pull requests

3 participants