3.0.0-alpha04
brings Java codegen and ApolloIdlingResource in Apollo Android 3. These were the final pieces that were not ported to Apollo Android 3 yet 🎉..
In addition, it brings some consistency improvements in the codegen/Gradle setup as well bump the max json stack size to 256 and other ergonomic improvements and fixes.
As we move towards a stable version, we'll have to settle for the current with-er
API or Builders
. Let us know what you think by letting a comment on the RFC.
✨[new] Java Codegen
Apollo Android 3 now generates Java models if the Kotlin plugin is not applied in your project. This is detected automatically and should work in the vast majority of cases. If you want to force Java codegen while still using the Kotlin plugin, you can set generateKotlinModels.set(false)
in your Gradle scripts:
apollo {
// Generate Java classes regardless of whether the Kotlin plugin is applied
generateKotlinModels.set(false)
}
Java models work like Kotlin models and use the same runtime. With the exception of default parameters, they are compatible with Kotlin operationBased
models so you can change the target language without having to update most of your code.
✨[new] apollo-idling-resource
apollo-idling-resource is now available in Apollo Android 3. You can include it with the apollo-idling-resource
artifact:
dependencies {
testImplementation("com.apollographql.apollo3:apollo-idling-resource:$version")
}
And create an ApolloClient
that will update the IdlingResource
:
val idlingResource = ApolloIdlingResource("test")
val apolloClient = ApolloClient("https://...")
.withIdlingResource(idlingResource)
✨[new] valueOf
for enums
Many thanks to @kubode for the contribution 💜
For GraphQL enums generated as sealed class, you can now call valueOf
to parse a String to a given enum value (or Unknown__ if unknown):
Given the below enum:
enum Direction {
NORTH,
EAST,
SOUTH,
WEST
}
You can use:
assertEquals(Direction.NORTH, Direction.valueOf("NORTH"))
assertEquals(Direction.Unknown__("NORTH-WEST"), Direction.valueOf("NORTH-WEST"))
✨[new] Platform errors for ApolloNetworkError
Many thanks to @ProVir for the help getting this done 💜
When something wrong happens during a network request, the runtime will throw a ApolloNetworkError
exception. You can now access the underlying platform error with ApolloNetworkError.platformCause
:
// On iOS you can cast to NSError
try {
apolloClient.query(query)
} catch (e: ApolloNetworkError) {
when ((e.platformCause as NSError?)?.domain) {
NSURLErrorDomain -> // handle NSURLErrorDomain errors ...
}
}
// On Android/JVM, platformCause is the same Throwable as Cause:
try {
apolloClient.query(query)
} catch (e: ApolloNetworkError) {
when (e.cause) {
is UnknownHostException -> // handle UnknownHostException errors ...
}
}
🚧[breaking] Mandatory package name
Because the default of an empty package name creates issues with kapt, it is now mandatory to set the package name of generated models:
apollo {
// Use the same packageName for all generated models
packageName.set("com.example")
// Or use a package name derived from the file location
packageNamesFromFilePaths()
}
🚧[breaking] Schema Types
For consistency, and in order to support multi-modules scenarios where some types are only generated in some modules, custom scalars, object and interface types are now generated as top-level classes in the .type
package name, like input objects and enums instead of being wrapped in a Types
object. Each schema type has a static type: CompiledType
property so you can access the type name in a type safe way.
// Replace
Types.Launch.name
// With
Launch.type.name
If you were using generated CustomScalarType
instances to register your custom scalar adapters, these are moved to the top level as well:
// Replace
ApolloClient("https://").withCustomScalarAdapter(Types.GeoPoint, geoPointAdapter)
// With
ApolloClient("https://").withCustomScalarAdapter(GeoPoint.type, geoPointAdapter)
🚧[breaking] Removed DefaultHttpRequestComposerParams
Because DefaultHttpRequestComposerParams
was setting multiple parameters at the same time (HTTP headers, method, etc..), setting one of them would overwrite a default set on the client. Instead of using DefaultHttpRequestComposerParams
, set parameters individually:
apolloClient.withHttpHeader("name", "value")
apolloRequest.withHttpHeader("otherName", "otherValue")
👷 All Changes
- Input array coercion (#3337)
- Java Codegen (#3335)
- bump the max stack size to 256 (#3333)
- Adds
valueOf
to the enum types (#3328) - Update to AGP 4.2 (#3324)
- bump Kotlin (#3319)
- Expose NSError (#3315)
- fix visibility of presentIfNotNull. (#3316)
- Add apollo-rx3-support (#3303)
- Move ApolloIdlingResource to apollo-idling-resource (#3302)
- simplify the Android setup (#3293)
- Make it possible to override ExecutionContext properties individually (#3294)
- Mandate package name (#3295)
- add more diagnostics for normalization failures (#3286)
- allow multiple HTTP headers with the same name (#3287)
- add error.path and error.extensions (#3285)
- Add 3.x ApolloIdlingResource (#3282)
- bump kotlin-compile-testing and enable warningsAsErrors again (#3278)
- add a way to disable Kdoc during development (#3279)
- Minor Cleanups (#3277)
- Simplify output dir connection (#3276)
- Remove split packages (#3275)
- Remove deprecated modules and move tests to the root level (#3274)
- Encode defaultValue as GraphQL value in introspection schemas (#3272)
- add a DefaultHttpNetworkTransport overload that takes a serverUrl (#3273)