Skip to content

Commit

Permalink
Introduce SchemaLayout & OperationsLayout (#5573)
Browse files Browse the repository at this point in the history
* add buildCodegenOptions() for times when we want default values. In the Gradle plugin, use the primary constructor
introduce SchemaLayout & OperationsLayout

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

Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>

---------

Co-authored-by: Benoit 'BoD' Lubek <BoD@JRAF.org>
  • Loading branch information
martinbonnin and BoD committed Jan 29, 2024
1 parent 8e63501 commit 58fc2e4
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 499 deletions.
163 changes: 73 additions & 90 deletions libraries/apollo-compiler/api/apollo-compiler.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,14 @@ object ApolloCompiler {
): SourceOutput {
val irSchema = buildIrSchema(codegenSchema, usedCoordinates)

val targetLanguage = defaultTargetLanguage(codegenOptions.common.targetLanguage, emptyList())
val targetLanguage = defaultTargetLanguage(codegenOptions.targetLanguage, emptyList())
codegenOptions.validate()

return if (targetLanguage == TargetLanguage.JAVA) {
JavaCodegen.buildSchemaSources(
codegenSchema = codegenSchema,
irSchema = irSchema,
commonCodegenOptions = codegenOptions.common,
javaCodegenOptions = codegenOptions.java,
codegenOptions = codegenOptions,
packageNameGenerator = packageNameGenerator,
compilerJavaHooks = compilerJavaHooks ?: defaultCompilerJavaHooks,
).toSourceOutput()
Expand All @@ -322,20 +321,19 @@ object ApolloCompiler {
codegenSchema = codegenSchema,
targetLanguage = targetLanguage,
irSchema = irSchema,
commonCodegenOptions = codegenOptions.common,
kotlinCodegenOptions = codegenOptions.kotlin,
codegenOptions = codegenOptions,
packageNameGenerator = packageNameGenerator,
compilerKotlinHooks = compilerKotlinHooks ?: defaultCompilerKotlinHooks,
).toSourceOutput()
}
}

fun buildSchemaAndOperationSourcesFromIr(
fun buildSchemaAndOperationsSourcesFromIr(
codegenSchema: CodegenSchema,
irOperations: IrOperations,
downstreamUsedCoordinates: UsedCoordinates?,
upstreamCodegenMetadata: List<CodegenMetadata>,
codegenOptions: CodegenOptions = CodegenOptions(),
codegenOptions: CodegenOptions,
packageNameGenerator: PackageNameGenerator,
operationOutputGenerator: OperationOutputGenerator?,
compilerKotlinHooks: List<ApolloCompilerKotlinHooks>?,
Expand All @@ -344,7 +342,7 @@ object ApolloCompiler {
): SourceOutput {
check(irOperations is DefaultIrOperations)

val targetLanguage = defaultTargetLanguage(codegenOptions.common.targetLanguage, upstreamCodegenMetadata)
val targetLanguage = defaultTargetLanguage(codegenOptions.targetLanguage, upstreamCodegenMetadata)
codegenOptions.validate()

val operationOutput = irOperations.operations.map {
Expand All @@ -363,7 +361,7 @@ object ApolloCompiler {
""".trimMargin()
}

val operationManifestFormat = codegenOptions.common.operationManifestFormat
val operationManifestFormat = codegenOptions.operationManifestFormat
if ((operationManifestFormat ?: defaultOperationManifestFormat) != MANIFEST_NONE) {
check(operationManifestFile != null) {
"Apollo: no operationManifestFile set to output '$operationManifestFormat' operation manifest"
Expand Down Expand Up @@ -392,8 +390,7 @@ object ApolloCompiler {
irOperations = irOperations,
operationOutput = operationOutput,
upstreamCodegenMetadata = upstreamCodegenMetadata + listOfNotNull(sourceOutput?.codegenMetadata),
commonCodegenOptions = codegenOptions.common,
javaCodegenOptions = codegenOptions.java,
codegenOptions = codegenOptions,
packageNameGenerator = packageNameGenerator,
compilerJavaHooks = compilerJavaHooks,
).toSourceOutput()
Expand All @@ -404,8 +401,7 @@ object ApolloCompiler {
irOperations = irOperations,
operationOutput = operationOutput,
upstreamCodegenMetadata = upstreamCodegenMetadata + listOfNotNull(sourceOutput?.codegenMetadata),
commonCodegenOptions = codegenOptions.common,
kotlinCodegenOptions = codegenOptions.kotlin,
codegenOptions = codegenOptions,
packageNameGenerator = packageNameGenerator,
compilerKotlinHooks = compilerKotlinHooks,
).toSourceOutput()
Expand All @@ -417,7 +413,7 @@ object ApolloCompiler {
/**
* Compiles a set of files without serializing the intermediate results
*/
fun buildSchemaAndOperationSources(
fun buildSchemaAndOperationsSources(
schemaFiles: Set<File>,
executableFiles: Set<File>,
codegenSchemaOptions: CodegenSchemaOptions,
Expand Down Expand Up @@ -445,7 +441,7 @@ object ApolloCompiler {
logger = logger
)

val sourceOutput = buildSchemaAndOperationSourcesFromIr(
val sourceOutput = buildSchemaAndOperationsSourcesFromIr(
codegenSchema = codegenSchema,
irOperations = irOperations,
downstreamUsedCoordinates = emptyMap(),
Expand Down

0 comments on commit 58fc2e4

Please sign in to comment.