apollo-kotlin icon indicating copy to clipboard operation
apollo-kotlin copied to clipboard

Support Ktor for all KMM Targets as optional

Open ProVir opened this issue 3 years ago • 4 comments

Hi!

Now there are good DefaultHttpEngine and they are enough for most tasks.

But having KtorHttpEngine as an optional solution would be great!

Example - the application uses GraphQL and REST API, I would like to have a common basis for forming clients, especially when the host is shared with the same requirements for headers, logging and other things.

There is such an implementation for JS, it seems it can be adapted and made universal.

ProVir avatar Jan 19 '22 13:01 ProVir

Hi!

Indeed it looks like the code that already exists in the JavaScript target could be generalized.

One thing we don't have yet is the WebSocket side of this - but it would be great to have it since it is currently missing from the JavaScript target. That could prove trickier to implement however!

A thought: if we went ahead with this, it would certainly be in the form of an independent module (so projects can opt-in), and keep OkHttp/NSURLRequest by default. A drawback being that you now potentially depend on 2 HTTP libraries, even though only one is used.

BoD avatar Jan 19 '22 13:01 BoD

+1 for the separate module for apollo-engine-ktor.

For users that do not want to pull OkHttp in the classpath, a short term option is to exclude it using Gradle. I think that'd work. If that becomes a bigger issue, I guess we could do apollo-runtime-core or something like this without the OkHttp dependency

martinbonnin avatar Jan 19 '22 17:01 martinbonnin

Note on this request. For Android theoretically the JS Http Engine could be used (by only removing the Js Parameter) https://github.com/apollographql/apollo-kotlin/blob/c6a16054c57e9c3b2c2c93f895d3169b37186d8a/apollo-runtime/src/jsMain/kotlin/com/apollographql/apollo3/network/http/KtorHttpEngine.kt

On iOS this results in an issue with the okio.Buffer because it is freezed. You get an kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen okio.Buffer@1ab1928 inside /apollo3/api/json/BufferedSourceJsonReader.kt:706:12 maybe the freeze occures inside the GCDWorker https://github.com/apollographql/apollo-kotlin/blob/c6a16054c57e9c3b2c2c93f895d3169b37186d8a/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt

Full Error output
Uncaught Kotlin exception: kotlin.Throwable: The process was terminated due to the unhandled exception thrown in the coroutine [StandaloneCoroutine{Cancelling}@15d1238, MainDispatcher]: Failed to parse GraphQL http network response
  at 0   MultiPlatformLibrary                0x000000010c63bf1d kfun:kotlinx.coroutines#handleCoroutineExceptionImpl(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 781 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/CoroutineExceptionHandlerImpl.kt:17:19)
  at 1   MultiPlatformLibrary                0x000000010c591130 kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 976 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/CoroutineExceptionHandler.kt:33:5)
  at 2   MultiPlatformLibrary                0x000000010c57e7d2 kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 194 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/Builders.common.kt:241:9)
  at 3   MultiPlatformLibrary                0x000000010c59f4b9 kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 2201 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Debug.kt:17:9748)
  at 4   MultiPlatformLibrary                0x000000010c5ab31f kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal + 1807 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:925:16)
  at 5   MultiPlatformLibrary                0x000000010c5aaae3 kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 707 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:878:16)
  at 6   MultiPlatformLibrary                0x000000010c5aa5ae kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 462 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/JobSupport.kt:843:30)
  at 7   MultiPlatformLibrary                0x000000010c57d995 kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 309 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:104:21)
  at 8   MultiPlatformLibrary                0x000000010c44e6cb kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1483 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:43:32)
  at 9   MultiPlatformLibrary                0x000000010c645d92 kfun:kotlinx.coroutines.internal.ShareableContinuation#resumeWith(kotlin.Result<1:0>){} + 594 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/internal/Sharing.kt:185:22)
  at 10  MultiPlatformLibrary                0x000000010c61d2f3 kfun:kotlinx.coroutines.internal.ScopeCoroutine#afterResume(kotlin.Any?){} + 387 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/internal/Scopes.kt:43:15)
  at 11  MultiPlatformLibrary                0x000000010c57da05 kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 421 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/AbstractCoroutine.kt:106:9)
  at 12  MultiPlatformLibrary                0x000000010c44e6cb kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1483 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/coroutines/ContinuationImpl.kt:43:32)
  at 13  MultiPlatformLibrary                0x000000010c6145b1 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 2897 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/native/src/Debug.kt:17:2786)
  at 14  MultiPlatformLibrary                0x000000010c64a955 kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda-0#internal + 101 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:36:10)
  at 15  MultiPlatformLibrary                0x000000010c64ad4d kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda-0$FUNCTION_REFERENCE$365.invoke#internal + 61 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:36:10)
  at 16  MultiPlatformLibrary                0x000000010c64ae2d kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda-0$FUNCTION_REFERENCE$365.$<bridge-UNN>invoke(){}#internal + 61 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:36:10)
  at 17  MultiPlatformLibrary                0x000000010c64bffa _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f7265_knbridge812 + 202 (/opt/buildAgent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/nativeDarwin/src/Dispatchers.kt:34:9)
  at 18  libdispatch.dylib                   0x000000010bf74848 _dispatch_call_block_and_release + 12
  at 19  libdispatch.dylib                   0x000000010bf75a2c _dispatch_client_callout + 8
  at 20  libdispatch.dylib                   0x000000010bf841f1 _dispatch_main_queue_callback_4CF + 1197
  at 21  CoreFoundation                      0x000000010e21e84d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
  at 22  CoreFoundation                      0x000000010e2190aa __CFRunLoopRun + 2772
  at 23  CoreFoundation                      0x000000010e2180f3 CFRunLoopRunSpecific + 567
  at 24  GraphicsServices                    0x0000000114357cd3 GSEventRunModal + 139
  at 25  UIKitCore                           0x00000001209c1f42 -[UIApplication _run] + 928
  at 26  UIKitCore                           0x00000001209c6b5e UIApplicationMain + 101
  at 27  SwiftUI                             0x0000000116a41dcf $s7SwiftUI17KitRendererCommon33_ACC2C5639A7D76F611E170E831FCA491LLys5NeverOyXlXpFAESpySpys4Int8VGSgGXEfU_ + 196
  at 28  SwiftUI                             0x0000000116a41d09 $s7SwiftUI6runAppys5NeverOxAA0D0RzlF + 148
Caused by: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen okio.Buffer@1ab1928
  at 0   MultiPlatformLibrary                0x000000010c429f79 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 89 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24:56)
  at 1   MultiPlatformLibrary                0x000000010c4237c7 kfun:kotlin.Exception#<init>(kotlin.String?){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:58)
  at 2   MultiPlatformLibrary                0x000000010c4239b7 kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:58)
  at 3   MultiPlatformLibrary                0x000000010c45c987 kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:24:85)
  at 4   MultiPlatformLibrary                0x000000010c45dddd ThrowInvalidMutabilityException + 429 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:109:11)
  at 5   MultiPlatformLibrary                0x000000010cb96ac2 MutationCheck + 114
  at 6   MultiPlatformLibrary                0x000000010c6c33f1 kfun:okio.Buffer#<set-size>(kotlin.Long){} + 81 (/Users/runner/work/okio/okio/okio/src/nonJvmMain/kotlin/okio/Buffer.kt:75:17)
  at 7   MultiPlatformLibrary                0x000000010c6c4f80 kfun:okio.Buffer#readByte(){}kotlin.Byte + 672 (/Users/runner/work/okio/okio/okio/src/commonMain/kotlin/okio/internal/-Buffer.kt:<unknown>)
  at 8   MultiPlatformLibrary                0x000000010c72e93e kfun:com.apollographql.apollo3.api.json.BufferedSourceJsonReader.doPeek#internal + 4622 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/json/BufferedSourceJsonReader.kt:277:16)
  at 9   MultiPlatformLibrary                0x000000010c72b4c2 kfun:com.apollographql.apollo3.api.json.BufferedSourceJsonReader#beginObject(){}com.apollographql.apollo3.api.json.JsonReader + 674 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/libraries/stdlib/src/kotlin/contracts/ContractBuilder.kt:74:79)
  at 10  MultiPlatformLibrary                0x000000010c71efa9 kfun:com.apollographql.apollo3.api.internal.ResponseParser#parse(com.apollographql.apollo3.api.json.JsonReader;com.apollographql.apollo3.api.Operation<0:0>;com.apollographql.apollo3.api.CustomScalarAdapters){0§<com.apollographql.apollo3.api.Operation.Data>}com.apollographql.apollo3.api.ApolloResponse<0:0> + 921 (/Users/runner/work/okio/okio/okio/src/commonMain/kotlin/okio/Okio.kt:<unknown>)
  at 11  MultiPlatformLibrary                0x000000010c7109ac kfun:com.apollographql.apollo3.api#parseJsonResponse__at__com.apollographql.apollo3.api.Operation<0:0>(com.apollographql.apollo3.api.json.JsonReader;com.apollographql.apollo3.api.CustomScalarAdapters){0§<com.apollographql.apollo3.api.Operation.Data>}com.apollographql.apollo3.api.ApolloResponse<0:0> + 636 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Operations.kt:59:25)
  at 12  MultiPlatformLibrary                0x000000010c785a5e kfun:com.apollographql.apollo3.network.http.HttpNetworkTransport.execute$lambda-1$lambda-0#internal + 526 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt:74:21)
  at 13  MultiPlatformLibrary                0x000000010c7879ea kfun:com.apollographql.apollo3.network.http.HttpNetworkTransport.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$271.invoke#internal + 154 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt:72:29)
  at 14  MultiPlatformLibrary                0x000000010c7553d4 kfun:com.apollographql.apollo3.internal.GCDWorker.execute$lambda-1$lambda-0#internal + 452 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:16:7)
  at 15  MultiPlatformLibrary                0x000000010c755bb4 kfun:com.apollographql.apollo3.internal.GCDWorker.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$257.invoke#internal + 68 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:17:6)
  at 16  MultiPlatformLibrary                0x000000010c755ced kfun:com.apollographql.apollo3.internal.GCDWorker.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$257.$<bridge-UNN>invoke(){}#internal + 61 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:17:6)
  at 17  MultiPlatformLibrary                0x000000010c755dda _636f6d2e61706f6c6c6f6772617068716c2e61706f6c6c6f333a61706f6c6c6f2d72756e74696d65_knbridge353 + 202 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:19:36)
  at 18  libdispatch.dylib                   0x000000010bf74848 _dispatch_call_block_and_release + 12
  at 19  libdispatch.dylib                   0x000000010bf75a2c _dispatch_client_callout + 8
  at 20  libdispatch.dylib                   0x000000010bf87bdd _dispatch_root_queue_drain + 887
  at 21  libdispatch.dylib                   0x000000010bf884c3 _dispatch_worker_thread2 + 196
  at 22  libsystem_pthread.dylib             0x000000010dd1c049 _pthread_wqthread + 256
  at 23  libsystem_pthread.dylib             0x000000010dd1b01b start_wqthread + 15
  Suppressed: kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen okio.Buffer@1ab1928
      at 0   MultiPlatformLibrary                0x000000010c429f79 kfun:kotlin.Throwable#<init>(kotlin.String?){} + 89 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Throwable.kt:24:56)
      at 1   MultiPlatformLibrary                0x000000010c4237c7 kfun:kotlin.Exception#<init>(kotlin.String?){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:23:58)
      at 2   MultiPlatformLibrary                0x000000010c4239b7 kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/Exceptions.kt:34:58)
      at 3   MultiPlatformLibrary                0x000000010c45c987 kfun:kotlin.native.concurrent.InvalidMutabilityException#<init>(kotlin.String){} + 87 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Freezing.kt:24:85)
      at 4   MultiPlatformLibrary                0x000000010c45dddd ThrowInvalidMutabilityException + 429 (/opt/buildAgent/work/6326934d18cfe24e/kotlin/kotlin-native/runtime/src/main/kotlin/kotlin/native/concurrent/Internal.kt:109:11)
      at 5   MultiPlatformLibrary                0x000000010cb96ac2 MutationCheck + 114
      at 6   MultiPlatformLibrary                0x000000010c6c33f1 kfun:okio.Buffer#<set-size>(kotlin.Long){} + 81 (/Users/runner/work/okio/okio/okio/src/nonJvmMain/kotlin/okio/Buffer.kt:75:17)
      at 7   MultiPlatformLibrary                0x000000010c6cb1e8 kfun:okio.Buffer#skip(kotlin.Long){} + 712 (/Users/runner/work/okio/okio/okio/src/commonMain/kotlin/okio/internal/-Buffer.kt:<unknown>)
      at 8   MultiPlatformLibrary                0x000000010c6caf11 kfun:okio.Buffer#clear(){} + 81 (/Users/runner/work/okio/okio/okio/src/commonMain/kotlin/okio/internal/-Buffer.kt:<unknown>)
      at 9   MultiPlatformLibrary                0x000000010c73a7ea kfun:com.apollographql.apollo3.api.json.BufferedSourceJsonReader#close(){} + 458 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/json/BufferedSourceJsonReader.kt:706:12)
      at 10  MultiPlatformLibrary                0x000000010c71f808 kfun:com.apollographql.apollo3.api.internal.ResponseParser#parse(com.apollographql.apollo3.api.json.JsonReader;com.apollographql.apollo3.api.Operation<0:0>;com.apollographql.apollo3.api.CustomScalarAdapters){0§<com.apollographql.apollo3.api.Operation.Data>}com.apollographql.apollo3.api.ApolloResponse<0:0> + 3064 (/Users/runner/work/okio/okio/okio/src/commonMain/kotlin/okio/Okio.kt:<unknown>)
      at 11  MultiPlatformLibrary                0x000000010c7109ac kfun:com.apollographql.apollo3.api#parseJsonResponse__at__com.apollographql.apollo3.api.Operation<0:0>(com.apollographql.apollo3.api.json.JsonReader;com.apollographql.apollo3.api.CustomScalarAdapters){0§<com.apollographql.apollo3.api.Operation.Data>}com.apollographql.apollo3.api.ApolloResponse<0:0> + 636 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Operations.kt:59:25)
      at 12  MultiPlatformLibrary                0x000000010c785a5e kfun:com.apollographql.apollo3.network.http.HttpNetworkTransport.execute$lambda-1$lambda-0#internal + 526 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt:74:21)
      at 13  MultiPlatformLibrary                0x000000010c7879ea kfun:com.apollographql.apollo3.network.http.HttpNetworkTransport.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$271.invoke#internal + 154 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo3/network/http/HttpNetworkTransport.kt:72:29)
      at 14  MultiPlatformLibrary                0x000000010c7553d4 kfun:com.apollographql.apollo3.internal.GCDWorker.execute$lambda-1$lambda-0#internal + 452 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:16:7)
      at 15  MultiPlatformLibrary                0x000000010c755bb4 kfun:com.apollographql.apollo3.internal.GCDWorker.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$257.invoke#internal + 68 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:17:6)
      at 16  MultiPlatformLibrary                0x000000010c755ced kfun:com.apollographql.apollo3.internal.GCDWorker.$execute$lambda-1$lambda-0$FUNCTION_REFERENCE$257.$<bridge-UNN>invoke(){}#internal + 61 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:17:6)
      at 17  MultiPlatformLibrary                0x000000010c755dda _636f6d2e61706f6c6c6f6772617068716c2e61706f6c6c6f333a61706f6c6c6f2d72756e74696d65_knbridge353 + 202 (/Users/runner/work/apollo-kotlin/apollo-kotlin/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt:19:36)
      at 18  libdispatch.dylib                   0x000000010bf74848 _dispatch_call_block_and_release + 12
      at 19  libdispatch.dylib                   0x000000010bf75a2c _dispatch_client_callout + 8
      at 20  libdispatch.dylib                   0x000000010bf87bdd _dispatch_root_queue_drain + 887
      at 21  libdispatch.dylib                   0x000000010bf884c3 _dispatch_worker_thread2 + 196
      at 22  libsystem_pthread.dylib             0x000000010dd1c049 _pthread_wqthread + 256
      at 23  libsystem_pthread.dylib             0x000000010dd1b01b start_wqthread + 15

Nailik avatar Feb 15 '22 12:02 Nailik

Following up from a slack discussion. One nice use case for this is that it'd then be possible to configure the HTTP client in a multiplatform way instead of configuring OkHttp/NSUrlSession separately.

martinbonnin avatar Jul 07 '22 10:07 martinbonnin

@martinbonnin Do you have a plan to use Ktor for Apollo Kotlin Standard HTTP Client with Android, iOS, JS? With the release of Compose for iOS, demand is expected to increase.

sonatard avatar May 11 '23 05:05 sonatard

Note on this request. For Android theoretically the JS Http Engine could be used (by only removing the Js Parameter) https://github.com/apollographql/apollo-kotlin/blob/c6a16054c57e9c3b2c2c93f895d3169b37186d8a/apollo-runtime/src/jsMain/kotlin/com/apollographql/apollo3/network/http/KtorHttpEngine.kt

On iOS this results in an issue with the okio.Buffer because it is freezed. You get an kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen okio.Buffer@1ab1928 inside /apollo3/api/json/BufferedSourceJsonReader.kt:706:12 maybe the freeze occures inside the GCDWorker https://github.com/apollographql/apollo-kotlin/blob/c6a16054c57e9c3b2c2c93f895d3169b37186d8a/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo3/internal/GCDWorker.kt

Full Error output

With the new memory management of kmm the freezed problem should have changed. Also my other statement might not be accurate anymore.

Nailik avatar May 11 '23 06:05 Nailik

@sonatard it's not the current focus but pull requests are very welcome if someone wants to take a stab at it.

martinbonnin avatar May 11 '23 09:05 martinbonnin

@martinbonnin @BoD Thank you for merging #5142 ! This will allow us to reduce our dependency on Android. Stack Inc have paid a fee to yt8492 and asked for a contribution. We would like to continue contributing to Apollo Kotlin. Thank you.

sonatard avatar Aug 08 '23 10:08 sonatard

This is now available in 4.0.0-alpha.3 🎉

Many thanks @yt8492 and @sonatard for looking into this 💙

martinbonnin avatar Aug 09 '23 09:08 martinbonnin