commonMain.com.apollographql.apollo3.api.ApolloRequest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-api-jvm Show documentation
Show all versions of apollo-api-jvm Show documentation
Apollo GraphQL API classes
package com.apollographql.apollo3.api
import com.apollographql.apollo3.annotations.ApolloExperimental
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?,
) : ExecutionOptions {
fun newBuilder(): Builder = newBuilder(operation)
@ApolloExperimental
fun newBuilder(operation: Operation): Builder {
return Builder(operation)
.requestUuid(requestUuid)
.executionContext(executionContext)
.httpMethod(httpMethod)
.httpHeaders(httpHeaders)
.sendApqExtensions(sendApqExtensions)
.sendDocument(sendDocument)
.enableAutoPersistedQueries(enableAutoPersistedQueries)
.canBeBatched(canBeBatched)
}
class Builder(
private var operation: Operation,
) : MutableExecutionOptions> {
private var requestUuid: Uuid = uuid4()
override var executionContext: ExecutionContext = ExecutionContext.Empty
override var httpMethod: HttpMethod? = null
override fun httpMethod(httpMethod: HttpMethod?): Builder = apply {
this.httpMethod = httpMethod
}
override var httpHeaders: List? = null
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
override fun sendApqExtensions(sendApqExtensions: Boolean?): Builder = apply {
this.sendApqExtensions = sendApqExtensions
}
override var sendDocument: Boolean? = null
override fun sendDocument(sendDocument: Boolean?): Builder = apply {
this.sendDocument = sendDocument
}
override var enableAutoPersistedQueries: Boolean? = null
override fun enableAutoPersistedQueries(enableAutoPersistedQueries: Boolean?): Builder = apply {
this.enableAutoPersistedQueries = enableAutoPersistedQueries
}
override var canBeBatched: Boolean? = null
override fun canBeBatched(canBeBatched: Boolean?): Builder = apply {
this.canBeBatched = canBeBatched
}
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,
)
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy