-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fetching data again and again if more queries without id executed #6307
Comments
Ran into the same issue. I've narrowed it down to being introduced in |
@vhenzl Can you try this? new InMemoryCache({
typePolicies: {
// Assuming the __typename for the viewer object is "Viewer":
Viewer: {
// This means the Viewer object is a singleton whose identity
// is independent of any of its fields (other than __typename),
// so the cache can assume that any two Viewer objects are merely
// different views of the same object, and safely merge their
// fields rather than just replacing one with the other, which is
// what seems to be happening right now. This is different from
// keyFields: false in that it allows the Viewer singleton object
// to be normalized, like other entity objects, rather than treating
// it as unidentified data.
keyFields: [],
},
},
}) You could also write |
@benjamn Thanks for the answer. Unfortunately, I can't use the trick with Is this new behaviour considered a bug or is it intended, expected? If it's expected, my guess is the same problem can occur for any type anywhere in the query, not just for the top-level fields. Right? Then the safest way how to prevent it would be to enforce querying |
most likely a bug, local mutations doing export const toggleComments = (
root: {},
variables: {
id: string,
commentsOpenColumnIndex: number | null
},
{ cache }: LocalResolverContext<NormalizedCacheObject, {}>
) => {
const id = cache.identify({
__typename: 'ReportType',
id: variables.id
});
if(id) {
cache.modify( {
_commentsOpenColumnIndex: _currentValue => variables.commentsOpenColumnIndex
}, id)
return true
} else {
return false
}
} also working fine on |
This issue exists for me in beta 50. Adding ID to the graphql query also resolved the bug. |
Ever since the big refactoring in #6221 made the client more aggressive about triggering network requests in response to incomplete cache data (when using a cache-first FetchPolicy), folks testing the betas/RCs have reported that feuding queries can end up triggering an endless loop of unhelpful network requests. This change does not solve the more general problem of queries competing with each other to update the same data in incompatible ways (see #6372 for mitigation strategies), but I believe this commit will effectively put a stop to most cases of endless network requests. See my lengthy implementation comment for more details, since this is a non-obvious solution to a very tricky problem. Fixes #6307. Fixes #6370. Fixes #6434. Fixes #6444.
…6448) Ever since the big refactoring in #6221 made the client more aggressive about triggering network requests in response to incomplete cache data (when using a cache-first FetchPolicy), folks testing the betas/RCs have reported that feuding queries can end up triggering an endless loop of unhelpful network requests. This change does not solve the more general problem of queries competing with each other to update the same data in incompatible ways (see #6372 for mitigation strategies), but I believe this commit will effectively put a stop to most cases of endless network requests. See my lengthy implementation comment for more details, since this is a non-obvious solution to a very tricky problem. Fixes #6307. Fixes #6370. Fixes #6434. Fixes #6444.
Without a reproduction I can't be sure, but |
@benjamn - Your efforts are greatly appreciated however I have tested both The proper fix in my instance has been to pass a custom function when instantiating the cache to parse the
The horrible bodge solution is simply to sweep the issue under the rug and continue using Alternatively I wonder if simply aliasing every query to include a generic |
The problem started after upgrading from beta 45 to beta 48 and is related to missing
id
in queries.Intended outcome:
I have two components, displaying a list of items, each has its own query. The queries are very similar and differ only in query arguments.
It should fetch each query just once, render items and doesn't do anything more.
Actual outcome:
After initial queries complete, a new request to the server is started. Once completed, the other query starts. Then the first one. And again and again…
However,
loading
status doesn't change, the components don't rerender. It just fetches data in the background.My observations:
The code above worked in beta 45, the problem occurs in beta 48+. I didn't try 46 and 47. It's still present in the just-released beta 49.
Querying
id
field onviewer
likein both queries fixes the problem.
Versions
The text was updated successfully, but these errors were encountered: