Skip to content

Commit 0cc58cc

Browse files
martinbonninBoD
andauthored
4.3 changelog and compiler plugins documentation (#6556)
* Add Changelog for 4.3.0 * Update docs for 4.3 (#6550) * add missing link * fix merge * Update CHANGELOG.md Co-authored-by: Benoit 'BoD' Lubek <[email protected]> * shorter syntax * mention the new normalized cache --------- Co-authored-by: Benoit 'BoD' Lubek <[email protected]>
1 parent e56fdb4 commit 0cc58cc

File tree

3 files changed

+49
-41
lines changed

3 files changed

+49
-41
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@ Change Log
33

44
# Next version
55

6+
# Version 4.3.0
7+
8+
Version 4.3.0 allows adding multiple compiler plugins and stabilizes `ApolloCompilerPlugin.beforeCompilationStep()` as the main entry point for compiler plugins. Read more in the [compiler plugins documentation page](https://www.apollographql.com/docs/kotlin/advanced/compiler-plugins).
9+
10+
This allows to move some cache-specific code generation logic to the new normalized cache repo and better separate concerns.
11+
12+
Moving forward, `ApolloCompilerPlugin.beforeCompilationStep()` and `ApolloCompilerRegistry.registerOperationIdsGenerator()` are considered stable because they play an important part in setting up [persisted queries](https://www.apollographql.com/docs/kotlin/advanced/persisted-queries). Other APIs are considered more advanced and will most likely stay unstable for the foreseeable future.
13+
14+
## Contributors 💜
15+
16+
Many thanks to @gnehz972 and @mengdd for their fixes about HTTP batching 💜
17+
18+
## 👷‍♂️ All changes
19+
20+
* Fix losing response headers when using batch request (#6538)
21+
* fix the batch size not respected issue (#6528)
22+
* prepare compiler plugins for 4.3 (#6549)
23+
* Allow to register multiple compiler plugins (#6546)
24+
* Add key fields to selections even when they're already selected with an alias (#6503) (#6544)
25+
* Ignore scalars/enums in checkCapitalizedFields (#6502) (#6543)
26+
* Call DocumentTransform.transform after processing (#6510) (#6512)
27+
628
# Version 4.2.0
729

830
_2025-04-28_

docs/source/advanced/compiler-plugins.mdx

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,61 +32,36 @@ plugins {
3232
}
3333

3434
dependencies {
35-
// Add apollo-compiler as a dependency
36-
implementation("com.apollographql.apollo:apollo-compiler:4.1.1")
35+
// Add apollo-compiler as a compileOnly dependency
36+
compileOnly("com.apollographql.apollo:apollo-compiler:4.3.0")
3737
}
3838
```
3939

4040
Next create your plugin in a `src/main/kotlin/mypackage/MyPlugin` file:
4141

4242
```kotlin
43-
package mypackage
44-
45-
import com.apollographql.apollo.compiler.OperationOutputGenerator
46-
import com.apollographql.apollo.compiler.ApolloCompilerPlugin
47-
import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor
48-
import com.apollographql.apollo.compiler.operationoutput.OperationId
49-
5043
class MyPlugin: ApolloCompilerPlugin {
51-
override fun operationIds(descriptors: List<OperationDescriptor>): List<OperationId> {
52-
// This assumes the returned ids are in the same order as the descriptors
53-
return registerOperations(descriptors).withIndex().map { OperationId(it.value, descriptors[it.index].name) }
54-
}
55-
56-
/**
57-
* Send operations to a remote server and return the server persisted ids
58-
*/
59-
fun registerOperations(descriptors: List<OperationDescriptor>): List<String> {
60-
// ...
44+
override fun beforeCompilationStep(
45+
environment: ApolloCompilerPluginEnvironment,
46+
registry: ApolloCompilerRegistry,
47+
) {
48+
// add your custom code here
6149
}
6250
}
6351
```
6452

65-
Next, create an `ApolloCompilerPluginProvider`. This is the entry point of compiler plugins. It is loaded using the [ServiceLoader](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) API.
66-
67-
```kotlin
68-
class MyPluginProvider: ApolloCompilerPluginProvider {
69-
override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin {
70-
return MyPlugin()
71-
}
72-
}
73-
```
7453

75-
Make your plugin discoverable by [ServiceLoader](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) by adding a resource in `src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPluginProvider`. This file contains the fully qualified name of your plugin:
54+
Make your plugin discoverable by [ServiceLoader](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) by adding a resource in `src/main/resources/META-INF/services/com.apollographql.apollo.compiler.ApolloCompilerPlugin`. This file contains the fully qualified name of your plugin:
7655

7756
```
78-
mypackage.MyPluginProvider
57+
mypackage.MyPlugin
7958
```
8059

8160
<Note>
8261

83-
The name of the resource file is important. It must be `com.apollographql.apollo.compiler.ApolloCompilerPluginProvider` and be in the `META-INF/services` folder. This is how `ServiceLoader` looks up plugins at runtime.
62+
The name of the resource file is important. It must be `com.apollographql.apollo.compiler.ApolloCompilerPlugin` and be in the `META-INF/services` folder. This is how `ServiceLoader` looks up plugins at runtime.
8463
</Note>
8564

86-
<Note>
87-
88-
Only a single plugin is supported at this time. If you need more, you can usually have a single wrapper plugin that calls your different implementations in the required order.
89-
</Note>
9065

9166
## Adding a plugin to the Apollo compiler classpath
9267

@@ -133,9 +108,14 @@ apollo {
133108
The arguments are available in `ApolloCompilerPluginEnvironment.arguments`:
134109

135110
```kotlin
136-
class MyPluginProvider: ApolloCompilerPluginProvider {
137-
override fun create(environment: ApolloCompilerPluginEnvironment): ApolloCompilerPlugin {
138-
return MyPlugin(environment.arguments.get("token") as String)
111+
class MyPlugin: ApolloCompilerPlugin {
112+
override fun beforeCompilationStep(
113+
environment: ApolloCompilerPluginEnvironment,
114+
registry: ApolloCompilerRegistry,
115+
) {
116+
val token = environment.arguments.get("token") as String
117+
118+
// add your custom code here
139119
}
140120
}
141121
```

docs/source/advanced/persisted-queries.mdx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,16 @@ The `Plugin` interface has an `operationIds()` method that you can override to c
108108
Example Md5 hash generator:
109109

110110
```kotlin
111-
class MyPlugin: Plugin {
112-
override fun operationIds(descriptors: List<OperationDescriptor>): List<OperationId> {
113-
return descriptors.map { OperationId(it.source.md5(), it.name) }
111+
class MyPlugin : ApolloCompilerPlugin {
112+
override fun beforeCompilationStep(
113+
environment: ApolloCompilerPluginEnvironment,
114+
registry: ApolloCompilerRegistry,
115+
) {
116+
registry.registerOperationIdsGenerator {
117+
it.map { OperationId(it.source.md5(), it.name) }
118+
}
114119
}
115120
}
121+
116122
```
117123

0 commit comments

Comments
 (0)