I’m attempting to follow the Multiplatform example for Apollo.
No matter what I do, ApolloHttpNetworkTransport can’t be resolved in my sources.
Here’s the code snippet:
import com.apollographql.apollo3.ApolloClient
val apolloClient = ApolloClient(
networkTransport = ApolloHttpNetworkTransport(
serverUrl = "https://foo.com/graphql",
headers = mapOf(
"Accept" to "application/json",
"Content-Type" to "application/json",
"X-API-KEY" to "blah",
)
)
)
Searching google and SO yields no applicable result.
Here’s the build.gradle.kts from the root of the project:
buildscript {
val kotlinVersion: String by project
repositories {
gradlePluginPortal()
google()
mavenCentral()
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("com.android.tools.build:gradle:7.0.0")
classpath("com.apollographql.apollo3:apollo-gradle-plugin:${Versions.apollo}")
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
and from the shared
directory:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
id("com.apollographql.apollo3")
}
kotlin {
android()
val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iosTarget("ios") {
binaries {
framework {
baseName = "shared"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinxCoroutines}") {
isForce = true
}
api("com.apollographql.apollo3:apollo-runtime:${Versions.apollo}")
runtimeOnly("com.apollographql.apollo3:apollo-api:${Versions.apollo}")
implementation("com.apollographql.apollo:apollo-android-support:2.5.9")
implementation("io.ktor:ktor-client-core:${Versions.ktor}")
implementation("io.ktor:ktor-client-cio:${Versions.ktor}")
implementation("io.ktor:ktor-client-logging:${Versions.ktor}")
implementation("io.ktor:ktor-client-auth:${Versions.ktor}")
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.kotlinCoroutines}")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.kotlinxCoroutines}")
implementation("io.ktor:ktor-client-android:${Versions.ktor}")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
val iosMain by getting {
dependencies{
implementation("io.ktor:ktor-client-ios:${Versions.ktor}")
}
}
val iosTest by getting
}
}
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(23)
targetSdkVersion(30)
}
}
//dependencies {
// implementation(project(mapOf("path" to ":")))
// implementation(project(mapOf("path" to ":")))
//}
kotlin.sourceSets.all {
languageSettings.apply {
useExperimentalAnnotation("kotlin.RequiresOptIn")
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
useExperimentalAnnotation("com.apollographql.apollo3.api.ApolloExperimental")
}
}
apollo {
generateKotlinModels.set(true)
codegenModels.set("operationBased")
}
Ignore the ktor stuff. I was originally going to use ktor, but found out it doesn’t support TLS in native projects.
Any pointers?