GraphConverter

open class GraphConverter(graphProcessor: AbstractGraphProcessor, json: GraphQLJson, registry: GraphQLDocumentRegistry? = null) : Converter.Factory(source)

Deprecated

Legacy Gson/GraphQLJson-backed converter. Use GraphQLConverterFactory with an explicit GraphQLTransportCodec instead.

Body for GraphQL requests and responses, closed for modification but open for extension.

Legacy: this Gson/GraphQLJson-backed converter lives in :compat for backward compatibility with the historical artifact and the asset-based discovery flow. New code should use the backend-neutral GraphQLConverterFactory from :runtime with an explicit co.anitrend.retrofit.graphql.serialization.GraphQLTransportCodec.

Serialization Backend

As of v0.13.x, GraphConverter uses a pluggable GraphQLJson instance instead of a hard dependency on Gson. The json property provides the serialization backend for both request and response conversion. Factory methods accept either a GraphQLJson instance directly or a Gson instance (preserved for backward compatibility, internally wrapped in GsonGraphQLJson).

Factory Methods

Context-backed (5 overloads: 4 Gson preserved + 1 GraphQLJson new)

// Default Gson (backward compatible)
GraphConverter.create(context)
// Custom Gson (backward compatible)
GraphConverter.create(context, gson)
// Custom Gson + registry (backward compatible)
GraphConverter.create(context, gson, registry)
// Default Gson + registry (backward compatible)
GraphConverter.create(context, registry)
// NEW: Custom GraphQLJson + registry
GraphConverter.create(context, json, registry)

Registry-only, no Context (3 overloads: 2 Gson preserved + 1 GraphQLJson new)

// Default Gson (backward compatible)
GraphConverter.create(registry)
// Custom Gson (backward compatible)
GraphConverter.create(gson, registry)
// NEW: Custom GraphQLJson
GraphConverter.create(json, registry)

Extending

Subclass GraphConverter to customize request/response conversion:

class CustomGraphConverter(
processor: AbstractGraphProcessor,
json: GraphQLJson,
) : GraphConverter(processor, json) {
override fun responseBodyConverter(...) = CustomResponseConverter(...)
}

Parameters

graphProcessor

Processor used for asset-based lookup. Registry-only factory overloads provide a no-op implementation when no asset fallback is required.

json

Pluggable GraphQLJson instance used for request and response serialization. Replaces the v2.x gson: Gson parameter.

registry

Optional GraphQLDocumentRegistry for build-time generated operation documents.

See also

Constructors

Link copied to clipboard
constructor(graphProcessor: AbstractGraphProcessor, json: GraphQLJson, registry: GraphQLDocumentRegistry? = null)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun requestBodyConverter(type: Type, parameterAnnotations: Array<out Annotation>, methodAnnotations: Array<out Annotation>, retrofit: Retrofit): Converter<*, RequestBody>?

Response body converter delegates logic processing to a child class that handles wrapping and deserialization of the json response data.

Link copied to clipboard
open override fun responseBodyConverter(type: Type, annotations: Array<out Annotation>, retrofit: Retrofit): Converter<ResponseBody, *>?

Response body converter delegates logic processing to a child class that handles wrapping and deserialization of the json response data.

Link copied to clipboard
fun setLogLevel(logLevel: LogLevel)

Sets the minimum level for log messages. Attempted messages with a too low log level are skipped and not printed to the system log.

Link copied to clipboard

Overrides the minimum level for log messages on the logger.

Link copied to clipboard
open fun stringConverter(type: Type?, annotations: Array<out Annotation?>?, retrofit: Retrofit?): Converter<*, String?>?