https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Aleksandr Ivanov

10/15/2020, 12:24 PM
Is there anyone experienced with apollo graphql multiplatform library? It is working fine on android but on iOS we got empty body on our backend.
l

louiscad

10/15/2020, 12:50 PM
If you have more details, I think @mbonnin might be able to help you as he's been working on it.
👀 1
m

mbonnin

10/15/2020, 12:54 PM
Yup, we even have #apollo-android since a few days !
@Aleksandr Ivanov do you have more details? Does your backend receive an empty body or does it respond with an empty body?
In all cases, I would recommend setting up a Charles proxy to capture the traffic
a

Aleksandr Ivanov

10/15/2020, 12:58 PM
Oh, Charles is a good idea. Will try it. Post body of the request is empty when came from iOS build. On Android it is working fine. Request is based on query defined in schema.
m

mbonnin

10/15/2020, 1:05 PM
Any chance your code is open source or can be shared? That'd be super helpful to debug
a

Aleksandr Ivanov

10/15/2020, 1:12 PM
It is private unfortunatelly. But I will try to extract a part of it to demo project.
👍 1
Previously I sent wrong information. The request body from iOS build is not empty. Experimented with charles. On android (successful response):
Copy code
:method: POST
:path: /graphql
:scheme: https

content-type: application/json; charset=utf-8
content-length: 316
accept-encoding: gzip
user-agent: okhttp/4.5.0
pragma: no-cache
cache-control: no-cache

{"operationName":"DriverSchedulePageQuery","variables":{"filter":{"from":"2020-10-15","to":"2020-10-29"}},"query":"query DriverSchedulePageQuery($filter: DateFilter!) { driverSchedule(filter: $filter) { __typename content { __typename date duties { __typename id driverShiftId type startAt endAt } } totalPages } }"}
on iOS (400 response):
Copy code
POST /graphql HTTP/1.1

Content-Type: application/x-www-form-urlencoded
User-Agent: Driver%20App/140 CFNetwork/1197 Darwin/19.6.0
Connection: keep-alive
Accept: */*
Accept-Language: en-us
Content-Length: 316
Accept-Encoding: gzip, deflate, br

{"operationName":"DriverSchedulePageQuery","variables":{"filter":{"from":"2020-10-15","to":"2020-10-29"}},"query":"query DriverSchedulePageQuery($filter: DateFilter!) { driverSchedule(filter: $filter) { __typename content { __typename date duties { __typename id driverShiftId type startAt endAt } } totalPages } }"}
The main difference I see is
Content-Type
Yes the problem was in the Content-Type. I manually set
content-type: application/json; charset=utf-8
and it works. Thank you for advice to use Charles 👍
l

louiscad

10/15/2020, 3:22 PM
Why the Android app didn't have that issue? OkHttp adding the content-type by default?
m

mbonnin

10/15/2020, 3:45 PM
Interesting, thanks for the follow up
@Aleksandr Ivanov do you mind opening an issue, we should do the same for iOS
l

louiscad

10/15/2020, 3:49 PM
@mbonnin Can't it be put in common code to avoid forgetting it when adding support for more platforms?
m

mbonnin

10/15/2020, 3:52 PM
We could put the string constant in common code but the way to set the headers is different on iOS and Android so some of it would have to be duplicated anyways
☝️ 1
(Also I don't really want to depend on ktor for a simple use case like this)
a

Aleksandr Ivanov

10/15/2020, 7:49 PM
Yep, will open it tomorrow. It is very confusing that it works differently.
🙏 1
m

mbonnin

10/16/2020, 1:56 PM
Thanks you so much ! If you have the iOS code at hand, a PR is very welcome, if not, I'll fix this somewhere next week
a

Aleksandr Ivanov

10/16/2020, 3:39 PM
I’m not very familiar with iOS development 🤷‍♂️
m

mbonnin

10/16/2020, 3:41 PM
AH ok, I though you had it fixed on your side already, no problem, we'll make a fix
a

Aleksandr Ivanov

10/16/2020, 6:53 PM
I fixed it in multiplatform code writen in kotlin by manually adding header to ApolloClient. If it is how it should be fixed in library I could do that. Just point me to right module to look into.
m

mbonnin

10/16/2020, 6:56 PM
Ah, got it! We want that to be in iOS code ultimately, I'll fix this
a

Aleksandr Ivanov

10/16/2020, 7:41 PM
👌
7 Views