-
Notifications
You must be signed in to change notification settings - Fork 13
Home
Maxwell edited this page Aug 2, 2026
·
9 revisions
retrofit-graphql is a Retrofit converter that injects .graphql query or mutation file contents into a request body along with any GraphQL variables. It supports runtime asset-based discovery and optional build-time code generation for type-safe request helpers.
- Automated persisted queries (APQ)
- GraphQL fragment resolution (resolves fragment references)
- Customizable logger (allows you to add a custom logger)
- Customizable discovery plugin (allows you to define where and how to look for graphql files)
- Backend-neutral request/response contracts (
GraphQLOperationRequest,GraphQLResponse) with explicit transport codecs - Optional build-time code generation (operation constants, document registry, variable classes, response DTOs)
-
GraphQLConverterFactory(:runtime) requires an explicitGraphQLTransportCodec(GsonGraphQLTransportCodecorKotlinxGraphQLTransportCodec) on every creation path. - Requests are
GraphQLOperationRequest<TVariables>; responses areGraphQLResponse<T>withGraphQLData.AbsentvsPresent(null), typed error paths, andGraphQLValueextensions. -
:apicarries no serializer, Gson, or kotlinx dependency.
- The legacy
GraphConverter/GraphQLJson/GraphContainer/QueryContainerBuildersurface and the 37io.github.wax911.library.*type aliases are deprecated but remain source- and binary-compatible, shipped exactly once from:compat(reachable through the deprecated:libraryaggregator). - Use it for existing asset-based
@GraphQueryflows; new code should use the backend-neutral path.
- Register for an API key for the client, follow this guide
- After acquiring an API key put it in the following directory
./app/.config/secrets.propertieswith the following format:token="YOUR_API_TOKEN_KEY_GOES_HERE"
See GraphQL File Uploads if you want to test that too.
The library is split into composable modules. The old :library aggregator is deprecated but still available for backward compatibility. See the Migration Guide for details on upgrading your project.
New capabilities:
-
Code Generation Plugin — Replace
.graphqlfiles inassets/with build-time generated types. Applyid("co.anitrend.retrofit.graphql.codegen")to your project. See Code Generation for the full guide. -
Type-Safe Request Helpers — Generated operation objects provide
.request(...)factory methods returning the backend-neutralGraphQLOperationRequest<TVariables>with named, type-safe parameters. -
Optional Response Models — Enable
generateResponsesto generate{OperationName}Dataclasses that match each operation's JSON shape, including aliases, conditionals, and abstract GraphQL types. Annotations are emitted per the strictserializationBackendsetting (NONE/KOTLINX/GSON);NONEis never auto-selected or upgraded. - Enum Class Generation — GraphQL enum types generate as Kotlin enum classes.
-
Scalar Mappings — Map custom GraphQL scalars to Kotlin types via
scalars { map("DateTime", "kotlin.String") }in the DSL. - Smaller Footprint — Depend only on the modules your project needs.
-
Registry-Based Resolution — Wire a
GraphQLDocumentRegistryinto the converter for faster query resolution without asset scanning.
- Code Generation — Full codegen DSL reference and generated output guide
- Switching to Codegen — Migrate from asset-based to codegen workflow
-
Migration Guide — Migrating from
:libraryto modular dependencies - Serialization Backends — Codegen annotation setting vs runtime transport codecs
- Generated Response DTOs — Using generated response models with Retrofit
- R8 / ProGuard — R8 configuration and keep rules
- Parameterized Types — How parameterized types flow through serialization
- Naming Contract — Kotlin name, wire name, and descriptor behavior rules
- Sample: Getting Started — Quick start with codegen or asset-based workflows
- Sample: GraphQL File Uploads — Multipart upload patterns
- Sample: Persisted Queries — Automatic Persisted Queries (APQ) setup