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

Query data is {} instead of undefined, despite pull request 3388 #7486

Closed
strblr opened this issue Dec 16, 2020 · 3 comments
Closed

Query data is {} instead of undefined, despite pull request 3388 #7486

strblr opened this issue Dec 16, 2020 · 3 comments

Comments

@strblr
Copy link

strblr commented Dec 16, 2020

Intended outcome:
According to apollographql/react-apollo#3388, unavailable data should not be {} but undefined. One reason mentioned in the PR makes a lot of sense (especially using codegen) :

Forcing no data situations to be empty objects can go against application schemas that enforce a value and don't allow empty objects.

Actual outcome:
It's actually still {} between refetches, when nothing's found in the cache, essentially giving two different semantics for "there's no data" : undefined on initial fetch, then {}. This feels inconsistent and generates nasty runtime errors that are not catched by TypeScript when using codegen.

It also makes patterns like these (recommended here : #6603 (comment)) pointless :

const continuousData = data ?? previousData

How to reproduce the issue:

  • CodeSandbox Link
    Let the first page load, then move to another page. Finally, read the data value in the console :
undefined
{todos: Object}
{todos: Object}
{}
{todos: Object}

Versions
@apollo/client: ^3.3.6 => 3.3.6

@gbiryukov
Copy link

I believe this issue is caused by this snippet.
Seems it had to be removed in this PR to follow currently documented behavior.

A workaround is to disable notifyOnNetworkStatusChange which is not possible in all cases.

@strblr
Copy link
Author

strblr commented Feb 1, 2021

Seems it had to be removed in this PR to follow currently documented behavior.

Honestly, this PR was just such a bad idea. I switched to urql.

@hwillson
Copy link
Member

Let us know if this is still a concern with @apollo/client@latest - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants