Intended outcome:
No network requests and/or queries are run
Actual outcome:
Apollo polls every 1s
How to reproduce the issue:
<Query skip pollInterval={1000} />
Version
Any workaround for this?
We workaround it using our own wrapper which will drop the pollInterval prop when skiping:
import React from 'react';
import { Query as WrappedQuery, OperationVariables, QueryProps, QueryResult } from 'react-apollo';
function Query<TData, TVariables = OperationVariables>(props: QueryProps<TData, TVariables>)
: JSX.Element {
// FIXME: https://github.com/apollographql/react-apollo/issues/2127
const { pollInterval, ...propsNoPoll } = props;
return <WrappedQuery { ...(props.skip ? propsNoPoll : props) }/>;
}
export { Query };
I met the same issue but only happened at re-rendering.
The first time rendering pollInterval respected skip props but after re-rendering, polling every time even the skip is true.
The workaround is to set pollInterval to 0 or the value.
<Query pollInterval={shouldSkip ? 0 : 1000 } />
Is it considered a bug? Will it be fixed?
I'm using state to hide/show a component that is using the useQuery hook with a set poll interval. Once the component is hidden, the query keeps on polling.
I don't believe this is intended and is a bug?
React Apollo has been refactored to use React Hooks behind the scenes for everything, which means a lot has changed since this issue was opened (and a lot of outstanding issues have been resolved). We'll close this issue off, but please let us know if you're still encountering this problem using React Apollo >= 3.1.0. Thanks!
This is still happening with:
"@apollo/react-hooks": "^3.1.3",
"react-apollo": "^3.1.3",
I'm seeing this also. My query looks like this:
useQuery(GET_CATS, {
variables: {
breed,
domestic,
},
skip: !breed || !domestic,
pollInterval: 10000
});
I get this error that the required variable breed is not provided. So, it seems to me like the poll interval is ignoring the skip.
For the time being, the fix pollInterval: breed ? 10000 : 0 worked but this should be addressed.
The versions I'm using:
"@apollo/react-hooks": "3.1.1",
"@apollo/react-ssr": "3.1.1",
Please re-open this issue. This issue is still happening with hooks.
Hey,
It's not totally clear to me how to achieve:
I don't want my polling query to issue any request on mount, because the polled items are also part of another bigger query, so want to avoid duplicating requested items.
Also it's not clear how polling works regarding fetchPolicy. Does polling always hit the network?
Edit, seems I got an answer: "Invariant Violation: Queries that specify the cache-first and cache-only fetchPolicies cannot also be polling queries."
I've just hit this with [email protected]. Can this issue be reopened?
Because we wanted skip to ignore pollInterval, we just wrapped useQuery like this:
import { useQuery as useQueryApollo } from '@apollo/react-hooks';
export const useQuery = (query, options = {}) => {
if (options.pollInterval) {
options.pollInterval = options.skip ? 0 : options.pollInterval;
}
return useQueryApollo(query, options);
};
Yeah I'm doing something similar, thanks @niamleeson. I just thought it was worth bumping this again. Hopefully it's something that could be fixed in Client v3.
Most helpful comment
Please re-open this issue. This issue is still happening with hooks.