Skip to content

Commit

Permalink
Revert compile time possible types (#5842)
Browse files Browse the repository at this point in the history
* Revert "fun => val (#5826)"

This reverts commit a0db6ad.

* Revert "Add compile time possibleTypes (#5823)"

This reverts commit 0aedd8c.
  • Loading branch information
martinbonnin committed Apr 22, 2024
1 parent e7472f7 commit 14da50d
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ internal object KotlinCodegen {
builders.add(ObjectBuilder(context, irObject, generateDataBuilders))
}
if (generateSchema && context.resolver.resolve(ResolverKey(ResolverKeyKind.Schema, "")) == null) {
builders.add(SchemaBuilder(context, codegenSchema.schema, irSchema.irObjects, irSchema.irInterfaces, irSchema.irUnions, irSchema.irEnums))
builders.add(SchemaBuilder(context, irSchema.irObjects, irSchema.irInterfaces, irSchema.irUnions, irSchema.irEnums))
builders.add(CustomScalarAdaptersBuilder(context, scalarMapping))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.apollographql.apollo3.compiler.codegen.kotlin.schema


import com.apollographql.apollo3.ast.Schema
import com.apollographql.apollo3.compiler.codegen.Identifier.type
import com.apollographql.apollo3.compiler.codegen.kotlin.CgFile
import com.apollographql.apollo3.compiler.codegen.kotlin.CgFileBuilder
import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinSchemaContext
import com.apollographql.apollo3.compiler.codegen.kotlin.KotlinSymbols
import com.apollographql.apollo3.compiler.codegen.schemaSubPackageName
import com.apollographql.apollo3.compiler.decapitalizeFirstLetter
import com.apollographql.apollo3.compiler.ir.IrEnum
import com.apollographql.apollo3.compiler.ir.IrInterface
import com.apollographql.apollo3.compiler.ir.IrObject
Expand All @@ -20,12 +18,9 @@ import com.squareup.kotlinpoet.MemberName
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.buildCodeBlock
import com.squareup.kotlinpoet.joinToCode

internal class SchemaBuilder(
private val context: KotlinSchemaContext,
private val schema: Schema,
private val objects: List<IrObject>,
private val interfaces: List<IrInterface>,
private val unions: List<IrUnion>,
Expand Down Expand Up @@ -70,25 +65,6 @@ internal class SchemaBuilder(
.addKdoc("A __Schema object containing all the composite types and a possibleTypes helper function")
.addProperty(typesPropertySpec())
.addFunction(possibleTypesFunSpec())
.apply {
(interfaces + unions).forEach {
addProperty(possibleTypesPropertySpec(it.name, schema.possibleTypes(schema.typeDefinition(it.name))))
}
}
.build()
}

private fun possibleTypesPropertySpec(name: String, possibleTypes: Set<String>): PropertySpec {
return PropertySpec.builder("${name.decapitalizeFirstLetter()}PossibleTypes", KotlinSymbols.List.parameterizedBy(KotlinSymbols.ObjectType))
.initializer(
buildCodeBlock {
add("listOf(")
add(possibleTypes.map {
CodeBlock.of("%L.$type", context.resolver.resolveSchemaType(it))
}.joinToCode(", "))
add(")")
}
)
.build()
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// If you updated the codegen and test fixtures, you should commit this file too.

Test: Total LOC:
aggregate-all 204924
aggregate-kotlin-responseBased 65822
aggregate-kotlin-operationBased 42426
aggregate-all 204879
aggregate-kotlin-responseBased 65795
aggregate-kotlin-operationBased 42408
aggregate-kotlin-compat 0
aggregate-java-operationBased 96676

Expand All @@ -13,9 +13,9 @@ kotlin-operationBased-fragments_with_defer_and_include_directives
java-operationBased-data_builders 3031
java-operationBased-mutation_create_review 2435
kotlin-responseBased-fragment_with_inline_fragment 2422
kotlin-responseBased-data_builders 2365
kotlin-responseBased-data_builders 2355
java-operationBased-fragment_with_inline_fragment 2261
kotlin-operationBased-data_builders 2014
kotlin-operationBased-data_builders 2004
java-operationBased-nested_named_fragments 1910
java-operationBased-fragment_spread_with_include_directive 1667
java-operationBased-union_inline_fragments 1666
Expand All @@ -27,7 +27,7 @@ java-operationBased-mutation_create_review_semantic_naming
java-operationBased-root_query_fragment_with_nested_fragments 1607
java-operationBased-simple_fragment 1505
java-operationBased-named_fragment_delegate 1493
kotlin-responseBased-mutation_create_review 1463
kotlin-responseBased-mutation_create_review 1454
java-operationBased-named_fragment_with_variables 1405
kotlin-responseBased-named_fragment_delegate 1371
kotlin-responseBased-unique_type_name 1354
Expand All @@ -42,7 +42,7 @@ kotlin-operationBased-nested_named_fragments
kotlin-responseBased-inline_fragment_intersection 1245
java-operationBased-two_heroes_with_friends 1241
java-operationBased-inline_fragment_merge_fields 1229
kotlin-responseBased-simple_fragment 1203
kotlin-responseBased-simple_fragment 1195
java-operationBased-named_fragment_inside_inline_fragment 1186
java-operationBased-fragments_with_type_condition 1183
java-operationBased-target_name 1168
Expand All @@ -69,7 +69,7 @@ kotlin-operationBased-root_query_fragment_with_nested_fragments
java-operationBased-inline_fragments_with_friends 1056
java-operationBased-fragment_spread_with_nested_fields 1054
kotlin-responseBased-simple_fragment_with_inline_fragments 1052
kotlin-operationBased-simple_fragment 1051
kotlin-operationBased-simple_fragment 1043
java-operationBased-operationbased2_ex8 1042
kotlin-operationBased-named_fragment_delegate 1013
java-operationBased-decapitalized_fields 993
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14da50d

Please sign in to comment.