Skip to content

Commit 3b61312

Browse files
martinbonninBoD
andauthored
[docs] Update migration guide (#6009)
* update migration guide * Update docs/source/migration/4.0.mdx Co-authored-by: Benoit 'BoD' Lubek <[email protected]> --------- Co-authored-by: Benoit 'BoD' Lubek <[email protected]>
1 parent fd7f409 commit 3b61312

File tree

2 files changed

+68
-64
lines changed

2 files changed

+68
-64
lines changed

docs/source/migration/4.0.mdx

Lines changed: 68 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,53 @@ description: From version 3
1111

1212
Apollo Kotlin 3 was a major rewrite of Apollo in Kotlin multiplatform.
1313

14-
Apollo Kotlin 4 focuses on tooling, stability and fixing some API regrets that came with 3.
15-
16-
While most of the common APIs stayed the same, Apollo Kotlin 4 contains a few binary breaking changes. To account for that, and in order to be more future proof, we [changed the package name](https://github.com/apollographql/apollo-kotlin/issues/4710) to `com.apollographql.apollo`.
14+
Apollo Kotlin 4 focuses on tooling, stability and making the library more maintainable, so it can evolve smoothly for the many years to come.
1715

1816
Apollo Kotlin 4 removes some deprecated symbols. We strongly recommend removing deprecated usages before migrating to version 4.
1917

20-
If you are using a library that depends on Apollo Kotlin transitively, you need it to update to version 4 before you can update your own application to version 4.
21-
22-
## Automatic migration using the Android Studio plugin
18+
## Automatic migration using the Android Studio/IntelliJ plugin
2319

24-
Apollo Kotlin 4 ships with a companion [Android Studio plugin](../testing/android-studio-plugin#migration-helpers) that automates most of the migration.
20+
Apollo Kotlin 4 ships with a companion [Android Studio/IntelliJ plugin](../testing/android-studio-plugin#migration-helpers) that automates most of the migration.
2521

2622
It automates most of the API changes but cannot deal with behavior changes like error handling.
2723

2824
We recommend using the plugin to automate the repetitive tasks but still go through this document for the details.
2925

30-
## Error handling
26+
## Moved artifacts
27+
28+
Over the years, a lot of support functionality was added alongside the `apollo-api` and `apollo-runtime` artifacts. While useful, most of this functionality doesn't share the same level of stability and maturity as the core artifacts and bundling them did not make much sense.
29+
30+
Moving forward, only the core artifacts remain in the `apollo-kotlin` repository and are released together.
31+
32+
Other artifacts are moved to new maven coordinates and GitHub repositories.
33+
34+
| Old coordinates | New coordinates | New Repository |
35+
|---------------------------------------------------------------------|------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------|
36+
| com.apollographql.apollo3:apollo-compose-support-incubating | com.apollographql.compose:compose-support | [apollographql/apollo-kotlin-compose-support](https://github.com/apollographql/apollo-kotlin-compose-support) |
37+
| com.apollographql.apollo3:apollo-compose-paging-support-incubating | com.apollographql.compose:compose-paging-support | [apollographql/apollo-kotlin-compose-support](https://github.com/apollographql/apollo-kotlin-compose-support) |
38+
| com.apollographql.apollo3:apollo-cli-incubating | com.apollographql.cli:apollo-cli | [apollographql/apollo-kotlin-cli](https://github.com/apollographql/apollo-kotlin-cli) |
39+
| com.apollographql.apollo3:apollo-engine-ktor | com.apollographql.ktor:apollo-engine-ktor | [apollographql/apollo-kotlin-ktor-support](https://github.com/apollographql/apollo-kotlin-ktor-support) |
40+
| com.apollographql.apollo3:apollo-mockserver | com.apollographql.mockserver:apollo-mockserver | [apollographql/apollo-kotlin-mockserver](https://github.com/apollographql/apollo-kotlin-mockserver) |
41+
| com.apollographql.apollo3:apollo-normalized-cache-incubating | com.apollographql.cache:normalized-cache-incubating | [apollographql/apollo-kotlin-normalized-cache-incubating](https://github.com/apollographql/apollo-kotlin-normalized-cache-incubating) |
42+
| com.apollographql.apollo3:apollo-normalized-cache-api-incubating | com.apollographql.cache:normalized-cache-incubating | [apollographql/apollo-kotlin-normalized-cache-incubating](https://github.com/apollographql/apollo-kotlin-normalized-cache-incubating) |
43+
| com.apollographql.apollo3:apollo-normalized-cache-sqlite-incubating | com.apollographql.cache:normalized-cache-sqlite-incubating | [apollographql/apollo-kotlin-normalized-cache-incubating](https://github.com/apollographql/apollo-kotlin-normalized-cache-incubating) |
44+
| com.apollographql.apollo3:apollo-runtime-java | com.apollographql.java:client | [apollographql/apollo-kotlin-java-support](https://github.com/apollographql/apollo-kotlin-java-support) |
45+
| com.apollographql.apollo3:apollo-rx2-support-java | com.apollographql.java:rx2 | [apollographql/apollo-kotlin-java-support](https://github.com/apollographql/apollo-kotlin-java-support) |
46+
| com.apollographql.apollo3:apollo-rx3-support-java | com.apollographql.java:rx3 | [apollographql/apollo-kotlin-java-support](https://github.com/apollographql/apollo-kotlin-java-support) |
47+
48+
Those new artifacts also have a new package name. You can usually guess it by removing `.apollo3`:
49+
50+
```kotlin
51+
// Replace
52+
import com.apollographql.apollo3.mockserver.MockServer
53+
54+
// With
55+
import com.apollographql.mockserver.MockServer
56+
```
57+
58+
## apollo-runtime
59+
60+
### Fetch errors do not throw
3161

3262
<Caution>
3363

@@ -39,9 +69,7 @@ See [nullability](../advanced/nullability) for a quick peek at the future of Gra
3969

4070
</Caution>
4171

42-
### Fetch errors do not throw
43-
44-
In Apollo Kotlin 3, non-GraphQL errors like network errors, cache misses, and parsing errors were surfaced by throwing exceptions in `ApolloCall.execute()` and in Flows (`ApolloCall.toFlow()`, `ApolloCall.watch()`). This was problematic because it was a difference in how to handle GraphQL errors vs other errors. Moreover, throwing terminates a Flow and consumers would have to handle re-collection.
72+
In Apollo Kotlin 3, non-GraphQL errors like network errors, cache misses, and parsing errors were surfaced by throwing exceptions in `ApolloCall.execute()` and in Flows (`ApolloCall.toFlow()`, `ApolloCall.watch()`). This was problematic because it was a difference in how to handle GraphQL errors vs other errors and it was easy to forget catching the exceptions. Uncaught network errors is by far the number one error reported by the [Google Play SDK Index](https://play.google.com/sdks). Moreover, throwing terminates a Flow and consumers would have to handle re-collection.
4573

4674
In Apollo Kotlin 4, a new field `ApolloResponse.exception` has been added and these errors are now surfaced by returning (for `execute()`) or emitting (for Flows) an `ApolloResponse` with a non-null `exception` instead of throwing it.
4775

@@ -116,7 +144,7 @@ apolloClient.query(query).watch()
116144
apolloClient.query(query).watch().filter { it.exception == null }
117145
```
118146

119-
### ApolloCompositeException is not thrown anymore
147+
### ApolloCompositeException is not thrown
120148

121149
When using the cache, Apollo Kotlin 3 threw `ApolloCompositeException` if no response could be found. For an example, a `CacheFirst` fetch policy would throw `ApolloCompositeException(cacheMissException, apolloNetworkException)` if both cache and network failed.
122150

@@ -134,6 +162,8 @@ val cacheMissException = exception
134162
val networkException = exception.suppressedExceptions.firstOrNull()
135163
```
136164

165+
For more control over the exception, use `toFlow()` and collect the different `ApolloResponse`.
166+
137167
### emitCacheMisses(Boolean) is removed
138168

139169
In Apollo Kotlin 3, when using the normalized cache, you could set `emitCacheMisses` to `true` to emit cache misses instead of throwing.
@@ -154,9 +184,7 @@ Those helper functions:
154184
* make `CacheFirst`, `NetworkFirst` and `CacheAndNetwork` policies ignore fetch errors.
155185
* throw ApolloComposite exception if needed.
156186

157-
Because of the number of different options in version 3 and the complexity of error handling, these functions may not 100% match the 3 behavior, especially in the advanced cases involving watchers. If you are in one of those cases, we strongly recommend using the 4 functions that are easier to reason about.
158-
159-
## Other Apollo Runtime changes
187+
Because of the number of different options in version 3 and the complexity of error handling, these functions may not 100% match the version 3 behavior, especially in the advanced cases involving watchers. If you are in one of those cases, we strongly recommend using the version 4 functions that are easier to reason about.
160188

161189
### Non standard HTTP headers are not sent by default
162190

@@ -194,47 +222,11 @@ val call = client.query(MyQuery())
194222
.execute()
195223
```
196224

197-
### `HttpEngine` now implements `Closeable`
225+
### `HttpEngine` implements `Closeable`
198226

199227
`HttpEngine` now implements `Closeable` and has its `dispose` method renamed to `close`. If you have a custom `HttpEngine`, you need to implement `close` instead of `dispose`.
200228

201-
202-
## Maven artifacts reorganization
203-
204-
Over the years, a lot of support functionality was added alongside `apollo-api` and `apollo-runtime`. While useful, most of this functionality doesn't share the same level of stability and maturity as the main artifacts and bundling them did not make much sense.
205-
206-
Moving forward, some artifacts are released separately and have new Maven coordinates, GitHub repositories and package names. Others are deprecated.
207-
208-
For the initial version 4 release, most artifacts are kept with deprecation warnings and will be removed in the future.
209-
210-
The artifacts are:
211-
212-
* apollo-mockserver
213-
* MockServer was born out of our own internal needs for a KMP-ready mockserver. Most of its public API is subject to change, and it has been moved to a separate repository.
214-
* apollo-cli-incubating
215-
* The Apollo CLI contract is subject to change and it has been moved to a separate repository.
216-
* apollo-rx-support
217-
* The RxJava{2-3} artifacts are very thin wrappers around kotlinx-coroutines-rx{2-3} and we recommend using those instead.
218-
* apollo-idling-resource
219-
* ApolloIdlingResource is deprecated. We recommend using reactive patterns to test your UI instead. See [this article about ways to do so](https://medium.com/androiddevelopers/alternatives-to-idling-resources-in-compose-tests-8ae71f9fc473) for more details.
220-
221-
### Summary
222-
223-
| Old coordinates | New coordinates | New Repository |
224-
|--------------------------------------------------|------------------------------------------------|:----------------------------------------------------------|
225-
| com.apollographql.apollo3:apollo-mockserver | com.apollographql.mockserver:apollo-mockserver | https://github.com/apollographql/apollo-kotlin-mockserver |
226-
| com.apollographql.apollo3:apollo-cli-incubating | com.apollographql.cli:apollo-cli | https://github.com/apollographql/apollo-kotlin-cli |
227-
| com.apollographql.apollo3:apollo-idling-resource | Deprecated | Deprecated |
228-
| com.apollographql.apollo3:apollo-rx2-support | Deprecated | Deprecated |
229-
| com.apollographql.apollo3:apollo-rx3-support | Deprecated | Deprecated |
230-
231-
232-
| Old package name | New package name |
233-
|--------------------------------------|------------------------------|
234-
| com.apollographql.apollo3.mockserver | com.apollographql.mockserver |
235-
| com.apollographql.apollo3.cli | com.apollographql.cli |
236-
237-
## Gradle Plugin
229+
## apollo-gradle-plugin
238230

239231
### Multi-module `dependsOn`
240232

@@ -325,6 +317,20 @@ dependencies {
325317
apolloUsedCoordinates(project(":feature1"))
326318
}
327319
```
320+
### Publishing is no longer configured automatically
321+
322+
Apollo artifacts are not automatically published anymore. To publish them, create a `MavenPublication`:
323+
324+
```kotlin
325+
publishing {
326+
publications {
327+
create("apollo", MavenPublication::class.java) {
328+
from(components["apollo"])
329+
artifactId = "${project.name}-apollo"
330+
}
331+
}
332+
}
333+
```
328334

329335
### Custom scalars declaration
330336

@@ -415,10 +421,6 @@ class MyPlugin: ApolloCompilerPlugin {
415421
}
416422
```
417423

418-
### Publishing is no longer configured automatically
419-
420-
In Apollo Kotlin 3, maven publishing was automatically configured. In Apollo Kotlin 4, this is no longer the case, and you need to configure the publishing tasks yourself.
421-
422424
### Operation manifest file location
423425

424426
Since Apollo Kotlin now supports [different operation manifest formats](../advanced/persisted-queries), the `operationOutput.json` file will be generated in `"build/generated/manifest/apollo/$service/operationOutput.json"` instead of `"build/generated/operationOutput/apollo/$service/operationOutput.json"`.
@@ -427,7 +429,7 @@ Since Apollo Kotlin now supports [different operation manifest formats](../advan
427429

428430
This was provided for compatibility with 2.x and is now removed. If you need specific package names for fragments, you can use a [compiler plugin](../advanced/compiler-plugins) and `ApolloCompilerPlugin.layout()` instead.
429431

430-
## Apollo Compiler
432+
## apollo-compiler
431433

432434
### "compat" `codegenModels` is removed
433435

@@ -580,7 +582,7 @@ val myEnum = MyEnum.UNKNOWN__("foo")
580582
val myEnum = MyEnum.safeValueOf("foo")
581583
```
582584

583-
## Cache
585+
## apollo-normalized-cache
584586

585587
### Configuration order
586588

@@ -614,12 +616,13 @@ The AST classes (`GQLNode` and subclasses) as well as `Introspection` classes ar
614616

615617
It is not possible to create a `Schema` from a File or String directly anymore. Instead, create a `GQLDocument` first and convert it to a schema with `toSchema()`.
616618

619+
## apollo-rx{2-3}-support
617620

618-
## Using RxJava artifacts is now an error
621+
The `apollo-rx2-support` and `apollo-rx3-support` artifacts are deprecated.
619622

620-
The `apollo-rx2-support` and `apollo-rx3-support` artifacts are very thin wrappers around [`kotlinx-coroutines-rx2`](https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx2) or [`kotlinx-coroutines-rx3`](https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx3) and will be removed in a future version.
623+
They were very thin wrappers around [`kotlinx-coroutines-rx2`](https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx2) or [`kotlinx-coroutines-rx3`](https://github.com/Kotlin/kotlinx.coroutines/tree/master/reactive/kotlinx-coroutines-rx3) and will be removed in a future version.
621624

622-
In Apollo Kotlin 4, use `kotlinx-coroutines-rx${version}` instead. Replace the artifact in your build script:
625+
Use `kotlinx-coroutines-rx${version}` directlyl instead. Replace the artifact in your build script:
623626

624627
```kotlin
625628
dependencies {
@@ -632,7 +635,7 @@ dependencies {
632635

633636
```
634637

635-
In your code, use `asFLowable()`:
638+
In your code, use `asFlowable()`:
636639

637640
```kotlin
638641
// Replace
@@ -648,7 +651,9 @@ apolloClient.query().rxSingle()
648651
apolloClient.query().toFlow().asFlowable().firstOrError()
649652
```
650653

654+
## apollo-idling-resource
651655

656+
ApolloIdlingResource is deprecated. We recommend using reactive patterns to test your UI instead. See [this article about ways to do so](https://medium.com/androiddevelopers/alternatives-to-idling-resources-in-compose-tests-8ae71f9fc473) for more details.
652657

653658
## Example of a migration
654659

libraries/apollo-adapters/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ apollo-adapters contains adapters for common date and big decimal GraphQL scalar
1515
| `com.apollographql.apollo3.adapter.JavaOffsetDateTimeAdapter` | For `java.time.OffsetDateTime` ISO8601 dates |
1616
| `com.apollographql.apollo3.adapter.DateAdapter` | For `java.util.Date` ISO8601 dates |
1717
| `com.apollographql.apollo3.adapter.BigDecimalAdapter` | For a Multiplatform `com.apollographql.apollo3.adapter.BigDecimal` class holding big decimal values |
18-
| `com.apollographql.apollo3.network.adapter.KtorHttpUrlAdapter` | For `io.ktor.http.Url` class holding url values |

0 commit comments

Comments
 (0)