commonMain.com.apollographql.apollo3.api.ApolloRequest.kt Maven / Gradle / Ivy
package com.apollographql.apollo3.api
import com.apollographql.apollo3.annotations.ApolloExperimental
import com.apollographql.apollo3.annotations.ApolloInternal
import com.apollographql.apollo3.api.http.HttpHeader
import com.apollographql.apollo3.api.http.HttpMethod
import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
/**
* A GraphQL request to execute. Execution can be customized with [executionContext]
*/
class ApolloRequest
private constructor(
val operation: Operation,
val requestUuid: Uuid,
override val executionContext: ExecutionContext,
override val httpMethod: HttpMethod?,
override val httpHeaders: List?,
override val sendApqExtensions: Boolean?,
override val sendDocument: Boolean?,
override val enableAutoPersistedQueries: Boolean?,
override val canBeBatched: Boolean?,
@ApolloInternal
val useV3ExceptionHandling: Boolean?,
) : ExecutionOptions {
fun newBuilder(): Builder = newBuilder(operation)
@ApolloExperimental
fun newBuilder(operation: Operation): Builder {
@Suppress("DEPRECATION")
return Builder(operation)
.requestUuid(requestUuid)
.executionContext(executionContext)
.httpMethod(httpMethod)
.httpHeaders(httpHeaders)
.sendApqExtensions(sendApqExtensions)
.sendDocument(sendDocument)
.enableAutoPersistedQueries(enableAutoPersistedQueries)
.canBeBatched(canBeBatched)
.useV3ExceptionHandling(useV3ExceptionHandling)
}
class Builder(
private var operation: Operation,
) : MutableExecutionOptions> {
private var requestUuid: Uuid = uuid4()
override var executionContext: ExecutionContext = ExecutionContext.Empty
private set
override var httpMethod: HttpMethod? = null
private set
override fun httpMethod(httpMethod: HttpMethod?): Builder = apply {
this.httpMethod = httpMethod
}
override var httpHeaders: List? = null
private set
override fun httpHeaders(httpHeaders: List?): Builder = apply {
this.httpHeaders = httpHeaders
}
override fun addHttpHeader(name: String, value: String): Builder = apply {
this.httpHeaders = (this.httpHeaders ?: emptyList()) + HttpHeader(name, value)
}
override var sendApqExtensions: Boolean? = null
private set
override fun sendApqExtensions(sendApqExtensions: Boolean?): Builder = apply {
this.sendApqExtensions = sendApqExtensions
}
override var sendDocument: Boolean? = null
private set
override fun sendDocument(sendDocument: Boolean?): Builder = apply {
this.sendDocument = sendDocument
}
override var enableAutoPersistedQueries: Boolean? = null
private set
override fun enableAutoPersistedQueries(enableAutoPersistedQueries: Boolean?): Builder = apply {
this.enableAutoPersistedQueries = enableAutoPersistedQueries
}
override var canBeBatched: Boolean? = null
private set
override fun canBeBatched(canBeBatched: Boolean?): Builder = apply {
this.canBeBatched = canBeBatched
}
private var useV3ExceptionHandling: Boolean? = null
@ApolloInternal
fun useV3ExceptionHandling(useV3ExceptionHandling: Boolean?): Builder = apply {
this.useV3ExceptionHandling = useV3ExceptionHandling
}
fun requestUuid(requestUuid: Uuid) = apply {
this.requestUuid = requestUuid
}
fun executionContext(executionContext: ExecutionContext) = apply {
this.executionContext = executionContext
}
override fun addExecutionContext(executionContext: ExecutionContext) = apply {
this.executionContext = this.executionContext + executionContext
}
fun build(): ApolloRequest {
@Suppress("DEPRECATION")
return ApolloRequest(
operation = operation,
requestUuid = requestUuid,
executionContext = executionContext,
httpMethod = httpMethod,
httpHeaders = httpHeaders,
sendApqExtensions = sendApqExtensions,
sendDocument = sendDocument,
enableAutoPersistedQueries = enableAutoPersistedQueries,
canBeBatched = canBeBatched,
useV3ExceptionHandling = useV3ExceptionHandling,
)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy