GraphContainer
Deprecated
Legacy serializer-coupled response wrapper. Use GraphQLResponse with the backend-neutral GraphQLConverterFactory instead.
GraphQL response that is spec compliant.
Legacy: this serializer-coupled response wrapper lives in :compat for the deprecated co.anitrend.retrofit.graphql.converter.GraphConverter flow. New code should use the backend-neutral co.anitrend.retrofit.graphql.model.GraphQLResponse contract with co.anitrend.retrofit.graphql.converter.GraphQLConverterFactory.
This is the top-level response wrapper used as the Retrofit return type for GraphQL operations. It is annotated with kotlinx.serialization.Serializable to enable direct deserialization by KotlinxGraphQLJson when Retrofit passes a parameterized type like GraphContainer<GetCurrentUserData>.
Serialization Behavior
kotlinx.serialization
data is deserialized using the type parameter
T(requires@SerializableonT)errors is deserialized via GraphError which is
@Serializableextensions is
@Transient(excluded) becauseMap<Any, Any>cannot be statically resolved by the kotlinx compiler plugin
Gson (via GsonGraphQLJson)
All fields are serialized/deserialized normally, including extensions
Accessing extensions with kotlinx
To read extensions while using kotlinx serialization, define your own @Serializable response wrapper with concrete JSON element types. No custom serializer is required unless the actual wire structure needs transformation:
@Serializable
data class JsonGraphContainer<T>(
val data: T? = null,
val errors: List<JsonGraphError>? = null,
val extensions: JsonObject? = null,
)
@Serializable
data class JsonGraphError(
val message: String? = null,
val path: List<JsonElement>? = null,
val locations: List<GraphError.Location>? = null,
val extensions: JsonObject? = null,
)
@POST("graphql")
suspend fun getCurrentUser(
@Body request: GraphQLRequest<EmptyGraphQLVariables>
): Response<JsonGraphContainer<GetCurrentUserData>>Alternatively, extract extension values from the raw JSON payload before kotlinx deserialization runs.
Usage with generated response DTOs
@POST("graphql")
suspend fun getCurrentUser(
@Body request: GraphQLRequest<EmptyGraphQLVariables>
): Response<GraphContainer<GetCurrentUserData>>Parameters
The successful response data, or null if the response contains only errors.
A list of GraphQL errors, or null if the response is successful. Each error is deserialized via GraphError.
The response extensions map. Gson-only; @Transient for kotlinx.
See also
Functions
Returns the non-null GraphContainer.data or throws GraphQLResponseException if the response contains errors.