Comments (3)
This sounds very similar to this issue, a fix was being worked on for that, but not sure what the status is for that and if it would fix this issue also.
I'm not sure what the difference is with this repro and mine, I didn't look in detail, but in my repro it only occurred with the read function defined, but it sounds like you're having the same issue even without a read function.
from apollo-client.
Hi @oscar60310 👋
Thanks for opening this issue with a clear reproduction of what you're seeing!
First, when I ran your reproduction, I noted that the fetchPolicy
and nextFetchPolicy
had no bearing on the infinite loop behavior, so I commented them out.
Before defining a merge function for it, I expected Apollo to log a warning and replace the value as described in the documentation.
This is indeed what's happening, but for reasons I'll get into below, our two queries are "replacing the value" in an infinite loop, with no way to resolve the feud. First, here's the warning I saw:
Can you confirm you see a similar warning?
The warning notes that Cache data may be lost when replacing the nested field of a Foobar object
and that This could cause additional (usually avoidable) network requests to fetch data that were otherwise cached
.
As you noted, when the Nested
entity can't be normalized, its fields are nested on our cached Foobar:foobar
entity.
The problem arises when QUERY_DATA_1
and QUERY_DATA_2
select non-overlapping fields on this non-normalized entity. In practice, this means that as soon as e.g. QUERY_DATA_1
resolves with foobar.nested.value1
, QUERY_DATA_2
sees that foobar.nested.value2
is missing in the cache, kicking off a network request whose response removes value1
from the cache and replaces it with value2
. QUERY_DATA_1
then "notices" value1
is missing, and the cycle repeats forever.
I think a note in the docs advising against selecting non-overlapping fields on non-normalized objects would be helpful but would love any other ideas/suggestions you have here. Thanks!
from apollo-client.
Hi @alessbell , thanks for the explanation!
Can you confirm you see a similar warning?
The warning notes that Cache data may be lost when replacing the nested field of a Foobar object and that This could cause additional (usually avoidable) network requests to fetch data that were otherwise cached.
Yes, I see the same warning. It makes me think that we might lose the benefit of the cache. In the worst case, each hook would send a single query. However, the consequence is much more critical than simply not using the cache; it could result in infinite requests being sent to our server.
Is it possible to escape from the loop when we detect a cache issue?
I noticed that if we don't have a value that changes with each request, there won't be an infinite loop, and the cache is not replaced (component1 and component2 both get the correct value).
export const QUERY_DATA_1 = gql`
query foobar1 {
foobar {
id
# lastOnlineAt
nested {
value1
}
}
}
`;
2024-06-10.20-50-09.mp4
from apollo-client.
Related Issues (20)
- fetchMore not hitting onError and causing an infinite loop of queries HOT 3
- [Docs] refetchQueries can fetch non active queries HOT 5
- Typescript compilation error in Node context HOT 5
- I try to integrate GraphQL PHP in backend with Apollo client and React in front end) but I get an undefined post response HOT 3
- awaitRefetchQueries to wait for refetch of queries affected by cache eviction after a mutation HOT 5
- ECONNREFUSED Error When Using Apollo Client with NextJS HOT 3
- resetStore can cause to refetch unmounted/inactive queries HOT 11
- GraphQLWsLink doesn't throw ApolloError when network error happens HOT 2
- WebSocket connection to 'ws://localhost:4000/graphql' failed: HOT 2
- useFragment throws an error when a fragment has the @include directive HOT 3
- Deprecate testing utilities introduced in 3.10 in favor of graphql-testing-library HOT 2
- Why does QueryResult not contain extensions but FetchResult does? HOT 3
- MockedResponse variableMatcher shows warning about no more mocked responses for the query HOT 4
- Partial data returned on error after resetting cache HOT 2
- Type error returning `IGNORE` object when using a generic `TypedDocumentNode` mutation HOT 2
- Documentataion: mutaitonHookOptions.ignoreResults requires additional clarification HOT 1
- @apollo/client reactive var state changes are not reflecting across libraries HOT 7
- fetchMore with fetchPolicy: "no-cache" makes two requests HOT 2
- Problem with custom type policy for query caching HOT 4
- App Crash when using ReactNativeFile in apollo upload client to upload file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-client.