apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

Loading property on refetched queries is not updated on resetStore

Open MorganeLecurieux opened this issue 4 years ago • 1 comments
trafficstars

Intended outcome: When using client.resetStore(), all queries are refetched, I expect the loading property from useQuery to be updated to true then false

Actual outcome: The loading property is never updated after a client.resetStore()

How to reproduce the issue: I'm using this after a workspace switch to refetch all the queries. So you could just have a regular "meQuery", do a client.resetStore check if loading passes at "true"

const { loading, error, data } = useQuery(GET_ME)

Versions "@apollo/client": "3.4.13"

MorganeLecurieux avatar Sep 30 '21 15:09 MorganeLecurieux

I think I am experiencing a similar problem.

I have a query like this:

query FetchExample(
	$vl1: ID!
	$vl3: ID!
	$vl4: [ID!]!
) {
	level1(id: $vl1) {
		id
		level2 {
			level3(id: $vl3) {
				id
				level4(filters: { userIds: $vl4 }) {
					level5 {
						edges {
							node {
								id
								value
							}
						}
					}
				}
			}
		}
	}
}

InMemoryCache defined like so:

const cache = new InMemoryCache({
	typePolicies: {
		level3: {
			fields: {
				level4: {merge: true},
			},
		},
	},
});

The query works just fine for the first time. I have a component that renders useQuery react hook and puts a result of it into a ContextProvider. But later, when I update children of level4 entity, I remove level3 entity from cache by doing so:

const client = useApolloClient();

client.cache.evict({
	id: `level3:${vl3}`,
});
client.cache.gc();

I see that Apollo run the query automatically, which is quite predictable. But a result of useQuery hook is not changed until response received. So, there is no change in a loading state. What am I doing wrong of may be there is some trick?

Version: "@apollo/client": "^3.6.9",

boonya avatar Aug 30 '22 14:08 boonya

Hi all, I'm doing some housekeeping. This might be similar to / a duplicate of https://github.com/apollographql/apollo-client/issues/8995 but I'll leave both issues open for now. Thanks for your patience!

bignimbus avatar Dec 05 '22 21:12 bignimbus

Just fo your information, to me it's not a problem anymore. I realized that I can use notifyOnNetworkStatusChange: true, property to resolve my issue.

boonya avatar Dec 19 '22 16:12 boonya

@MorganeLecurieux I think @boonya's comment is correct. Can you try notifyOnNetworkStatusChange: true and see if this resolves your issue?

jerelmiller avatar Dec 19 '22 18:12 jerelmiller

Hi all - I believe @boonya's comment above is correct, too. I'll go ahead and close out this issue, but @MorganeLecurieux if you have any other information here feel free to comment and I can re-open it. Thanks!

alessbell avatar Dec 18 '23 19:12 alessbell

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. For general questions, we recommend using StackOverflow or our discord server.

github-actions[bot] avatar Jan 18 '24 00:01 github-actions[bot]