All skills
apollographql avatar

/apollo-kotlin

@93b90fd official
by Apollo GraphQLapollographql/skills115 stars
13

Guide for building applications with Apollo Kotlin, the GraphQL client library for Android and Kotlin. Use this skill when: (1) setting up Apollo Kotlin in a Gradle project for Android, Kotlin/JVM, or KMP, (2) configuring schema download and codegen for GraphQL services, (3) configuring an `ApolloClient` with auth, interceptors, and caching, (4) writing queries, mutations, or subscriptions,

Use this Skill: https://skilld.dev/gh/apollographql/skills/apollo-kotlin

This session only. Nothing lands on disk.

referencessetup.md

≈883 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Setup

Use this guide to setup Apollo Kotlin and configure code generation and schema downloads.

Gradle

  • Prefer Apollo Kotlin 5, do not use v3 or older versions
  • Always use the latest version
  • To determine the latest version, execute scripts/list-apollo-kotlin-versions.sh and pick the latest release

Add the Apollo Kotlin Gradle plugin:

plugins {
  // Other Gradle plugins, including Android and Kotlin
  // ...

  // Apollo Kotlin Gradle plugin
  id("com.apollographql.apollo").version("LATEST_APOLLO_VERSION")
}

Add the runtime dependency:

dependencies {
  // Other dependencies
  // ...

  // Apollo runtime
  implementation("com.apollographql.apollo:apollo-runtime") // Note: no need to specify version here because the plugin will manage it
}

Service configuration

Define a service (one per GraphQL endpoint if multiple are needed).

apollo {
  service("service") {
    packageName.set("com.example.graphql")
  }
}

Custom scalars

Map custom scalars to Kotlin types and adapters.

apollo {
  service("service") {
    // ...
    mapScalar("GeoPoint", "com.example.graphql.GeoPoint", "com.example.graphql.GeoPointAdapter")
  }
}

Some commonly used scalars adapters are available in this library: https://github.com/apollographql/apollo-kotlin-adapters. Use it to avoid writing your own adapters for common types like BigDecimal, Instant. etc.

Schema management

Prefer a checked-in schema file so builds are reproducible.

Configure introspection schema download:

apollo {
  service("service") {
    // ...
    introspection {
      endpointUrl.set("https://your.domain/graphql")
      schemaFile.set(file("src/main/graphql/schema.graphqls"))
    }
  }
}

This creates a task downloadServiceApolloSchemaFromIntrospection that downloads the schema and saves it to the specified location.

Run it before writing operations:

./gradlew downloadServiceApolloSchemaFromIntrospection

Multi-module

If multiple modules are desirable, a few rules apply:

  • One and only one module can contain the schema (the "schema module"). This is the schema that all other modules ("feature modules") can reuse.
  • The schema module and modules that want to share fragment definitions must enable the generation of metadata with generateApolloMetadata.set(true).
  • Feature modules that depend on the schema module and/or other modules must declare those dependencies with dependsOn(project(":schema"))
  • Also add the reverse dependencies in the schema module with isADependencyOf(project(":feature")), so only the used types are generated in the schema module.

Project layout

A typical layout for an Android or JVM module:

src/main/graphql/
  GetUserQuery.graphql
  schema.graphqls
  extra.graphqls
src/main/kotlin/
  com/example/myapp/
    SomeClass.kt

For KMP:

src/commonMain/graphql/
  GetUserQuery.graphql
  schema.graphqls
  extra.graphqls
src/commonMain/kotlin/
  com/example/myapp/
    SomeClass.kt

Client setup

  • Keep a single ApolloClient (or one per service in a multiple services case) and inject it via DI.
  • Add auth headers in one place through interceptors.
  • Configure logging for dev builds only.
val apolloClient = ApolloClient.Builder()
  .serverUrl("https://your.domain/graphql")
  .addHttpInterceptor(AuthorizationInterceptor(token))
  .apply {
    if (isDebugBuild) {
      addHttpInterceptor(LoggingInterceptor(level = Level.BODY))
    }
  }
  .build()

Source: SKILL.md on GitHub

1 alert16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a comprehensive guide and supporting scripts for integrating Apollo Kotlin into Android, JVM, and Kotlin Multiplatform projects. All external resources, scripts, and dependencies are sourced from the official Apollo GraphQL organization or well-known services like GitHub.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    5/6 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 93b90fd. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 months ago
What it can do
Runs commands
compatibility
JVM 8+, Kotlin 1.9+, Gradle 8+, Android/JVM/Kotlin Multiplatform projects.
metadata
{
  "author": "apollographql",
  "version": "1.0.3"
}
All 1 allowed tools
Bash(./gradlew:*) Bash(gradle:*) Bash(curl:*) Read Write Edit Glob Grep WebFetch
  • apollo
  • graphql
  • kotlin
  • android
  • gradle
  • codegen
  • kmp
  • jvm
  • client

README badge

README badge for apollographql/skills/apollo-kotlin

Instructs an AI agent on setting up and using Apollo Kotlin, the strongly typed GraphQL client for Android, JVM, and Kotlin Multiplatform projects. Covers Gradle configuration, schema codegen, ApolloClient setup with auth and caching, and writing GraphQL operations. Targets Apollo Kotlin v5+ projects.

Generated from the current SKILL.md.

Does this skill work with Android, JVM, and Kotlin Multiplatform projects?
Yes. Apollo Kotlin supports Android, JVM, and Kotlin Multiplatform (KMP) projects. It requires JVM 8+, Kotlin 1.9+, and Gradle 8+.
What version of Apollo Kotlin should I use?
Use Apollo Kotlin v5 or later. The skill includes a migration guide from v4 but does not support v3 or older versions.
Can this skill help with schema download and code generation?
Yes. The skill covers Gradle plugin setup, schema download configuration, and code generation including custom scalar types.
Does this cover authentication and caching?
Yes. The skill includes guidance on configuring ApolloClient with auth, interceptors, and setting up the normalized cache.
Can I use this skill for queries, mutations, and subscriptions?
Yes. The skill covers implementing and executing queries, mutations, and subscriptions in Apollo Kotlin.

Generated from the current SKILL.md. These answers refresh after source changes.