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

v4: fetchMore produces incorrect variables in InMemoryCache read function #1115

Closed
MechJosh0 opened this issue Dec 14, 2020 · 2 comments
Closed

Comments

@MechJosh0
Copy link

Describe the bug
When using InMemoryCache I should be able to access the variables sent in the network query. You can do this correctly on the first query, and when you use refetch, however, when using fetchMore this doesn't work.

To Reproduce

// useGetFooResults.ts
...
fetchMore({
	page: page.value,
});
...
// ApolloConfiguration.ts
...
const cache: InMemoryCache = new InMemoryCache({
	typePolicies: {
		Query: {
			fields: {
				Foo: {
					read(existing, incoming, { variables }) {
						console.log(variables.page); // When using `fetchMore` this will show the old variable, not the new variable that was used in the request

						// read logic...
					},
					merge(existing, incoming, { variables }) {
						// merge logic...
					},
				},
			},
		},
	},
});
...

Expected behaviour
I should be able to access the correct and latest variables in the InMemoryCache function when using either refetch and fetchMore.

Versions
vue: 2.6.12
vue-apollo: 4.0.0-alpha.12
apollo-client: 3.2.5

@lucatk
Copy link

lucatk commented May 18, 2021

@MechJosh0 can you confirm just updating apollo-client (respective version with merged #7810) and using refetchWritePolicy fixes this?
It does not seem to in my case, especially since using refetchWritePolicy doesnt seem to change behavior of fetchMore.
Did you find any workaround?

@MechJosh0
Copy link
Author

@lucatk Sorry I can't be of any help. I ended up not going that route. I have just tested to see what happens and each time I run a new query it's running the read method for each stored version of the query along with the argument for that. Perhaps it's fixed.

I am using the same versions from the ticket description except for apollo/client which I'm now running at v3.3.12.

I am going to close this ticket as I'm leaning towards the fact that it's been resolved as I'm not having this issue anymore.

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

No branches or pull requests

2 participants