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

Data is undefined on cold cache start #5924

Closed
dilame opened this issue Feb 8, 2020 · 5 comments
Closed

Data is undefined on cold cache start #5924

dilame opened this issue Feb 8, 2020 · 5 comments
Assignees
Milestone

Comments

@dilame
Copy link

dilame commented Feb 8, 2020

My setup

const graphqlDefaultOptions: DefaultOptions = {
  watchQuery: {
    fetchPolicy: 'cache-and-network'
  }
};

Intended outcome:

I don't want to recieve undefined data. It breaks the whole application and violates your type definitions.
Your types declares that data will always be defined
https://github.com/apollographql/apollo-client/blob/master/src/core/types.ts#L23
so i cant even check the data without @ts-ignore.
It's a pain to check it everywhere

Actual outcome:

I recieve undefined data and a lot of errors in console like ERROR TypeError: Cannot read property 'account' of undefined

image

How to reproduce the issue:

Just set fetchPolicy: 'cache-and-network' and query smth.

Versions

  System:
    OS: macOS 10.15.2
  Binaries:
    Node: 13.6.0 - /usr/local/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Browsers:
    Chrome: 80.0.3987.87
    Firefox: 65.0
    Safari: 13.0.4
  npmPackages:
    apollo-angular: ^1.8.0 => 1.8.0 
    apollo-angular-link-http: ^1.9.0 => 1.9.0 
    apollo-cache-inmemory: ^1.6.0 => 1.6.5 
    apollo-cache-persist: ^0.1.1 => 0.1.1 
    apollo-client: ^2.6.0 => 2.6.8 
    apollo-link: ^1.2.11 => 1.2.13 
    apollo-link-http: ^1.5.16 => 1.5.16 
  npmGlobalPackages:
    apollo: 2.16.1
@benjamn benjamn self-assigned this Feb 14, 2020
@benjamn benjamn added this to the Release 3.0 milestone Feb 14, 2020
@benjamn
Copy link
Member

benjamn commented Feb 14, 2020

@dilame Just to be sure I'm understanding, are you calling client.query (which returns a single Promise), as opposed to using client.watchQuery or useQuery or something that can receive multiple results? If so, then this is definitely a bug.

@dilame
Copy link
Author

dilame commented Feb 14, 2020

I'm using client.watchQuery, because cache-and-network works only with it.

@benjamn benjamn removed the 🏓 awaiting-contributor-response requires input from a contributor label Feb 18, 2020
@dilame
Copy link
Author

dilame commented Feb 22, 2020

I'm sorry, i will use this issue for another one bug report because i have the same setup, dont want to duplicate it.

I've found one more bug.

Even if i subscribe to watchQuery second time (cache is hot at this moment) i have 2 emits, first with loading: true, second is false

Снимок экрана 2020-02-22 в 14 23 20

But actually there is NO REQUESTS. I can tell it because i look at Network tab of my developer console. So, first, why i have 2 emits even if data is presented in cache? Second - why it shows me loading state when actually it's not?

@bwhitty
Copy link
Contributor

bwhitty commented Mar 23, 2020

@dilame @benjamn I believe this is the exact same thing as #5947 (just adding another data point to connect dots) which as a reproduction codesandbox

@hwillson
Copy link
Member

data being undefined on a cold cache start is intentional (e.g. apollographql/react-apollo#3388 helps explains some of the reasoning for this). Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 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

4 participants