question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

useLazyQuery loading and networkStatus when call refetch. fetchMore send two requests

See original GitHub issue

Hello. I try to use hook useLazyQuery to filter data with new variables. apollo client config for watch query is fetchPolicy: ‘cache-and-network’,

  const [getTracks, { data, loading, error, networkStatus, called, refetch }] = useLazyQuery(TracksPageQuery);

  useEffect(() => {
    if (!called) {
      getTracks({ variables: getQueryVariables() });
    } else {
      refetch(getQueryVariables());
    }
  }, [JSON.stringify(urlQueries)]);

When i set new variables at first time - refetch does not trigger loading as true and networkStatus always 7. But refetch with repeated variables return loading true, as i need.

I tried different fetchPolicy setting, and only with ‘cache-and-network’ and repeated variables returned loading true on refetch. Also it does not suit me to set notifyOnNetworkStatusChange, because i need to show previous result before data will update, and spinner for loading over.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

1reaction
alamothecommented, Jan 1, 2021

Same issues:

  • For "cache-and-network", when fetchMore is called, it will make two different queries to the backend.
  • For the default "cache-first" policy, when fetchMore is called, it won’t update loading (but it doesn’t suffer from the first issue).
0reactions
anjopatercommented, May 3, 2022

I have the same issue,

    "@apollo/client": "^3.5.10",
    "@apollo/react-hooks": "^4.0.0",

The loading status change from false to true in the first call, but after that doing refech is always false, and checking the networkStatus it’s always 7 so I’m not able to get the loading correct status.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Queries - Apollo GraphQL Docs
To run a query within a React component, call useQuery and pass it a GraphQL ... Apollo Client supports two strategies for this:...
Read more >
Fetch more function is undefined for useLazyQuery react ...
My goal to use it in fetch more button click. However, when I try to use it the fetchMore function is undefined. Here...
Read more >
GraphQL Pagination with Apollo V3 - Part 2
The onClick handler on the “load more” button calls the fetchMore function. Then we pass in the after variable (this is basically the...
Read more >
useLazyQuery with Apollo Client - YouTube
Execute GraphQL queries using the useLazyQuery hook with Apollo Client 3.Learn more about GraphQL: ...
Read more >
Interfaces: ApolloQuery - Apollo Elements
networkStatus is useful if you want to display a different loading ... that fetchMore was called on this query and that the network...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found