Skip to content

Commit e461fd2

Browse files
authored
Do not add key fields if the cache compiler plugin is already doing it (#6541)
Keep in sync with v4
1 parent 8b3ec0e commit e461fd2

File tree

26 files changed

+490
-431
lines changed

26 files changed

+490
-431
lines changed

libraries/apollo-annotations/api/apollo-annotations.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public final class com/apollographql/apollo/annotations/ApolloDeprecatedSince$Ve
2525
public static final field v4_0_1 Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;
2626
public static final field v4_0_2 Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;
2727
public static final field v4_1_2 Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;
28+
public static final field v4_2_1 Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;
2829
public static final field v5_0_0 Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;
2930
public static fun getEntries ()Lkotlin/enums/EnumEntries;
3031
public static fun valueOf (Ljava/lang/String;)Lcom/apollographql/apollo/annotations/ApolloDeprecatedSince$Version;

libraries/apollo-annotations/api/apollo-annotations.klib.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ open annotation class com.apollographql.apollo.annotations/ApolloDeprecatedSince
3838
enum entry v4_0_1 // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.v4_0_1|null[0]
3939
enum entry v4_0_2 // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.v4_0_2|null[0]
4040
enum entry v4_1_2 // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.v4_1_2|null[0]
41+
enum entry v4_2_1 // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.v4_2_1|null[0]
4142
enum entry v5_0_0 // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.v5_0_0|null[0]
4243

4344
final val entries // com.apollographql.apollo.annotations/ApolloDeprecatedSince.Version.entries|#static{}entries[0]

libraries/apollo-annotations/src/commonMain/kotlin/com/apollographql/apollo/annotations/ApolloDeprecatedSince.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ annotation class ApolloDeprecatedSince(val version: Version) {
3434
v4_0_1,
3535
v4_0_2,
3636
v4_1_2, // All symbols above are ERRORs in 5.0.0 except a few ones that are perpetual soft deprecations like SubscriptionWsProtocol (https://youtrack.jetbrains.com/issue/KT-54106)
37+
v4_2_1,
3738
v5_0_0
3839
}
3940
}

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public final class com/apollographql/apollo/compiler/After : com/apollographql/a
1313

1414
public final class com/apollographql/apollo/compiler/ApolloCompiler {
1515
public static final field INSTANCE Lcom/apollographql/apollo/compiler/ApolloCompiler;
16-
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;
16+
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/SchemaDocumentTransform;)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;
1818
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;
1919
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;
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/SchemaDocumentTransform;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
}
@@ -54,25 +54,21 @@ public abstract interface class com/apollographql/apollo/compiler/ApolloCompiler
5454

5555
public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerRegistry {
5656
public abstract fun registerExecutableDocumentTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;)V
57-
public abstract fun registerExtraCodeGenerator (Lcom/apollographql/apollo/compiler/CodeGenerator;)V
5857
public abstract fun registerForeignSchemas (Ljava/util/List;)V
5958
public abstract fun registerIrTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6059
public abstract fun registerJavaOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6160
public abstract fun registerKotlinOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
6261
public abstract fun registerLayout (Lcom/apollographql/apollo/compiler/LayoutFactory;)V
6362
public abstract fun registerOperationIdsGenerator (Lcom/apollographql/apollo/compiler/OperationIdsGenerator;)V
64-
public abstract fun registerSchemaTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/SchemaTransform;)V
63+
public abstract fun registerSchemaCodeGenerator (Lcom/apollographql/apollo/compiler/SchemaCodeGenerator;)V
64+
public abstract fun registerSchemaTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/SchemaDocumentTransform;)V
6565
}
6666

6767
public final class com/apollographql/apollo/compiler/Before : com/apollographql/apollo/compiler/Order {
6868
public fun <init> (Ljava/lang/String;)V
6969
public final fun getId ()Ljava/lang/String;
7070
}
7171

72-
public abstract interface class com/apollographql/apollo/compiler/CodeGenerator {
73-
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;Ljava/io/File;)V
74-
}
75-
7672
public final class com/apollographql/apollo/compiler/CodegenMetadata {
7773
public static final field Companion Lcom/apollographql/apollo/compiler/CodegenMetadata$Companion;
7874
public fun <init> (Ljava/lang/String;Lcom/apollographql/apollo/compiler/TargetLanguage;Ljava/util/List;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V
@@ -201,6 +197,11 @@ public abstract interface class com/apollographql/apollo/compiler/CommonCodegenO
201197
public abstract fun getUseSemanticNaming ()Ljava/lang/Boolean;
202198
}
203199

200+
public abstract interface class com/apollographql/apollo/compiler/DocumentTransform {
201+
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLFragmentDefinition;)Lcom/apollographql/apollo/ast/GQLFragmentDefinition;
202+
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLOperationDefinition;)Lcom/apollographql/apollo/ast/GQLOperationDefinition;
203+
}
204+
204205
public final class com/apollographql/apollo/compiler/EntryPoints {
205206
public fun <init> ()V
206207
public final fun buildCodegenSchema (Ljava/util/Map;IZLjava/util/List;Ljava/util/function/Consumer;Ljava/io/File;Ljava/io/File;)V
@@ -364,7 +365,7 @@ public abstract interface class com/apollographql/apollo/compiler/LayoutFactory
364365
}
365366

366367
public abstract interface class com/apollographql/apollo/compiler/OperationIdsGenerator {
367-
public abstract fun generate (Ljava/util/Collection;)Ljava/util/List;
368+
public abstract fun generate (Ljava/util/List;)Ljava/util/List;
368369
}
369370

370371
public abstract interface class com/apollographql/apollo/compiler/OperationsCodegenOpt {
@@ -401,6 +402,10 @@ public final class com/apollographql/apollo/compiler/RuntimeAdapterInitializer :
401402
public final fun serializer ()Lkotlinx/serialization/KSerializer;
402403
}
403404

405+
public abstract interface class com/apollographql/apollo/compiler/SchemaCodeGenerator {
406+
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;Ljava/io/File;)V
407+
}
408+
404409
public abstract interface class com/apollographql/apollo/compiler/SchemaCodegenOpt {
405410
public abstract fun getGenerateSchema ()Ljava/lang/Boolean;
406411
public abstract fun getGeneratedSchemaName ()Ljava/lang/String;
@@ -409,12 +414,12 @@ public abstract interface class com/apollographql/apollo/compiler/SchemaCodegenO
409414
public abstract interface class com/apollographql/apollo/compiler/SchemaCodegenOptions : com/apollographql/apollo/compiler/JavaSchemaCodegenOptions, com/apollographql/apollo/compiler/KotlinSchemaCodegenOptions {
410415
}
411416

412-
public abstract interface class com/apollographql/apollo/compiler/SchemaListener {
413-
public abstract fun onSchema (Lcom/apollographql/apollo/ast/Schema;Ljava/io/File;)V
417+
public abstract interface class com/apollographql/apollo/compiler/SchemaDocumentTransform {
418+
public abstract fun transform (Lcom/apollographql/apollo/ast/GQLDocument;)Lcom/apollographql/apollo/ast/GQLDocument;
414419
}
415420

416-
public abstract interface class com/apollographql/apollo/compiler/SchemaTransform {
417-
public abstract fun transform (Lcom/apollographql/apollo/ast/GQLDocument;)Lcom/apollographql/apollo/ast/GQLDocument;
421+
public abstract interface class com/apollographql/apollo/compiler/SchemaListener {
422+
public abstract fun onSchema (Lcom/apollographql/apollo/ast/Schema;Ljava/io/File;)V
418423
}
419424

420425
public final class com/apollographql/apollo/compiler/StringsKt {

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import com.apollographql.apollo.compiler.ir.IrOperationsBuilder
4545
import com.apollographql.apollo.compiler.ir.IrSchemaBuilder
4646
import com.apollographql.apollo.compiler.ir.buildIrDataBuilders
4747
import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor
48-
import com.apollographql.apollo.compiler.operationoutput.OperationId
4948
import com.apollographql.apollo.compiler.operationoutput.toOperationOutput
5049
import com.apollographql.apollo.compiler.pqm.toPersistedQueryManifest
5150
import java.io.File
@@ -60,7 +59,7 @@ object ApolloCompiler {
6059
logger: Logger?,
6160
codegenSchemaOptions: CodegenSchemaOptions,
6261
foreignSchemas: List<ForeignSchema>,
63-
schemaTransform: SchemaTransform?,
62+
schemaTransform: SchemaDocumentTransform?,
6463
): CodegenSchema {
6564
val schemaDocuments = schemaFiles.map {
6665
it.normalizedPath to it.file.toGQLDocument(allowJson = true)
@@ -190,7 +189,7 @@ object ApolloCompiler {
190189
upstreamCodegenModels: List<String>,
191190
upstreamFragmentDefinitions: List<GQLFragmentDefinition>,
192191
options: IrOptions,
193-
executableDocumentTransform: ExecutableDocumentTransform?,
192+
documentTransform: ExecutableDocumentTransform?,
194193
logger: Logger?,
195194
): IrOperations {
196195
val schema = codegenSchema.schema
@@ -232,14 +231,24 @@ object ApolloCompiler {
232231

233232
/**
234233
* Step 2, Modify the AST to add typename, key fields and call any user-provided transform.
234+
* If we detect that the cache compiler plugin is present, we skip adding the keyfields because it will do it.
235+
* TODO: deprecate `addTypename`
235236
*/
236-
var document = ApolloExecutableDocumentTransform(options.addTypename ?: defaultAddTypename).transform(
237-
schema = schema,
238-
document = GQLDocument(userDefinitions, sourceLocation = null),
239-
upstreamFragmentDefinitions
237+
val hasCacheCompilerPlugin = try {
238+
Class.forName("com.apollographql.cache.apollocompilerplugin.internal.ApolloCacheCompilerPlugin")
239+
true
240+
} catch (_: ClassNotFoundException) {
241+
false
242+
}
243+
244+
var document = ApolloExecutableDocumentTransform(options.addTypename ?: defaultAddTypename, !hasCacheCompilerPlugin).transform(
245+
schema = schema,
246+
document = GQLDocument(userDefinitions, sourceLocation = null),
247+
upstreamFragmentDefinitions
240248
)
241-
if (executableDocumentTransform != null) {
242-
document = executableDocumentTransform.transform(schema, document, upstreamFragmentDefinitions)
249+
250+
if (documentTransform != null) {
251+
document = documentTransform.transform(schema, document, upstreamFragmentDefinitions)
243252
}
244253

245254
/**
@@ -475,8 +484,8 @@ object ApolloCompiler {
475484
irOperationsTransform: Transform<IrOperations>?,
476485
javaOutputTransform: Transform<JavaOutput>?,
477486
kotlinOutputTransform: Transform<KotlinOutput>?,
478-
executableDocumentTransform: ExecutableDocumentTransform?,
479-
schemaTransform: SchemaTransform?,
487+
documentTransform: ExecutableDocumentTransform?,
488+
schemaDocumentTransform: SchemaDocumentTransform?,
480489
logger: Logger?,
481490
operationManifestFile: File?,
482491
): SourceOutput {
@@ -485,7 +494,7 @@ object ApolloCompiler {
485494
logger = logger,
486495
codegenSchemaOptions = codegenSchemaOptions,
487496
foreignSchemas = emptyList(),
488-
schemaTransform = schemaTransform
497+
schemaTransform = schemaDocumentTransform
489498
)
490499

491500
return buildSchemaAndOperationsSources(
@@ -498,7 +507,7 @@ object ApolloCompiler {
498507
irOperationsTransform,
499508
javaOutputTransform,
500509
kotlinOutputTransform,
501-
executableDocumentTransform,
510+
documentTransform,
502511
logger,
503512
operationManifestFile
504513
)
@@ -517,7 +526,7 @@ object ApolloCompiler {
517526
irOperationsTransform: Transform<IrOperations>?,
518527
javaOutputTransform: Transform<JavaOutput>?,
519528
kotlinOutputTransform: Transform<KotlinOutput>?,
520-
executableDocumentTransform: ExecutableDocumentTransform?,
529+
documentTransform: ExecutableDocumentTransform?,
521530
logger: Logger?,
522531
operationManifestFile: File?,
523532
): SourceOutput {
@@ -526,7 +535,7 @@ object ApolloCompiler {
526535
executableFiles = executableFiles,
527536
upstreamCodegenModels = emptyList(),
528537
upstreamFragmentDefinitions = emptyList(),
529-
executableDocumentTransform = executableDocumentTransform,
538+
documentTransform = documentTransform,
530539
options = irOptions,
531540
logger = logger
532541
)
@@ -642,6 +651,3 @@ fun interface LayoutFactory {
642651
fun create(codegenSchema: CodegenSchema): SchemaAndOperationsLayout?
643652
}
644653

645-
fun interface OperationIdsGenerator {
646-
fun generate(operationDescriptorList: Collection<OperationDescriptor>): List<OperationId>
647-
}

0 commit comments

Comments
 (0)