-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
(graphcache) - result.fetching is always false in some cases when using requestPolicy cache-and-network #2002
Comments
Have you checked the |
Hello @JoviDeCroock, there is a print about loading and stale prop: Query result with session came after stale setted to false, before that, the query result is:
|
So that seems correct right 😅 we are serving a result from cache (partial result) and are fetching in the background which we can derive because of |
Wait a moment, why it's getting result from cache? This doesn't make sense, i doesn't have this data from cache as you can see in query 1, i'm getting users, and the unique "cache" data, should be id. I think your affirmation is right, we are serving a result from cache (partial result, in this case, id), but is not the correct behavior. In this way, i can't show loading for the front and doesn't have any data available to show in front. |
Your schema tells that the missing fields are nullable so it's rightfully reported as partial in the future #2018 might solve that |
Speaking as someone coming from the apollo-client, this behaviour is surprising. I have a field marked as nullable, which we base business logic upon in the frontend. The logic (in this case, redirect to a 404 page in case of a missing field) runs before we get a chance to fetch the missing data. There is a semantic difference between a (as of yet) missing value and null. In case of a non-nullable value, we might be returning out-of-date data, but at least it's guaranteed that the field had that value at some point in time. In case of a nullable field, the field might never have been set to null. The workaround for me is to simply not pass the |
@Dremora Not quite sure I get the context of the missing fields in your case; I'm assuming the redirect to 404 is a custom implementation. It very much depends however how you implemented that in your GraphQL schema. A That specific semantic difference will definitely depend on how you're building the schema. This actually also recently came up here: #1365 (reply in thread) To summarise that thread, partial data in Graphcache is explicitly a semantic layer on top of existing schema data. But in the absence of However, you can always choose to defer "destructive logic" like a redirect by not applying it when a result is marked with |
@kitten apologies for late reply. Yes, 404 is indeed a custom implementation. It looks like this: useEffect(() => {
if (data && !data.item) {
void redirect('/404');
}
}, [data, data?.item, redirect]); I rely on the When it comes to |
@Dremora Well, nullability opeators is actually what you likely want together with schema-awareness. It'd allow you to explicitly say that the frontend does not handle a certain case, in other words: query ($id: ID!) {
item!(id: $id) {
id
...Item
}
} Here we say that In reverse The spec for this however is taking quite a while, so I'm currently considering to support a Relay-like approach to this by adding However, in either case, if you're doing a redirect only when an entity is missing, it's often sufficient to wait for data to settle, i.e. to change your check to: useEffect(() => {
if (!result.fetching && !result.stale && !result.data?.item) {
return redirect('/404');
}
}, [result]); In general, checking for This also has other uses. Suppose you're on a list page and because you redirect the user to a "create item" page. Let's say you don't have Graphcache updaters set up, and hence either use the |
Hi,
Awesome work!
I am trying to use urql cache in my application but i'm having an issue with that =/
Isn't in all queries, but in some places this happen, i'm doing the query, but the fetching prop is always false.
loading is just an alias to fetching.
If i changed requestPolicy to network-only, it's work, for some reason, i think that the component understand that already read a value from cache, then don't show loading, but i'm not sure.
I have some idea about that, but still don't know how solve that.
I have two queries, first query get all users to populate a user table, the second query is triggered when i click in a table row, selecting a specific user.
Then i have something like this:
query 1:
query 2:
I'm not showing loading at component that trigger query 2. I don't know how solve that, but i think that when i get a user with id 123, and in the last query a i found a array with users, and have some object of user, with id 123, the cache undersand that is the same value.
urql version & exchanges:
"urql": "^2.0.5",
"@urql/exchange-auth": "^0.1.3",
"@urql/exchange-graphcache": "^4.3.5",
"@urql/devtools": "^2.0.3",
"@urql/exchange-multipart-fetch": "^0.1.13",
Steps to reproduce
I don't know how, maybe i should make a demo if need.
Expected behavior
Fetching first setted to true in second component (running query 2)
Actual behavior
Fetching first setted to false always in second component (running query 2)
Someone have any suggestion? I think it's something silly that i have forgotten.
Thanks for your help =)
The text was updated successfully, but these errors were encountered: