Skip to content

Keep compiler plugin in sync with v4 #6547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions libraries/apollo-compiler/api/apollo-compiler.api
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public final class com/apollographql/apollo/compiler/ApolloCompiler {
public static final field INSTANCE Lcom/apollographql/apollo/compiler/ApolloCompiler;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
}
Expand All @@ -31,15 +31,14 @@ public final class com/apollographql/apollo/compiler/ApolloCompilerKt {
}

public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerPlugin {
public abstract fun beforeCompilationStep (Lcom/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment;Lcom/apollographql/apollo/compiler/ApolloCompilerRegistry;)V
public fun beforeCompilationStep (Lcom/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment;Lcom/apollographql/apollo/compiler/ApolloCompilerRegistry;)V
public fun operationIds (Ljava/util/List;)Ljava/util/List;
}

public final class com/apollographql/apollo/compiler/ApolloCompilerPluginEnvironment {
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;Ljava/io/File;)V
public fun <init> (Ljava/util/Map;Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;)V
public final fun getArguments ()Ljava/util/Map;
public final fun getLogger ()Lcom/apollographql/apollo/compiler/ApolloCompilerPluginLogger;
public final fun getOutputDirectory ()Ljava/io/File;
}

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

public abstract interface class com/apollographql/apollo/compiler/ApolloCompilerRegistry {
public abstract fun registerExecutableDocumentTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/ExecutableDocumentTransform;)V
public abstract fun registerExtraCodeGenerator (Lcom/apollographql/apollo/compiler/CodeGenerator;)V
public abstract fun registerForeignSchemas (Ljava/util/List;)V
public abstract fun registerIrTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
public abstract fun registerJavaOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
public abstract fun registerKotlinOutputTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/Transform;)V
public abstract fun registerLayout (Lcom/apollographql/apollo/compiler/LayoutFactory;)V
public abstract fun registerOperationIdsGenerator (Lcom/apollographql/apollo/compiler/OperationIdsGenerator;)V
public abstract fun registerOperationsTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/OperationsTransform;)V
public abstract fun registerSchemaTransform (Ljava/lang/String;[Lcom/apollographql/apollo/compiler/Order;Lcom/apollographql/apollo/compiler/SchemaTransform;)V
}

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

public abstract interface class com/apollographql/apollo/compiler/CodeGenerator {
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;)V
public abstract fun generate (Lcom/apollographql/apollo/ast/GQLDocument;Ljava/io/File;)V
}

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

public abstract interface class com/apollographql/apollo/compiler/ExecutableDocumentTransform {
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLDocument;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDocument;
}

public final class com/apollographql/apollo/compiler/ExpressionAdapterInitializer : com/apollographql/apollo/compiler/AdapterInitializer {
public static final field Companion Lcom/apollographql/apollo/compiler/ExpressionAdapterInitializer$Companion;
public fun <init> (Ljava/lang/String;)V
Expand Down Expand Up @@ -372,10 +375,6 @@ public abstract interface class com/apollographql/apollo/compiler/OperationsCode
public abstract interface class com/apollographql/apollo/compiler/OperationsCodegenOptions : com/apollographql/apollo/compiler/JavaOperationsCodegenOptions, com/apollographql/apollo/compiler/KotlinOperationsCodegenOptions {
}

public abstract interface class com/apollographql/apollo/compiler/OperationsTransform {
public abstract fun transform (Lcom/apollographql/apollo/ast/Schema;Lcom/apollographql/apollo/ast/GQLDocument;Ljava/util/List;)Lcom/apollographql/apollo/ast/GQLDocument;
}

public final class com/apollographql/apollo/compiler/OptionsKt {
public static final field ADD_TYPENAME_ALWAYS Ljava/lang/String;
public static final field ADD_TYPENAME_IF_ABSTRACT Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import com.apollographql.apollo.compiler.codegen.kotlin.KotlinCodegen
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput
import com.apollographql.apollo.compiler.codegen.kotlin.toSourceOutput
import com.apollographql.apollo.compiler.codegen.plus
import com.apollographql.apollo.compiler.internal.ApolloOperationsTransform
import com.apollographql.apollo.compiler.internal.ApolloExecutableDocumentTransform
import com.apollographql.apollo.compiler.internal.checkApolloInlineFragmentsHaveTypeCondition
import com.apollographql.apollo.compiler.internal.checkApolloReservedEnumValueNames
import com.apollographql.apollo.compiler.internal.checkApolloTargetNameClashes
Expand Down Expand Up @@ -190,7 +190,7 @@ object ApolloCompiler {
upstreamCodegenModels: List<String>,
upstreamFragmentDefinitions: List<GQLFragmentDefinition>,
options: IrOptions,
operationsTransform: OperationsTransform?,
executableDocumentTransform: ExecutableDocumentTransform?,
logger: Logger?,
): IrOperations {
val schema = codegenSchema.schema
Expand Down Expand Up @@ -233,13 +233,13 @@ object ApolloCompiler {
/**
* Step 2, Modify the AST to add typename, key fields and call any user-provided transform.
*/
var document = ApolloOperationsTransform(options.addTypename ?: defaultAddTypename).transform(
var document = ApolloExecutableDocumentTransform(options.addTypename ?: defaultAddTypename).transform(
schema = schema,
document = GQLDocument(userDefinitions, sourceLocation = null),
upstreamFragmentDefinitions
)
if (operationsTransform != null) {
document = operationsTransform.transform(schema, document, upstreamFragmentDefinitions)
if (executableDocumentTransform != null) {
document = executableDocumentTransform.transform(schema, document, upstreamFragmentDefinitions)
}

/**
Expand Down Expand Up @@ -394,7 +394,7 @@ object ApolloCompiler {
}

val operationOutput = descriptors.toOperationOutput(
(operationIdsGenerator ?: defaultOperationOutputGenerator).generate(descriptors)
(operationIdsGenerator ?: defaultOperationIdsGenerator).generate(descriptors)
)

check(operationOutput.size == irOperations.operations.size) {
Expand Down Expand Up @@ -475,7 +475,7 @@ object ApolloCompiler {
irOperationsTransform: Transform<IrOperations>?,
javaOutputTransform: Transform<JavaOutput>?,
kotlinOutputTransform: Transform<KotlinOutput>?,
operationsTransform: OperationsTransform?,
executableDocumentTransform: ExecutableDocumentTransform?,
schemaTransform: SchemaTransform?,
logger: Logger?,
operationManifestFile: File?,
Expand All @@ -498,7 +498,7 @@ object ApolloCompiler {
irOperationsTransform,
javaOutputTransform,
kotlinOutputTransform,
operationsTransform,
executableDocumentTransform,
logger,
operationManifestFile
)
Expand All @@ -517,7 +517,7 @@ object ApolloCompiler {
irOperationsTransform: Transform<IrOperations>?,
javaOutputTransform: Transform<JavaOutput>?,
kotlinOutputTransform: Transform<KotlinOutput>?,
operationsTransform: OperationsTransform?,
executableDocumentTransform: ExecutableDocumentTransform?,
logger: Logger?,
operationManifestFile: File?,
): SourceOutput {
Expand All @@ -526,7 +526,7 @@ object ApolloCompiler {
executableFiles = executableFiles,
upstreamCodegenModels = emptyList(),
upstreamFragmentDefinitions = emptyList(),
operationsTransform = operationsTransform,
executableDocumentTransform = executableDocumentTransform,
options = irOptions,
logger = logger
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.apollographql.apollo.ast.ForeignSchema
import com.apollographql.apollo.ast.GQLDocument
import com.apollographql.apollo.ast.GQLFragmentDefinition
import com.apollographql.apollo.ast.Schema
import com.apollographql.apollo.compiler.codegen.SchemaAndOperationsLayout
import com.apollographql.apollo.compiler.codegen.java.JavaOutput
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinOutput
import com.apollographql.apollo.compiler.ir.IrOperations
Expand All @@ -32,7 +31,9 @@ interface ApolloCompilerPlugin {
* @param environment options and environment for the plugin.
* @param registry the registry where to register transformations.
*/
fun beforeCompilationStep(environment: ApolloCompilerPluginEnvironment, registry: ApolloCompilerRegistry)
fun beforeCompilationStep(environment: ApolloCompilerPluginEnvironment, registry: ApolloCompilerRegistry) {

}

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

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

@ApolloExperimental
fun registerOperationsTransform(id: String, vararg orders: Order, transform: OperationsTransform)
fun registerExecutableDocumentTransform(id: String, vararg orders: Order, transform: ExecutableDocumentTransform)
@ApolloExperimental
fun registerIrTransform(id: String, vararg orders: Order, transform: Transform<IrOperations>)

Expand All @@ -102,9 +98,9 @@ fun interface SchemaTransform {


/**
* A [OperationsTransform] transforms operations and fragments at build time. [OperationsTransform] can add or remove fields automatically, for an example.
* A [ExecutableDocumentTransform] transforms operations and fragments at build time. [ExecutableDocumentTransform] can add or remove fields automatically, for an example.
*/
fun interface OperationsTransform {
fun interface ExecutableDocumentTransform {
/**
* Transforms the given document.
*
Expand Down Expand Up @@ -141,7 +137,7 @@ fun interface CodeGenerator {
/**
* Transforms the given input into an output of the same type
*/
fun generate(schema: GQLDocument)
fun generate(schema: GQLDocument, outputDirectory: File)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class LegacyOperationIdsGenerator(private val plugin: ApolloCompilerPlu
@Suppress("DEPRECATION")
val operationIds = plugin.operationIds(operationDescriptorList.toList())
if (operationIds != null) {
println("Apollo: using ApolloCompiler.operationIds() is deprecated. Please use registry.registerOperationIdsGenerator() instead.")
println("Apollo: using ApolloCompilerPlugin.operationIds() is deprecated. Please use registry.registerOperationIdsGenerator() instead.")
return operationIds
}
return NoList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package com.apollographql.apollo.compiler
import com.apollographql.apollo.annotations.ApolloDeprecatedSince
import com.apollographql.apollo.annotations.ApolloExperimental
import com.apollographql.apollo.compiler.internal.sha256
import com.apollographql.apollo.compiler.operationoutput.OperationDescriptor
import com.apollographql.apollo.compiler.operationoutput.OperationId
import com.apollographql.apollo.compiler.operationoutput.OperationOutput
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import java.nio.charset.StandardCharsets

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

internal val defaultAlwaysGenerateTypesMatching = emptySet<String>()

internal val defaultOperationOutputGenerator = object : OperationIdsGenerator {

override fun generate(operationDescriptorList: Collection<OperationDescriptor>): List<OperationId> {
return operationDescriptorList.map {
OperationId(it.source.sha256(), it.name)
}
internal val defaultOperationIdsGenerator = OperationIdsGenerator { operationDescriptorList ->
operationDescriptorList.map {
OperationId(it.source.sha256(), it.name)
}
}

Expand Down
Loading
Loading