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

Variable recalculation for each polling request #3053

Closed
adam-bernau opened this issue Feb 21, 2018 · 10 comments

Comments

@adam-bernau
Copy link

@adam-bernau adam-bernau commented Feb 21, 2018

Intended outcome:
Use query polling option and recalculate variables for every request.

Actual outcome:
We have a time deppendend query variable, this variable is not propagated from the props, but it is calculated from current time in the query options function. But it's not recalculated when a new polling request is throwed. Is there a way how to enforce variables recalculation please?

const config = {
 options: (props) => {
     const { base } = props;
     // a dynamic variable calculated from current time, it is not recalculated
     const  from =  new Date().getTime() - base; 
     const variables = { from};
     const pollInterval = 5000;
     return { variables, pollInterval };
  }
};

How to reproduce the issue:
https://codesandbox.io/s/q3mjxyw7zw
I tried to simplify the issue and create a simple config with a current time dependend variable.
This variable is not recalculated.

Version

  • apollo-client@2.2.5
@Auchindoun

This comment has been minimized.

Copy link

@Auchindoun Auchindoun commented Feb 27, 2018

I'm also running into this issue. I calculate a variable based on certain parameters and am struggling to find a way to update the initial variables that polling uses if it changes.

Calling updateQuery doesn't seem to have the ability to update the variables as mentioned, either, which at first glance I thought it may be able to.

It looks like the function i use to calculate the property is being called and returning the correct variables (from inside options), but the polling query is still using the stale data from when the page was first loaded.

edit: relevant code to clarify

function getFoo () {
   ...
   return foo // returning correct value on new poll cycle
}


@graphql(query, {
  options: props => {
    return {
      variables: {
        foo: getFoo(),
        ...
      }
   },
   ...
})

But the network tab is using the original value of foo from the initial page load.

@Auchindoun

This comment has been minimized.

Copy link

@Auchindoun Auchindoun commented Mar 6, 2018

bump

@gitupiikki

This comment has been minimized.

Copy link

@gitupiikki gitupiikki commented Mar 14, 2018

Same problem with apollo client 2.2.7. At least i'm not the only one struggling with this problem

@Trancever

This comment has been minimized.

Copy link

@Trancever Trancever commented Mar 20, 2018

/label has-reproduction

@Auchindoun

This comment has been minimized.

Copy link

@Auchindoun Auchindoun commented May 7, 2018

Any update on this issue?

@littletower

This comment has been minimized.

Copy link

@littletower littletower commented Sep 11, 2018

you could use the startPolling and stopPolling functions.
https://www.apollographql.com/docs/react/essentials/queries.html#refetching

@abeaclark

This comment has been minimized.

Copy link

@abeaclark abeaclark commented Dec 6, 2018

Also hitting this issue

@settings settings bot removed the has-reproduction label Dec 12, 2018
@codenamezjames

This comment has been minimized.

Copy link

@codenamezjames codenamezjames commented Dec 18, 2018

I also have this issue with the VUE implementation of Apollo I'm assuming its a limitation of the core Apollo client.

@healqq

This comment has been minimized.

Copy link

@healqq healqq commented Jun 19, 2019

as @littletower mentioned if you call stopPolling before updating variables and then enable polling again - everything will work fine.

@jbaxleyiii

This comment has been minimized.

Copy link
Member

@jbaxleyiii jbaxleyiii commented Jul 9, 2019

Thanks for reporting this. There hasn't been any activity here in quite some time, so we'll close this issue for now. If this is still a problem (using a modern version of Apollo Client), please let us know. Thanks!

@jbaxleyiii jbaxleyiii closed this Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.