-
Notifications
You must be signed in to change notification settings - Fork 645
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
Enqueued MockServer
response null
#5571
Comments
Hi 👋 Can you share your |
Hi @martinbonnin, thanks a lot for your answer on this. I do not get an exception. I corrected the My
And regarding parsing, I also tried to parse json with:
And In that case I got exception
I use the apollo library within a kotlin multiplatform project. |
val user = MyUserImpl_ResponseAdapter.MyUser.fromJson(jsonReader, CustomScalarAdapters.Empty) This is internal APIs, you're not really supposed to call them directly. If you want, you'll need to call -val user = MyUserImpl_ResponseAdapter.MyUser.fromJson(jsonReader, CustomScalarAdapters.Empty)
+val user = MyUserImpl_ResponseAdapter.MyUser.obj().fromJson(jsonReader, CustomScalarAdapters.Empty) The public API to do the same thing is Back to your original problem, can you try adding {
"data": {
"getUser": {
"__typename": "BackendUser",
"birthdate": "1990-11-08T00:00:00",
"city": null,
"country": null,
"deactivationTimestamp": null,
"email": "roxana@company.de",
"firstName": "Roxana",
"gender": "FEMALE",
"houseNr": null,
"id": "xxxx",
"lastName": "Test",
"phone": null,
"postalCode": null,
"salutation": "MRS",
"street": null,
"title": null,
"lastOnline": "2024-01-25T18:18:52"
}
}
} The Apollo Compiler queries |
PS: Note that the exception is not thrown, it's part of |
@martinbonnin thank you so so much ❤️. Ya it was mit good old friend Regarding the
Ah okay, thank you for clarification that this is internal and should not be used from outside. I now used
I am not sure why, this is just FYI maybe there is an issue somewhere?
Aaaahh okay 👍, oh this is cool tbh 😍, so thank you for the hint here. From what I see now, there is Nonetheless, there is also
Do I understand it correctly that this is thrown in case |
My bad, But using
For server/network errors, etc.. it's all in
I typically recommend to handle errors like this: if (response.data != null) {
// Handle (potentially partial) data
} else {
// Something wrong happened
if (response.exception != null) {
// Handle non-GraphQL errors (network, cache miss, etc...)
} else {
// Handle GraphQL errors in response.errors
}
} If you don't want to deal with partial data, you can opt-in the new error-aware parsing. You can read https://www.apollographql.com/docs/kotlin/v4/advanced/nullability#error-aware-parsing for more details. Hope this helps! |
@martinbonnin thank you so much for the explanation and the informations. Now everything makes sense for me. I really like the new Error aware parsing within apollo v4 😍 - very nice addition. But do I understand it correctly, that when I specify throwing errors in case that parsing fails with And in case I want some queries and mutations to behave different from that "standard" and to display the data returned from the server, even if it is partial I would need to configure |
That is correct. With |
Ah okay. That make totally sense, now I got the whole idea on that and how it works. And I will start using it. Thanks a lot for the explanations 🙌 ❤️. I guess now my questions are totally answers and I really learned again a lot about the Kotlin apollo client which is a lot more nicer since the last time I used it 🙂. I wish you a wonderful weekend and close this issue. |
Many thanks for the kind words 💙😃. Let us know how the error-aware parsing works for you. This is brand new functionality and your feedback is super important! |
Question
Hi 👋,
I am trying to write some unit tests for my Apollo code and I want to use this nice
MockServer
. Nonetheless, when enqueue responses to it and execute my "mock query", I end up inApolloResponse
withdata
anderrors
null.I am using
com.apollographql.apollo3:apollo-testing-support
v4.0.0-beta.4
andcom.apollographql.apollo3:apollo-mockserver
v4.0.0-beta.4
And I don't know why. Can you please have a quick look and tell me what I am doing wrong?
The text was updated successfully, but these errors were encountered: