Skip to content

Commit 2d819e0

Browse files
authored
Keep compiler plugin in sync with v4 (#6547)
* Keep compiler plugins in sync * update apiDump * fix sorting of transforms * fix build
1 parent 10063d2 commit 2d819e0

File tree

17 files changed

+155
-105
lines changed

17 files changed

+155
-105
lines changed

libraries/apollo-compiler/api/apollo-compiler.api

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public final class com/apollographql/apollo/compiler/ApolloCompiler {
1515
public static final field INSTANCE Lcom/apollographql/apollo/compiler/ApolloCompiler;
1616
public final fun buildCodegenSchema (Ljava/util/List;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;Lcom/apollographql/apollo/compiler/CodegenSchemaOptions;Ljava/util/List;Lcom/apollographql/apollo/compiler/SchemaTransform;)Lcom/apollographql/apollo/compiler/CodegenSchema;
1717
public final fun buildDataBuilders (Lcom/apollographql/apollo/compiler/CodegenSchema;Lcom/apollographql/apollo/compiler/UsedCoordinates;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/codegen/SchemaLayout;Ljava/util/List;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
18-
public final fun buildIrOperations (Lcom/apollographql/apollo/compiler/CodegenSchema;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/OperationsTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;)Lcom/apollographql/apollo/compiler/ir/IrOperations;
19-
public final fun buildSchemaAndOperationsSources (Lcom/apollographql/apollo/compiler/CodegenSchema;Ljava/util/List;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/LayoutFactory;Lcom/apollographql/apollo/compiler/OperationIdsGenerator;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/OperationsTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;Ljava/io/File;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
20-
public final fun buildSchemaAndOperationsSources (Ljava/util/List;Ljava/util/List;Lcom/apollographql/apollo/compiler/CodegenSchemaOptions;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/LayoutFactory;Lcom/apollographql/apollo/compiler/OperationIdsGenerator;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/OperationsTransform;Lcom/apollographql/apollo/compiler/SchemaTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;Ljava/io/File;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
18+
public final fun buildIrOperations (Lcom/apollographql/apollo/compiler/CodegenSchema;Ljava/util/List;Ljava/util/List;Ljava/util/List;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;)Lcom/apollographql/apollo/compiler/ir/IrOperations;
19+
public final fun buildSchemaAndOperationsSources (Lcom/apollographql/apollo/compiler/CodegenSchema;Ljava/util/List;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/LayoutFactory;Lcom/apollographql/apollo/compiler/OperationIdsGenerator;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;Ljava/io/File;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
20+
public final fun buildSchemaAndOperationsSources (Ljava/util/List;Ljava/util/List;Lcom/apollographql/apollo/compiler/CodegenSchemaOptions;Lcom/apollographql/apollo/compiler/IrOptions;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/LayoutFactory;Lcom/apollographql/apollo/compiler/OperationIdsGenerator;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;Lcom/apollographql/apollo/compiler/SchemaTransform;Lcom/apollographql/apollo/compiler/ApolloCompiler$Logger;Ljava/io/File;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
2121
public final fun buildSchemaAndOperationsSourcesFromIr (Lcom/apollographql/apollo/compiler/CodegenSchema;Lcom/apollographql/apollo/compiler/ir/IrOperations;Lcom/apollographql/apollo/compiler/UsedCoordinates;Ljava/util/List;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/codegen/SchemaAndOperationsLayout;Lcom/apollographql/apollo/compiler/OperationIdsGenerator;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;Ljava/io/File;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
2222
public final fun buildSchemaSources (Lcom/apollographql/apollo/compiler/CodegenSchema;Lcom/apollographql/apollo/compiler/UsedCoordinates;Lcom/apollographql/apollo/compiler/CodegenOptions;Lcom/apollographql/apollo/compiler/codegen/SchemaLayout;Lcom/apollographql/apollo/compiler/Transform;Lcom/apollographql/apollo/compiler/Transform;)Lcom/apollographql/apollo/compiler/codegen/SourceOutput;
2323
}
@@ -31,15 +31,14 @@ public final class com/apollographql/apollo/compiler/ApolloCompilerKt {
3131
}
3232

3333
public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerPlugin {
34-
public abstract fun beforeCompilationStep (Lcom/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment;Lcom/apollographql/apollo/compiler/ApolloCompilerRegistry;)V
34+
public fun beforeCompilationStep (Lcom/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment;Lcom/apollographql/apollo/compiler/ApolloCompilerRegistry;)V
3535
public fun operationIds (Ljava/util/List;)Ljava/util/List;
3636
}
3737

3838
public final class com/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment {
39-
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;Ljava/io/File;)V
39+
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;)V
4040
public final fun getArguments ()Ljava/util/Map;
4141
public final fun getLogger ()Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;
42-
public final fun getOutputDirectory ()Ljava/io/File;
4342
}
4443

4544
public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerPluginLogger {
@@ -54,14 +53,14 @@ public abstract interface class com/apollographql/apollo/compiler/ApolloCompiler
5453
}
5554

5655
public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerRegistry {
56+
public abstract fun registerExecutableDocumentTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;)V
5757
public abstract fun registerExtraCodeGenerator (Lcom/apollographql/apollo/compiler/CodeGenerator;)V
5858
public abstract fun registerForeignSchemas (Ljava/util/List;)V
5959
public abstract fun registerIrTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6060
public abstract fun registerJavaOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6161
public abstract fun registerKotlinOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6262
public abstract fun registerLayout (Lcom/apollographql/apollo/compiler/LayoutFactory;)V
6363
public abstract fun registerOperationIdsGenerator (Lcom/apollographql/apollo/compiler/OperationIdsGenerator;)V
64-
public abstract fun registerOperationsTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/OperationsTransform;)V
6564
public abstract fun registerSchemaTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/SchemaTransform;)V
6665
}
6766

@@ -71,7 +70,7 @@ public final class com/apollographql/apollo/compiler/Before : com/apollographql/
7170
}
7271

7372
public abstract interface class com/apollographql/apollo/compiler/CodeGenerator {
74-
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;)V
73+
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;Ljava/io/File;)V
7574
}
7675

7776
public final class com/apollographql/apollo/compiler/CodegenMetadata {
@@ -215,6 +214,10 @@ public final class com/apollographql/apollo/compiler/EntrypointsKt {
215214
public static final fun findCodegenSchemaFile (Ljava/lang/Iterable;)Ljava/io/File;
216215
}
217216

217+
public abstract interface class com/apollographql/apollo/compiler/ExecutableDocumentTransform {
218+
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLDocument;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDocument;
219+
}
220+
218221
public final class com/apollographql/apollo/compiler/ExpressionAdapterInitializer : com/apollographql/apollo/compiler/AdapterInitializer {
219222
public static final field Companion Lcom/apollographql/apollo/compiler/ExpressionAdapterInitializer$Companion;
220223
public fun <init> (Ljava/lang/String;)V
@@ -372,10 +375,6 @@ public abstract interface class com/apollographql/apollo/compiler/OperationsCode
372375
public abstract interface class com/apollographql/apollo/compiler/OperationsCodegenOptions : com/apollographql/apollo/compiler/JavaOperationsCodegenOptions, com/apollographql/apollo/compiler/KotlinOperationsCodegenOptions {
373376
}
374377

375-
public abstract interface class com/apollographql/apollo/compiler/OperationsTransform {
376-
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLDocument;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDocument;
377-
}
378-
379378
public final class com/apollographql/apollo/compiler/OptionsKt {
380379
public static final field ADD_TYPENAME_ALWAYS Ljava/lang/String;
381380
public static final field ADD_TYPENAME_IF_ABSTRACT Ljava/lang/String;

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompiler.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import com.apollographql.apollo.compiler.codegen.kotlin.KotlinCodegen
3434
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput
3535
import com.apollographql.apollo.compiler.codegen.kotlin.toSourceOutput
3636
import com.apollographql.apollo.compiler.codegen.plus
37-
import com.apollographql.apollo.compiler.internal.ApolloOperationsTransform
37+
import com.apollographql.apollo.compiler.internal.ApolloExecutableDocumentTransform
3838
import com.apollographql.apollo.compiler.internal.checkApolloInlineFragmentsHaveTypeCondition
3939
import com.apollographql.apollo.compiler.internal.checkApolloReservedEnumValueNames
4040
import com.apollographql.apollo.compiler.internal.checkApolloTargetNameClashes
@@ -190,7 +190,7 @@ object ApolloCompiler {
190190
upstreamCodegenModels: List<String>,
191191
upstreamFragmentDefinitions: List<GQLFragmentDefinition>,
192192
options: IrOptions,
193-
operationsTransform: OperationsTransform?,
193+
executableDocumentTransform: ExecutableDocumentTransform?,
194194
logger: Logger?,
195195
): IrOperations {
196196
val schema = codegenSchema.schema
@@ -233,13 +233,13 @@ object ApolloCompiler {
233233
/**
234234
* Step 2, Modify the AST to add typename, key fields and call any user-provided transform.
235235
*/
236-
var document = ApolloOperationsTransform(options.addTypename ?: defaultAddTypename).transform(
236+
var document = ApolloExecutableDocumentTransform(options.addTypename ?: defaultAddTypename).transform(
237237
schema = schema,
238238
document = GQLDocument(userDefinitions, sourceLocation = null),
239239
upstreamFragmentDefinitions
240240
)
241-
if (operationsTransform != null) {
242-
document = operationsTransform.transform(schema, document, upstreamFragmentDefinitions)
241+
if (executableDocumentTransform != null) {
242+
document = executableDocumentTransform.transform(schema, document, upstreamFragmentDefinitions)
243243
}
244244

245245
/**
@@ -394,7 +394,7 @@ object ApolloCompiler {
394394
}
395395

396396
val operationOutput = descriptors.toOperationOutput(
397-
(operationIdsGenerator ?: defaultOperationOutputGenerator).generate(descriptors)
397+
(operationIdsGenerator ?: defaultOperationIdsGenerator).generate(descriptors)
398398
)
399399

400400
check(operationOutput.size == irOperations.operations.size) {
@@ -475,7 +475,7 @@ object ApolloCompiler {
475475
irOperationsTransform: Transform<IrOperations>?,
476476
javaOutputTransform: Transform<JavaOutput>?,
477477
kotlinOutputTransform: Transform<KotlinOutput>?,
478-
operationsTransform: OperationsTransform?,
478+
executableDocumentTransform: ExecutableDocumentTransform?,
479479
schemaTransform: SchemaTransform?,
480480
logger: Logger?,
481481
operationManifestFile: File?,
@@ -498,7 +498,7 @@ object ApolloCompiler {
498498
irOperationsTransform,
499499
javaOutputTransform,
500500
kotlinOutputTransform,
501-
operationsTransform,
501+
executableDocumentTransform,
502502
logger,
503503
operationManifestFile
504504
)
@@ -517,7 +517,7 @@ object ApolloCompiler {
517517
irOperationsTransform: Transform<IrOperations>?,
518518
javaOutputTransform: Transform<JavaOutput>?,
519519
kotlinOutputTransform: Transform<KotlinOutput>?,
520-
operationsTransform: OperationsTransform?,
520+
executableDocumentTransform: ExecutableDocumentTransform?,
521521
logger: Logger?,
522522
operationManifestFile: File?,
523523
): SourceOutput {
@@ -526,7 +526,7 @@ object ApolloCompiler {
526526
executableFiles = executableFiles,
527527
upstreamCodegenModels = emptyList(),
528528
upstreamFragmentDefinitions = emptyList(),
529-
operationsTransform = operationsTransform,
529+
executableDocumentTransform = executableDocumentTransform,
530530
options = irOptions,
531531
logger = logger
532532
)

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/ApolloCompilerPlugin.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import com.apollographql.apollo.ast.ForeignSchema
66
import com.apollographql.apollo.ast.GQLDocument
77
import com.apollographql.apollo.ast.GQLFragmentDefinition
88
import com.apollographql.apollo.ast.Schema
9-
import com.apollographql.apollo.compiler.codegen.SchemaAndOperationsLayout
109
import com.apollographql.apollo.compiler.codegen.java.JavaOutput
1110
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput
1211
import com.apollographql.apollo.compiler.ir.IrOperations
@@ -32,7 +31,9 @@ interface ApolloCompilerPlugin {
3231
* @param environment options and environment for the plugin.
3332
* @param registry the registry where to register transformations.
3433
*/
35-
fun beforeCompilationStep(environment: ApolloCompilerPluginEnvironment, registry: ApolloCompilerRegistry)
34+
fun beforeCompilationStep(environment: ApolloCompilerPluginEnvironment, registry: ApolloCompilerRegistry) {
35+
36+
}
3637

3738
/**
3839
* Computes operation ids for persisted queries.
@@ -58,11 +59,6 @@ class ApolloCompilerPluginEnvironment(
5859
* A logger that can be used by the plugin.
5960
*/
6061
val logger: ApolloCompilerPluginLogger,
61-
/**
62-
* The compiler output directory.
63-
* May be null if the plugin is called from a non-codegen step like building the schema and/or the IR.
64-
*/
65-
val outputDirectory: File?,
6662
)
6763

6864
sealed interface Order
@@ -76,7 +72,7 @@ interface ApolloCompilerRegistry {
7672
fun registerSchemaTransform(id: String, vararg orders: Order, transform: SchemaTransform)
7773

7874
@ApolloExperimental
79-
fun registerOperationsTransform(id: String, vararg orders: Order, transform: OperationsTransform)
75+
fun registerExecutableDocumentTransform(id: String, vararg orders: Order, transform: ExecutableDocumentTransform)
8076
@ApolloExperimental
8177
fun registerIrTransform(id: String, vararg orders: Order, transform: Transform<IrOperations>)
8278

@@ -102,9 +98,9 @@ fun interface SchemaTransform {
10298

10399

104100
/**
105-
* A [OperationsTransform] transforms operations and fragments at build time. [OperationsTransform] can add or remove fields automatically, for an example.
101+
* A [ExecutableDocumentTransform] transforms operations and fragments at build time. [ExecutableDocumentTransform] can add or remove fields automatically, for an example.
106102
*/
107-
fun interface OperationsTransform {
103+
fun interface ExecutableDocumentTransform {
108104
/**
109105
* Transforms the given document.
110106
*
@@ -141,7 +137,7 @@ fun interface CodeGenerator {
141137
/**
142138
* Transforms the given input into an output of the same type
143139
*/
144-
fun generate(schema: GQLDocument)
140+
fun generate(schema: GQLDocument, outputDirectory: File)
145141
}
146142

147143

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/LegacyOperationIdsGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ internal class LegacyOperationIdsGenerator(private val plugin: ApolloCompilerPlu
88
@Suppress("DEPRECATION")
99
val operationIds = plugin.operationIds(operationDescriptorList.toList())
1010
if (operationIds != null) {
11-
println("Apollo: using ApolloCompiler.operationIds() is deprecated. Please use registry.registerOperationIdsGenerator() instead.")
11+
println("Apollo: using ApolloCompilerPlugin.operationIds() is deprecated. Please use registry.registerOperationIdsGenerator() instead.")
1212
return operationIds
1313
}
1414
return NoList

libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/Options.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package com.apollographql.apollo.compiler
33
import com.apollographql.apollo.annotations.ApolloDeprecatedSince
44
import com.apollographql.apollo.annotations.ApolloExperimental
55
import com.apollographql.apollo.compiler.internal.sha256
6-
import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor
76
import com.apollographql.apollo.compiler.operationoutput.OperationId
87
import com.apollographql.apollo.compiler.operationoutput.OperationOutput
98
import kotlinx.serialization.SerialName
109
import kotlinx.serialization.Serializable
11-
import java.nio.charset.StandardCharsets
1210

1311
const val MODELS_RESPONSE_BASED = "responseBased"
1412
const val MODELS_OPERATION_BASED = "operationBased"
@@ -649,12 +647,9 @@ private val NoOpLogger = object : ApolloCompiler.Logger {
649647

650648
internal val defaultAlwaysGenerateTypesMatching = emptySet<String>()
651649

652-
internal val defaultOperationOutputGenerator = object : OperationIdsGenerator {
653-
654-
override fun generate(operationDescriptorList: Collection<OperationDescriptor>): List<OperationId> {
655-
return operationDescriptorList.map {
656-
OperationId(it.source.sha256(), it.name)
657-
}
650+
internal val defaultOperationIdsGenerator = OperationIdsGenerator { operationDescriptorList ->
651+
operationDescriptorList.map {
652+
OperationId(it.source.sha256(), it.name)
658653
}
659654
}
660655

0 commit comments

Comments
 (0)