Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Question: How to tell if data prop fulfills current query or a previous one #447

Closed
dallonf opened this issue Feb 2, 2017 · 6 comments
Closed

Comments

@dallonf
Copy link

dallonf commented Feb 2, 2017

This question may turn into a feature request depending on whether there's a way to do this... here's my use case:

I have a page that displays a list of objects. Because caching and mutations are kind of weird in Apollo at the moment, I have this list component set to forceFetch: true.

This query is somewhat expensive, so even though I need to run it every time you visit the page, if something's already cached for it, I want to render the page right away and have the forceFetch query run in the background, updating the results (if there is anything to update) once it's done.

I also want this general sequence (immediately render from cache if available, then update in the background) to occur when changing query variables, and that's where I'm starting to run into trouble, because when variables change, one of two things will happen:

  • If the new query can be fulfilled from cache, the component will be updated immediately with new data, and a request goes out in the background. The networkStatus will be changed to setVariables while this is happening.
  • If the new query cannot be fulfilled from cache, the component will still have the old data while a request will go out for new data. I would like to render a spinner in this case. The networkStatus will be changed to setVariables while this is happening.

So... after a lot of rambling, my question is if there's a way to tell the difference between these two states, because I want the UX to be different. If there's not a way... can there be? :)

@calebmer
Copy link
Contributor

calebmer commented Feb 2, 2017

Currently, there is no way to do this on the client’s side. There is, of course, a lot you could do in your React components to get your desired behavior such as setting a loading prop to true whenever you call setVariables.

@dallonf
Copy link
Author

dallonf commented Feb 2, 2017

Thanks for the reply! I'm actually not calling setVariables(), I'm actually relying on state changes from Redux and React Router for that purpose... since my component is not necessarily the one changing the variables, it would be somewhere between impossible and hugely encapsulation-breaking to work around this issue in my app.

Can you help me understand the underlying problem so I can create an issue on apollo-client or wherever needs work? Might even be able to cook up a PR if I've got time.

@jbaxleyiii
Copy link
Contributor

@dallonf is this still an issue?

@dallonf
Copy link
Author

dallonf commented May 3, 2017

Yes; I have a PR open on apollo-client (apollographql/apollo-client#1607) that may resolve this, although it has a pretty heavy impact, so there may be a better option.

@stale stale bot added the wontfix label Jul 5, 2017
@stale
Copy link

stale bot commented Jul 29, 2017

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

@dallonf
Copy link
Author

dallonf commented Jul 30, 2017

I think this issue is actually in Apollo Client rather than react-apollo, so I'll just point to apollographql/apollo-client#1607 and close this

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