commonMain.com.apollographql.apollo.cache.CacheHeaders.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-normalized-cache-api-jvm Show documentation
Show all versions of apollo-normalized-cache-api-jvm Show documentation
Apollo GraphQL Normalized Cache Common APIs
package com.apollographql.apollo.cache
import com.apollographql.apollo.api.Operation
import com.apollographql.apollo.cache.normalized.NormalizedCache
import com.apollographql.apollo.cache.normalized.Record
import kotlin.jvm.JvmField
import kotlin.jvm.JvmStatic
/**
* A key/value collection which is sent with [Record] from a [Operation] to the [NormalizedCache].
*
* For headers which the default [NormalizedCache] respect, see [ApolloCacheHeaders].
*/
class CacheHeaders internal constructor(private val headerMap: Map) {
class Builder {
private val headerMap = mutableMapOf()
fun addHeader(headerName: String, headerValue: String) = apply {
headerMap[headerName] = headerValue
}
fun addHeaders(headerMap: Map) = apply {
this.headerMap.putAll(headerMap)
}
fun build() = CacheHeaders(headerMap)
}
/**
* @return A [CacheHeaders.Builder] with a copy of this [CacheHeaders] values.
*/
fun toBuilder(): Builder = builder().addHeaders(headerMap)
fun headerValue(header: String): String? = headerMap[header]
fun hasHeader(headerName: String): Boolean = headerMap.containsKey(headerName)
companion object {
@JvmStatic
fun builder() = Builder()
@JvmField
val NONE = CacheHeaders(emptyMap())
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy