Skip to content

Commit 99039c4

Browse files
authored
Add deprecations on symbols that are getting removed in v4 (#5746)
* Add deprecations on symbols that are getting removed in v4 * Update API dump * Next version is v3.8.3, not v3.8.4 * Un-deprecate CustomScalarAdapters.adapterContext as it's used in generated code, and it's probably not worth adding @Suppress("DEPRECATION") everywhere
1 parent 9121f3b commit 99039c4

File tree

16 files changed

+179
-17
lines changed

16 files changed

+179
-17
lines changed

libraries/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/ApolloRequest.kt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.apollographql.apollo3.api
22

3+
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince
4+
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_8_3
35
import com.apollographql.apollo3.annotations.ApolloExperimental
46
import com.apollographql.apollo3.api.http.HttpHeader
57
import com.apollographql.apollo3.api.http.HttpMethod
@@ -25,7 +27,7 @@ private constructor(
2527
fun newBuilder(): Builder<D> = newBuilder(operation)
2628

2729
@ApolloExperimental
28-
fun <E: Operation.Data> newBuilder(operation: Operation<E>): Builder<E> {
30+
fun <E : Operation.Data> newBuilder(operation: Operation<E>): Builder<E> {
2931
return Builder(operation)
3032
.requestUuid(requestUuid)
3133
.executionContext(executionContext)
@@ -43,44 +45,72 @@ private constructor(
4345
) : MutableExecutionOptions<Builder<D>> {
4446
private var requestUuid: Uuid = uuid4()
4547
override var executionContext: ExecutionContext = ExecutionContext.Empty
48+
@Deprecated("Use addExecutionContext() instead")
49+
@ApolloDeprecatedSince(v3_8_3)
50+
set
4651

4752
override var httpMethod: HttpMethod? = null
53+
@Deprecated("Use httpMethod() instead")
54+
@ApolloDeprecatedSince(v3_8_3)
55+
set
4856

4957
override fun httpMethod(httpMethod: HttpMethod?): Builder<D> = apply {
58+
@Suppress("DEPRECATION")
5059
this.httpMethod = httpMethod
5160
}
5261

5362
override var httpHeaders: List<HttpHeader>? = null
63+
@Deprecated("Use httpHeaders() instead")
64+
@ApolloDeprecatedSince(v3_8_3)
65+
set
5466

5567
override fun httpHeaders(httpHeaders: List<HttpHeader>?): Builder<D> = apply {
68+
@Suppress("DEPRECATION")
5669
this.httpHeaders = httpHeaders
5770
}
5871

5972
override fun addHttpHeader(name: String, value: String): Builder<D> = apply {
73+
@Suppress("DEPRECATION")
6074
this.httpHeaders = (this.httpHeaders ?: emptyList()) + HttpHeader(name, value)
6175
}
6276

6377
override var sendApqExtensions: Boolean? = null
78+
@Deprecated("Use sendApqExtensions() instead")
79+
@ApolloDeprecatedSince(v3_8_3)
80+
set
6481

6582
override fun sendApqExtensions(sendApqExtensions: Boolean?): Builder<D> = apply {
83+
@Suppress("DEPRECATION")
6684
this.sendApqExtensions = sendApqExtensions
6785
}
6886

6987
override var sendDocument: Boolean? = null
88+
@Deprecated("Use sendDocument() instead")
89+
@ApolloDeprecatedSince(v3_8_3)
90+
set
7091

7192
override fun sendDocument(sendDocument: Boolean?): Builder<D> = apply {
93+
@Suppress("DEPRECATION")
7294
this.sendDocument = sendDocument
7395
}
7496

7597
override var enableAutoPersistedQueries: Boolean? = null
98+
@Deprecated("Use enableAutoPersistedQueries() instead")
99+
@ApolloDeprecatedSince(v3_8_3)
100+
set
76101

77102
override fun enableAutoPersistedQueries(enableAutoPersistedQueries: Boolean?): Builder<D> = apply {
103+
@Suppress("DEPRECATION")
78104
this.enableAutoPersistedQueries = enableAutoPersistedQueries
79105
}
80106

81107
override var canBeBatched: Boolean? = null
108+
@Deprecated("Use canBeBatched() instead")
109+
@ApolloDeprecatedSince(v3_8_3)
110+
set
82111

83112
override fun canBeBatched(canBeBatched: Boolean?): Builder<D> = apply {
113+
@Suppress("DEPRECATION")
84114
this.canBeBatched = canBeBatched
85115
}
86116

@@ -89,15 +119,16 @@ private constructor(
89119
}
90120

91121
fun executionContext(executionContext: ExecutionContext) = apply {
122+
@Suppress("DEPRECATION")
92123
this.executionContext = executionContext
93124
}
94125

95126
override fun addExecutionContext(executionContext: ExecutionContext) = apply {
127+
@Suppress("DEPRECATION")
96128
this.executionContext = this.executionContext + executionContext
97129
}
98130

99131
fun build(): ApolloRequest<D> {
100-
@Suppress("DEPRECATION")
101132
return ApolloRequest(
102133
operation = operation,
103134
requestUuid = requestUuid,

libraries/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CompiledGraphQL.kt

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.apollographql.apollo3.api
55
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince
66
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_0_1
77
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_3_3
8+
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_8_3
89
import com.apollographql.apollo3.annotations.ApolloExperimental
910
import com.apollographql.apollo3.api.json.BufferedSinkJsonWriter
1011
import com.apollographql.apollo3.api.json.writeAny
@@ -36,6 +37,7 @@ class CompiledField internal constructor(
3637
name: String,
3738
variables: Executable.Variables,
3839
): Any? {
40+
@Suppress("DEPRECATION")
3941
return resolveVariables(arguments.firstOrNull { it.name == name }?.value, variables)
4042
}
4143

@@ -55,6 +57,7 @@ class CompiledField internal constructor(
5557
return name
5658
}
5759
val map = arguments.associateBy { it.name }.mapValues { it.value.value }
60+
@Suppress("DEPRECATION")
5861
val resolvedArguments = resolveVariables(map, variables)
5962
return try {
6063
val buffer = Buffer()
@@ -136,7 +139,7 @@ class CompiledFragment internal constructor(
136139
}
137140

138141
data class CompiledCondition(val name: String, val inverted: Boolean, val defaultValue: Boolean) {
139-
constructor(name: String, inverted: Boolean): this(name, inverted, true)
142+
constructor(name: String, inverted: Boolean) : this(name, inverted, true)
140143

141144
fun copy(name: String = this.name, inverted: Boolean = this.inverted) = CompiledCondition(name, inverted, defaultValue)
142145
}
@@ -168,7 +171,7 @@ sealed class CompiledNamedType(val name: String) : CompiledType() {
168171
/**
169172
* A GraphQL scalar type that is mapped to a Kotlin. This is named "Custom" for historical reasons
170173
* but is also used for builtin scalars
171-
*
174+
*
172175
* TODO v4: rename this to ScalarType
173176
*/
174177
class CustomScalarType(
@@ -302,11 +305,11 @@ class InputObjectType(
302305

303306
class EnumType(
304307
name: String,
305-
val values: List<String>
308+
val values: List<String>,
306309
) : CompiledNamedType(name) {
307310
@Deprecated("Use the primary constructor instead")
308311
@ApolloDeprecatedSince(ApolloDeprecatedSince.Version.v3_5_1)
309-
constructor(name: String): this(name, emptyList())
312+
constructor(name: String) : this(name, emptyList())
310313
}
311314

312315
/**
@@ -383,13 +386,16 @@ class CompiledArgument private constructor(
383386
/**
384387
* Resolve all variables that may be contained inside `value`
385388
*/
386-
@Suppress("UNCHECKED_CAST")
389+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
390+
@ApolloDeprecatedSince(v3_8_3)
391+
@Suppress("UNCHECKED_CAST", "DEPRECATION")
387392
fun resolveVariables(value: Any?, variables: Executable.Variables): Any? {
388393
return when (value) {
389394
null -> null
390395
is CompiledVariable -> {
391396
variables.valueMap[value.name]
392397
}
398+
393399
is Map<*, *> -> {
394400
value as Map<String, Any?>
395401
value.mapValues {
@@ -398,11 +404,13 @@ fun resolveVariables(value: Any?, variables: Executable.Variables): Any? {
398404
.sortedBy { it.first }
399405
.toMap()
400406
}
407+
401408
is List<*> -> {
402409
value.map {
403410
resolveVariables(it, variables)
404411
}
405412
}
413+
406414
else -> value
407415
}
408416
}
@@ -467,6 +475,7 @@ fun CompiledNamedType.isComposite(): Boolean {
467475
is InterfaceType,
468476
is ObjectType,
469477
-> true
478+
470479
else
471480
-> false
472481
}

libraries/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/CustomScalarAdapters.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ class CustomScalarAdapters private constructor(
1616
// This is currently used for @skip/@include and @defer.
1717
// Ideally it should be passed as its own parameter, but we're avoiding a breaking change.
1818
// See https://github.com/apollographql/apollo-kotlin/pull/3813
19+
/**
20+
* Note: this shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.
21+
*/
1922
val adapterContext: AdapterContext,
20-
private val unsafe: Boolean
23+
private val unsafe: Boolean,
2124
) : ExecutionContext.Element {
2225

2326
private val adaptersMap: Map<String, Adapter<*>> = customScalarAdapters
@@ -62,6 +65,7 @@ class CustomScalarAdapters private constructor(
6265

6366
@Deprecated("Use adapterContext.variables() instead", ReplaceWith("adapterContext.variables()"))
6467
@ApolloDeprecatedSince(v3_2_1)
68+
@Suppress("DEPRECATION")
6569
fun variables() = adapterContext.variables()
6670

6771
override val key: ExecutionContext.Key<*>
@@ -120,7 +124,6 @@ class CustomScalarAdapters private constructor(
120124
adaptersMap.clear()
121125
}
122126

123-
@Suppress("DEPRECATION")
124127
fun build() = CustomScalarAdapters(adaptersMap, adapterContext, unsafe)
125128

126129
fun adapterContext(adapterContext: AdapterContext): Builder = apply {

libraries/apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/Executables.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.apollographql.apollo3.api.json.MapJsonWriter
88
import okio.Buffer
99
import kotlin.jvm.JvmName
1010

11-
@Suppress("UNCHECKED_CAST")
1211
fun <D : Executable.Data> Executable<D>.variables(customScalarAdapters: CustomScalarAdapters): Executable.Variables {
1312
return variables(customScalarAdapters, false)
1413
}

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo3/gradle/api/Service.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.android.build.gradle.api.BaseVariant
44
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince
55
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_0_0
66
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_0_1
7+
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_8_3
78
import com.apollographql.apollo3.annotations.ApolloExperimental
89
import com.apollographql.apollo3.compiler.OperationIdGenerator
910
import com.apollographql.apollo3.compiler.OperationOutputGenerator
@@ -334,6 +335,8 @@ interface Service {
334335
*
335336
* Default value: false
336337
*/
338+
@Deprecated("Used for backward compat with 2.x, will be removed in a future version")
339+
@ApolloDeprecatedSince(v3_8_3)
337340
val useSchemaPackageNameForFragments: Property<Boolean>
338341

339342
/**
@@ -540,8 +543,10 @@ interface Service {
540543
* The directory where the test builders will be written.
541544
* If you want a [DirectoryProperty] that carries the task dependency, use [outputDirConnection]
542545
*/
546+
@Deprecated("Test builders are operation based and generate a lot of code. Use data builders instead")
547+
@ApolloDeprecatedSince(v3_8_3)
543548
val testDir: DirectoryProperty
544-
549+
545550
/**
546551
* Whether to generate the operationOutput.json
547552
*
@@ -853,6 +858,8 @@ interface Service {
853858
* - commonTest sourceSet for Kotlin multiplatform projects
854859
* - test *and* androidTest variants for Android projects
855860
*/
861+
@Deprecated("Test builders are operation based and generate a lot of code. Use data builders instead")
862+
@ApolloDeprecatedSince(v3_8_3)
856863
fun testDirConnection(action: Action<in DirectoryConnection>)
857864

858865
/**

libraries/apollo-http-cache/src/main/kotlin/com/apollographql/apollo3/cache/http/CachingHttpInterceptor.kt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.apollographql.apollo3.cache.http
22

33
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince
4+
import com.apollographql.apollo3.annotations.ApolloDeprecatedSince.Version.v3_8_3
45
import com.apollographql.apollo3.api.http.DefaultHttpRequestComposer
56
import com.apollographql.apollo3.api.http.HttpHeader
67
import com.apollographql.apollo3.api.http.HttpMethod
@@ -33,6 +34,7 @@ class CachingHttpInterceptor internal constructor(
3334

3435
val cache: ApolloHttpCache = lruHttpCache
3536

37+
@Suppress("DEPRECATION")
3638
override suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse {
3739
val policy = request.headers.valueOf(CACHE_FETCH_POLICY_HEADER) ?: defaultPolicy(request)
3840
val cacheKey = request.headers.valueOf(CACHE_KEY_HEADER)!!
@@ -98,6 +100,7 @@ class CachingHttpInterceptor internal constructor(
98100
}
99101
}
100102

103+
@Suppress("DEPRECATION")
101104
private fun defaultPolicy(request: HttpRequest): String {
102105
return if (request.headers.firstOrNull { it.name == CACHE_OPERATION_TYPE_HEADER }?.value == "query") {
103106
CACHE_FIRST
@@ -106,6 +109,7 @@ class CachingHttpInterceptor internal constructor(
106109
}
107110
}
108111

112+
@Suppress("DEPRECATION")
109113
private suspend fun networkMightThrow(request: HttpRequest, chain: HttpInterceptorChain, cacheKey: String): HttpResponse {
110114
val response = chain.proceed(request)
111115

@@ -127,6 +131,7 @@ class CachingHttpInterceptor internal constructor(
127131
return response
128132
}
129133

134+
@Suppress("DEPRECATION")
130135
private fun cacheMightThrow(request: HttpRequest, cacheKey: String): HttpResponse {
131136
val operationName = request.headers.valueOf(DefaultHttpRequestComposer.HEADER_APOLLO_OPERATION_NAME)
132137
val response = try {
@@ -193,51 +198,75 @@ class CachingHttpInterceptor internal constructor(
193198
}
194199
}
195200

196-
/**
197-
*
198-
*/
201+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
202+
@ApolloDeprecatedSince(v3_8_3)
199203
const val CACHE_KEY_HEADER = "X-APOLLO-CACHE-KEY"
200204

201205
internal const val REQUEST_UUID_HEADER = "X-APOLLO-REQUEST-UUID"
202206

203207
/**
204208
* Cache fetch strategy http header
205209
*/
210+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
211+
@ApolloDeprecatedSince(v3_8_3)
206212
const val CACHE_FETCH_POLICY_HEADER = "X-APOLLO-CACHE-FETCH-POLICY"
207213

208214
/**
209215
* Cache operation type http header
210216
*/
217+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
218+
@ApolloDeprecatedSince(v3_8_3)
211219
const val CACHE_OPERATION_TYPE_HEADER = "X-APOLLO-CACHE-OPERATION-TYPE"
212220

221+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
222+
@ApolloDeprecatedSince(v3_8_3)
213223
const val CACHE_ONLY = "CACHE_ONLY"
224+
225+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
226+
@ApolloDeprecatedSince(v3_8_3)
214227
const val NETWORK_ONLY = "NETWORK_ONLY"
228+
229+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
230+
@ApolloDeprecatedSince(v3_8_3)
215231
const val CACHE_FIRST = "CACHE_FIRST"
232+
233+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
234+
@ApolloDeprecatedSince(v3_8_3)
216235
const val NETWORK_FIRST = "NETWORK_FIRST"
217236

218237
/**
219238
* Request served Date/time http header
220239
*/
240+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
241+
@ApolloDeprecatedSince(v3_8_3)
221242
const val CACHE_SERVED_DATE_HEADER = "X-APOLLO-SERVED-DATE"
222243

223244
/**
224245
* Cached response expiration timeout http header (in millisecond)
225246
*/
247+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
248+
@ApolloDeprecatedSince(v3_8_3)
226249
const val CACHE_EXPIRE_TIMEOUT_HEADER = "X-APOLLO-EXPIRE-TIMEOUT"
227250

228251
/**
229252
* Expire cached response flag http header
230253
*/
254+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
255+
@ApolloDeprecatedSince(v3_8_3)
231256
const val CACHE_EXPIRE_AFTER_READ_HEADER = "X-APOLLO-EXPIRE-AFTER-READ"
232257

233258
/**
234259
* Do not store the http response
235260
*/
261+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
262+
@ApolloDeprecatedSince(v3_8_3)
236263
const val CACHE_DO_NOT_STORE = "X-APOLLO-CACHE-DO-NOT-STORE"
237264

238265
/**
239266
* Signals that HTTP response comes from the local cache
240267
*/
268+
@Deprecated("This shouldn't be part of the public API and will be removed in Apollo Kotlin 4. If you needed this, please open an issue.")
269+
@ApolloDeprecatedSince(v3_8_3)
241270
const val FROM_CACHE = "X-APOLLO-FROM-CACHE"
242271
}
243272
}

0 commit comments

Comments
 (0)