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

refetch didn't change loading's value #1235

Closed
qxchen6 opened this issue Jul 28, 2021 · 6 comments
Closed

refetch didn't change loading's value #1235

qxchen6 opened this issue Jul 28, 2021 · 6 comments

Comments

@qxchen6
Copy link

qxchen6 commented Jul 28, 2021

Describe the bug
refetch function didn't change loading's value

To Reproduce

  1. const { loading, refetch } = useQuery<T, T2>(query, options)
  2. loading is true on first fetch, it's fine.
  3. then call refetch function. the loading is still false

Expected behavior
When start refetch , loading should change to true ,and change to false at request done.

Versions
vue: 3
vue-apollo: "@vue/apollo-composable": "^4.0.0-alpha.12"
@apollo/client: "@apollo/client": "^3.3.19",

@enzostvs
Copy link

Hello @qxchen6 i dont know if you fixed your problem, but you need to add notifyOnNetworkStatusChange in your options query.
Like this:
const { result, refetch, loading } = useQuery(myQuery, { ...params }, { notifyOnNetworkStatusChange: true } )

@laddi-netapp
Copy link

laddi-netapp commented Oct 15, 2021

We're seeing the same issue in my project, and we've already set notifyOnNetworkStatusChange to true. It's easy to debug by adding a result hook and logging out the value of the loading value passed in vs. the value of $apollo.loading, even $apollo.queries.xxx.loading, and see that the value isn't being updated for the $apollo object.

@jjstanton
Copy link

@laddi-netapp is this affecting all queries or just some?

I'm having similar issues and I have also set notifyOnNetworkStatusChange to true.

@laddi-netapp
Copy link

@jjstanton it's basically every query we try.

@ramonparisg
Copy link

This is still happening in version 4.0.0-alpha.17. Does anyone has a workaround? I've tried setting notifyOnNetworkStatusChange to true as well. @laddi-netapp @jjstanton @sam585456525 @Akryum

@jjstanton
Copy link

@ramonparisg notifyOnNetworkStatusChange seems to be solving the problem for me. I don't think this was its intended use but has become the go to solution, as its mentioned here in the documentation.

We've created a global function that uses this prop, a bit easier than having to rewrite it repeatedly:

export const queryFilter = (gql: any, vars: any, fn: any) => {
    const { result, loading, error, refetch, variables, fetchMore } = useQuery(gql, vars, { notifyOnNetworkStatusChange: true });
    const data = fn ? useResult(result, [], fn) : useResult(result, []);
    return {
        data: data,
        loading: loading,
        error: error,
        refetch,
        variables,
        fetchMore
    };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants