diff --git a/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinProjectModelService.kt b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinProjectModelService.kt index 46d4224..5558da7 100644 --- a/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinProjectModelService.kt +++ b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/ApolloKotlinProjectModelService.kt @@ -8,7 +8,6 @@ import com.apollographql.apollo.compiler.model.CompilationUnitModel import com.apollographql.apollo.compiler.model.ProjectModel import com.apollographql.apollo.compiler.model.toCompilationUnitModel import com.apollographql.apollo.compiler.model.toProjectModel -import com.apollographql.apollo.compiler.toCodegenOptions import com.apollographql.apollo.gradle.api.ApolloGradleToolingModel import com.apollographql.apollo.tooling.model.TelemetryData import com.apollographql.apollo.tooling.model.toTelemetryData diff --git a/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Json.kt b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Json.kt new file mode 100644 index 0000000..590b0af --- /dev/null +++ b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Json.kt @@ -0,0 +1,66 @@ +package com.apollographql.ijplugin.gradle + +import com.apollographql.apollo.compiler.CodegenOptions +import com.apollographql.apollo.compiler.CodegenSchemaOptions +import com.apollographql.apollo.compiler.IrOptions +import kotlinx.serialization.json.Json +import java.io.File + +// We are linking with a version of apollo-compiler that may be outdated and we might read files that contain new (unknown at that time) fields +private val json = Json { + ignoreUnknownKeys = true + explicitNulls = false + coerceInputValues = true +} + +private inline fun File.parseFromJson(): T { + return json.decodeFromString(readText()) +} + +fun File.toCodegenOptions(): CodegenOptions = runCatching { parseFromJson() }.getOrElse { + CodegenOptions( + targetLanguage = null, + packageName = null, + rootPackageName = null, + decapitalizeFields = null, + useSemanticNaming = null, + generateMethods = null, + operationManifestFormat = null, + generateSchema = null, + generatedSchemaName = null, + sealedClassesForEnumsMatching = null, + generateApolloEnums = null, + generateAsInternal = null, + addUnknownForEnums = null, + addDefaultArgumentForInputObjects = null, + generateFilterNotNull = null, + generateInputBuilders = null, + addJvmOverloads = null, + requiresOptInAnnotation = null, + jsExport = null, + generateModelBuilders = null, + classesForEnumsMatching = null, + generatePrimitiveTypes = null, + nullableFieldStyle = null, + generateFragmentImplementations = null, + generateQueryDocument = null, + ) +} + +fun File.toCodegenSchemaOptions(): CodegenSchemaOptions = runCatching { parseFromJson() }.getOrElse { + CodegenSchemaOptions() +} + +fun File.toIrOptions(): IrOptions = runCatching { parseFromJson() }.getOrElse { + IrOptions( + fieldsOnDisjointTypesMustMerge = null, + decapitalizeFields = null, + flattenModels = null, + warnOnDeprecatedUsages = null, + failOnWarnings = null, + addTypename = null, + generateOptionalOperationVariables = null, + alwaysGenerateTypesMatching = null, + codegenModels = null, + ) +} diff --git a/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Telemetry.kt b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Telemetry.kt index 40d522f..6ffec71 100644 --- a/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Telemetry.kt +++ b/plugin/src/main/kotlin/com/apollographql/ijplugin/gradle/Telemetry.kt @@ -3,9 +3,6 @@ package com.apollographql.ijplugin.gradle import com.apollographql.apollo.annotations.ApolloExperimental import com.apollographql.apollo.annotations.ApolloInternal import com.apollographql.apollo.compiler.TargetLanguage -import com.apollographql.apollo.compiler.toCodegenOptions -import com.apollographql.apollo.compiler.toCodegenSchemaOptions -import com.apollographql.apollo.compiler.toIrOptions import com.apollographql.apollo.gradle.api.ApolloGradleToolingModel import com.apollographql.apollo.tooling.model.TelemetryData import com.apollographql.ijplugin.telemetry.TelemetryProperty