Launch Apollo Studio

Get started with Multiplatform (Experimental)

Note: Multiplatform support is experimental and still under heavy development, expect the API to change. If you have feedback, we'd love to hear it. Please see Contributing.md for how to get in touch.

You can also check out the multiplatform samples for more details.

Kotlin multiplatform allows to use the same queries and generated models on both Android and iOS. On Android it uses OkHttp to handle the HTTP calls. On iOS, it uses NSUrlConnection.

Add the Gradle plugin

In your app Gradle file, apply the com.apollographql.apollo plugin:

Using the plugins DSL:

plugins {
  // ...

Or using the legacy syntax:

buildscript {
  // ...

apply(plugin = "com.apollographql.apollo")

The plugin is hosted on the Gradle plugin portal, Jcenter and Maven Central.

Add the runtime dependencies

Multiplatform uses a different artifact from apollo-runtime. Its goal is to offer a coroutine-first API and is named apollo-runtime-kotlin:

kotlin {
  // targets

  sourceSets {
    commonMain {
      dependencies {

Download your schema.json file

Apollo Android requires your GraphQL server's schema as a schema.json file. You can obtain the contents of this file by running an introspection query on your server.

The Apollo Gradle plugin exposes a downloadApolloSchema task to help you obtain your schema. Provide this task your server's GraphQL endpoint and the output location for the schema.json file:

./gradlew downloadApolloSchema \
  --endpoint="https://your.domain/graphql/endpoint" \

If your GraphQL endpoint requires authentication, you can pass custom HTTP headers:

./gradlew downloadApolloSchema \
  --endpoint="https://your.domain/graphql/endpoint" \
  --schema="app/src/main/graphql/com/example" \
  --header="Authorization: Bearer $TOKEN"

Add your query

Add your schema.json and other .graphql files under src/commonMain/graphql. Build your module and generated code will be available under commonMain sourceSet. That means you can use them both in commonMain or platform specific Kotlin code. Once the Kotlin plugin builds the iOS Framework, generated code can even be called from Swift code.

Executing your query

You use an instance of the ApolloClient class to interact with your server and cache.

To make a query using your generated models:

// First, create an `ApolloClient`
// Replace the serverUrl with your GraphQL endpoint
  val apolloClient = ApolloClient(
      networkTransport = ApolloHttpNetworkTransport(
          serverUrl = "https://your.domain/graphql/endpoint",
          headers = mapOf(
              "Accept" to "application/json",
              "Content-Type" to "application/json",

// in your coroutine scope, call `ApolloClient.query(...).execute()`
scope.launch {
  // execute() returns a Flow, here we only take the first item
  val response = apolloClient.query(LaunchDetailsQuery(id = "83")).execute().single()

  // launch now contains a typesafe model of your data
  println("Launch site: ${response.data?.launch?.site"})
Edit on GitHub