-
-
Notifications
You must be signed in to change notification settings - Fork 612
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] Both result data and exception are sometimes null on network result #747
Comments
I'm not sure using variable in resolved field is permitted or not, and encouraged or not. But when I change the endpoint to use variable at start. Everything goes well. |
post it on github. and let more people see it. I'll anwser you there.
…------------------ Original message ------------------
From: "Jakub Myśliwiec";
Sendtime: Tuesday, Oct 20, 2020 5:19 PM
To: "zino-app/graphql-flutter";
Cc: "zonyzhao"<1668069501@qq.com>; "State change";
Subject: Re: [zino-app/graphql-flutter] result.data is null. (#747)
I have the same issue, can you explain more precisely how you managed to solve it? I don't get what endpoint you changed.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I had similar issue to yours, the query result data and exception was null, but query worked fine in graphql playground. The difference was that some queries that was written earlier worked fine in my flutter app, only the new queries I added had that issue. I deleted comment, because problem "magically" disappear, after I restarted app few times, without any change in code. When I find out what was causing the problem I'll post it here. |
I'm not that lucky as you. I restarted IDE and invalidate cache. Even restart the PC. didn't work. |
Sorry to hear you beat your head on the wall here for so long – it is likely this is due to #744. Can you add:
Also try with Basically, what I think is probably happening here is that the returned structure is somehow slightly unexpected, so the |
Details I added in the discord:
assert(
!(result.data == null && result.exception == null && result.source == QueryResultSource.network),
'network results should always have either data or an exception, but $result has neither. '
'This may be caused by a malformed response or cache misconfiguration.'
);
|
@micimize String typenameDataIdFromObject(Object object) {
if (object is Map<String, Object> &&
object.containsKey('__typename') &&
object.containsKey('id'))
return "${object['__typename']}/${object['id']}";
return null;
} final url = DotEnv().env["GRAPHQL_URL"];
final HttpLink httpLink = HttpLink(url);
final AuthLink authLink = AuthLink(getToken: () async {
final token = await TokenService.getToken();
return '$token';
});
final Link link = authLink.concat(httpLink);
ValueNotifier<GraphQLClient> client = ValueNotifier(GraphQLClient(
cache: GraphQLCache(
dataIdFromObject: typenameDataIdFromObject,
),
link: link,
));
GraphqlClientService(client: client); here's my final friendsList = gql(r'''
query FriendsList {
me {
friends {
__typename
id
name
email
age
favoriteAlcoholName
favoriteAlcoholType
description
gender
genderPreference
alcoholPreference
agePreferenceFrom
agePreferenceTo
latestLocation {
latitude
longitude
}
}
}
}
'''); final WatchQueryOptions options = WatchQueryOptions(
document: query.friendsList,
fetchResults: true,
fetchPolicy:
fetchCache ? FetchPolicy.cacheFirst : FetchPolicy.networkOnly); //fetchCache is set to false
final queryResult = await client.value.query(options);
checkQueryResultForErrors(queryResult); //checks if queryResult has exceptions if it has, our custom exception is thrown
print(queryResult.data);
print(queryResult.exception);
print(queryResult.source); I'm pretty sure that my backend works fine because when I run the same query in graphql playground it works fine and I get the following json as a result: {
"data": {
"me": {
"friends": []
}
}
} However when I run my flutter app that query works randomly, sometimes it fetches result properly, but more often both the result data and exceptions is null and source is network. Sometimes restarting app helps but not always. |
@jmysliv thanks for the info – the fact that it's inconsistent is even more troubling than it just not working. Does it ever have friends data? Also, try this in the playground and see if query FriendsList {
__typename
me {
__typename
friends {
__typename
id
name
}
}
} |
@micimize thanks for reply. Yes, but I was testing without any friends added. Here's result for your query when I added friend in the database. {
"data": {
"__typename": "Query",
"me": {
"__typename": "Account",
"friends": [
{
"__typename": "Account",
"id": "6512afe0-c173-4d66-b803-57891fb3172e",
"name": "kuba"
}
]
}
}
} |
Okay, I think I found source of the problem. I tried your query inside my flutter app and it started working. The same result I achieved when I commented code inside this function (it returns null all the time). String typenameDataIdFromObject(Object object) {
// if (object is Map<String, Object> &&
// object.containsKey('__typename') &&
// object.containsKey('id'))
// return "${object['__typename']}/${object['id']}";
return null;
} I think there is some problem with cache when there isn't |
While @jmysliv is using the stable version, I 'm using |
@Zony-Zhao and @jmysliv I made a PR that should hopefully provide more info on what's going on here – try running your queries with the following to see if it gives more fruitful errors: dependency_overrides:
graphql:
git:
url: git@github.com:micimize/graphql-flutter.git
ref: norm_data_handling
path: packages/graphql
normalize:
git:
url: git@github.com:micimize/ferry.git
ref: partial_paths
path: normalize |
@micimize Seems that nothing changed cause I get the following query result after I run my previous code with the dependency override: QueryResult(source: QueryResultSource.network, data: null, exception: null, timestamp: 2020-10-26 22:04:16.678639) However as I write before, when I added __typename field to my query it started work fine so I don't get any errors now. |
@micimize I probably will join this issue because I was trying to hunt the bug in my app as well, I thought there is some issue with rebroadcasting, but apparently, I have the same problem as 2 guys above. To shortly describe in mutation on |
Okay, small update. I've made a condition in |
@SanjiKir if you reproduce again with these overrides, does dependency_overrides:
graphql:
git:
url: git@github.com:micimize/graphql-flutter.git
ref: norm_data_handling
path: packages/graphql
normalize:
git:
url: git@github.com:micimize/ferry.git
ref: partial_paths
path: normalize |
I'm really perplexed by this issue, and can't seem to find a solid test case / hypothesis for when this happens, but given the current behavior description of "sometimes Anyone running in to this please test with a clean cache and the above overrides, and record a sequence of cache that can create the write/read round-trip failure. It is possible that someone might be running in to gql-dart/ferry#98, or that #754 solves the issue in some cases but not all, but we need data that can be turned into an actual test case. |
@micimize I will give it a shot, today or tomorrow. Pinky swear :D Just to clarify things, in case this thing occurs again instead of silently failing it should throw an error, right? |
@SanjiKir yes – in fact you prompted me to add the following in the event of non-structural roundtrip cache failures:
|
merged #754, but I am not confident it solves whatever is happening here. Regardless, please add |
@Zony-Zhao this looks like an entirely different possible issue. Either the client is not adding the error to the exception for some reason, or you aren't checking for |
Yeah,My bad. This is another thing. I'll delete the post in case of misdirecting others. |
@micimize Extremely sorry for breaking my pinky swear, but I just managed to test it. So I bumped to
And duplicated the bug. The update was no written to the cache, yet I didn't see any error. Also I am not 100% sure, but I believe this problem was in v3 as well when I was using old options to write to the cache. |
@micimize Okay update. I debugged it from all ends. What I've noticed, is that Do you have any ideas what can be wrong? |
Actual code excepts are invaluable here. Maybe:
|
I just stumbled across this error, adding some more info here which might help diagnose. My query is:
I was getting |
@FickleLife the fact that the variable made a difference is noteworthy, but based on what you're saying it isn't necessarily the same issue:
|
Not sure about the previous one, the funny thing it's actually related to the entity the order is being placed on. So Order has always a place, right. And in
mutation
Fragment
Result data correct
Result data wrong
Notice that the place is the same, however order state is closed. Meaning this order was created and closed earlier and now we've tried to create a new one, however both
No, no race conditions, no multiple order creations, nothing like that.
No race condition, no mutation are running
We don't use optimistim so far
This I am not sure I understand, if you can elaborate I can do a double check. We do not provide a custom function for normalization, which means we use the default one. cc @micimize |
@SanjiKir Thanks for the details – on the last item if you aren't using I've made a branch and added a test and data for investigating this issue, but have still not had any luck actually reproducing:
It is rather perplexing. That the cache write has to both fail silently, and then succeed to read an old value, implies either that something is critically wrong (i.e. hive somehow fails |
@micimize Okay I started debugging graphql lib now to solve this problem. What I've found out that it tries to eagerly resolve it from cache (see image), because mutation have default cache and network policy. Now I am not 100% sure, but my guess is since we do not provide
Now I am not sure this is actually correct behavior, it's probably done for optimism, right? Any ideas on how can I fix it besides using |
@SanjiKir ohhhh ok, we finally have an answer to what's going on. So, actually I would recommend using Here's what's happening: The default policy for This is a serious issue, but different from this one. Here're more details on exactly what's happening. Am closing this in favor of #774 |
🎉 This issue has been resolved in version 4.0.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Describe the bug
Just upgraded to graphql_flutter:
^4.0.0-beta.3
. What I did is a normal query as I did before.I'm not sure what is the problem.
I do the same query in postman which is all fine.
I wonder in what situation this data would be null? isLoading is false, and there is no exception. Having worked on it for hours and have no clue.
The text was updated successfully, but these errors were encountered: