Skip to content
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

Workaround for Name Too Long violations with responseBased code generation #5480

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f14d88e
Staging the changes which will allow us to include a directive set by…
AdamMTGreenberg Nov 17, 2023
8007f5c
Creating the file model for the explicitly remove class which we want…
AdamMTGreenberg Nov 17, 2023
16bfb88
Implementing the flattening algorithm for ensuring that the system wi…
AdamMTGreenberg Nov 17, 2023
068aa7a
Creation of a Test suite for the manual flattening based on naming co…
AdamMTGreenberg Nov 17, 2023
a017ace
Remove the old tests
AdamMTGreenberg Nov 17, 2023
0543176
Baseline tests for the experimental gradle option
AdamMTGreenberg Nov 17, 2023
27a7981
"Fixing lint errors"
AdamMTGreenberg Nov 18, 2023
9ebddb9
Creating the baseline test setup for the CodeGen test to include the …
AdamMTGreenberg Nov 28, 2023
a7d0a30
Updated the schema and query with a lot of silly names
AdamMTGreenberg Nov 28, 2023
bb9f819
Query can be query can be added to the query name it isn't good
AdamMTGreenberg Nov 28, 2023
5081e2a
Query can be query can be added to the query name it isn't good
AdamMTGreenberg Nov 28, 2023
324391d
Enable the inclusion of Fragmnets in responseBased outputs
AdamMTGreenberg Nov 28, 2023
d796820
Introduce the test JSON
AdamMTGreenberg Nov 28, 2023
51c9da0
Introduce the expected behavior output
AdamMTGreenberg Nov 28, 2023
9cdf347
All expected files belong in the com.example package
AdamMTGreenberg Nov 28, 2023
5e755a9
General changes and cleanup
AdamMTGreenberg Nov 28, 2023
fbdb95d
Cleanup package names
AdamMTGreenberg Nov 28, 2023
add3d31
Updating the fragment files
AdamMTGreenberg Nov 28, 2023
8ed94bd
Add in the operationBased tests just to ensure
AdamMTGreenberg Nov 28, 2023
5c17853
Eliminate the test of java
AdamMTGreenberg Nov 28, 2023
9015ae6
No com.example in the expected hierarchy
AdamMTGreenberg Nov 28, 2023
aff7b60
Correct the package names
AdamMTGreenberg Nov 28, 2023
d30db1d
Replace the version with a version alias
AdamMTGreenberg Nov 28, 2023
e97d69f
Compile til it breaks - fixing the test variables
AdamMTGreenberg Nov 29, 2023
b7b0ed2
This test is uncovering all sorts of breaks - building out the nested…
AdamMTGreenberg Nov 29, 2023
1788cac
Flatten the adapter
AdamMTGreenberg Nov 29, 2023
36e9bc1
Fixing code for the fragments as well as updating the cases where we …
AdamMTGreenberg Nov 29, 2023
5ec4a52
New boolean value
AdamMTGreenberg Dec 5, 2023
7047e9b
Updating expected with generated variables
AdamMTGreenberg Dec 7, 2023
b5fcf77
Updating expected output
AdamMTGreenberg Dec 8, 2023
b4feadd
Since we do not expect to support operationBased changes in this gral…
AdamMTGreenberg Dec 14, 2023
db3dea2
Updating the pieces for the api changes due to the new flattenExplici…
AdamMTGreenberg Dec 14, 2023
152e1bd
Updating the pieces for the api changes due to the new flattenExplici…
AdamMTGreenberg Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private fun ApolloGradleToolingModel.toTelemetryProperties(): Set<TelemetryPrope
it.jsExport?.let { add(ApolloJsExport(it)) }
it.addTypename?.let { add(ApolloAddTypename(it)) }
it.flattenModels?.let { add(ApolloFlattenModels(it)) }
it.flattenModelsExplicitly?.let { add(TelemetryProperty.ApolloFlattenModelsExplicitly(it)) }
it.fieldsOnDisjointTypesMustMerge?.let { add(ApolloFieldsOnDisjointTypesMustMerge(it)) }
it.generateApolloMetadata?.let { add(ApolloGenerateApolloMetadata(it)) }
add(ApolloUsedOptions(it.usedOptions.toList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ sealed class TelemetryProperty(
*/
class ApolloFlattenModels(flattenModels: Boolean) : TelemetryProperty("ak_flatten_models", flattenModels)

/**
* Value of the Apollo Kotlin option `flattenModelsExplicitly` if set.
*/
class ApolloFlattenModelsExplicitly(flattenModelsExplicitly: String) : TelemetryProperty("ak_flatten_models_explicitly", flattenModelsExplicitly)

/**
* Value of the Apollo Kotlin option `fieldsOnDisjointTypesMustMerge` if set.
*/
Expand Down
24 changes: 24 additions & 0 deletions libraries/apollo-compiler/api/apollo-compiler.api
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public final class com/apollographql/apollo3/compiler/OptionsKt {
public static final field defaultFailOnWarnings Z
public static final field defaultFieldsOnDisjointTypesMustMerge Z
public static final field defaultFlattenModels Z
public static final field defaultFlattenModelsExplicitly Ljava/lang/String;
public static final field defaultGenerateAsInternal Z
public static final field defaultGenerateDataBuilders Z
public static final field defaultGenerateFilterNotNull Z
Expand Down Expand Up @@ -397,6 +398,29 @@ public final class com/apollographql/apollo3/compiler/codegen/java/adapter/Adapt
public static synthetic fun singletonAdapterInitializer$default (Lcom/squareup/javapoet/TypeName;Lcom/squareup/javapoet/TypeName;ZILjava/lang/Object;)Lcom/squareup/javapoet/CodeBlock;
}

public final class com/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedNode$Companion {
public final fun buildTree (Ljava/util/List;)Lcom/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedNode;
}

public final class com/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClasses$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClasses$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClasses;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClasses;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClasses$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/codegen/kotlin/experimental/ExplicitlyRemovedSubClassesKt {
public static final fun buildFileFromUserDir (Ljava/lang/String;)Ljava/io/File;
}

public final class com/apollographql/apollo3/compiler/ir/IrCatchTo : java/lang/Enum {
public static final field Companion Lcom/apollographql/apollo3/compiler/ir/IrCatchTo$Companion;
public static final field NoCatch Lcom/apollographql/apollo3/compiler/ir/IrCatchTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ object ApolloCompiler {
codegenModels = codegenModels,
generateOptionalOperationVariables = options.generateOptionalOperationVariables,
flattenModels = options.flattenModels,
flattenModelsExplicitly = options.flattenModelsExplicitly,
decapitalizeFields = options.decapitalizeFields,
alwaysGenerateTypesMatching = options.alwaysGenerateTypesMatching,
generateDataBuilders = options.codegenSchema.generateDataBuilders,
Expand Down Expand Up @@ -363,6 +364,11 @@ object ApolloCompiler {
"enclosing one.")
}

if (ir.flattenModelsExplicitly != "") {
error("Java codegen does not support flattening nested models explicitly as it could trigger name clashes when a nested class has " +
"the same name as an enclosing one.")
}

return CodegenMetadata(
JavaCodeGen(
commonCodegenOptions = commonCodegenOptions,
Expand Down Expand Up @@ -412,6 +418,7 @@ object ApolloCompiler {
failOnWarnings: Boolean = defaultFailOnWarnings,
logger: Logger = defaultLogger,
flattenModels: Boolean = defaultFlattenModels,
flattenModelsExplicitly: String = defaultFlattenModelsExplicitly,
codegenModels: String = defaultCodegenModels,
addTypename: String = defaultAddTypename,
decapitalizeFields: Boolean = defaultDecapitalizeFields,
Expand Down Expand Up @@ -469,6 +476,7 @@ object ApolloCompiler {
failOnWarnings = failOnWarnings,
logger = logger,
flattenModels = flattenModels,
flattenModelsExplicitly = flattenModelsExplicitly,
incomingFragments = emptyList(),
addTypename = addTypename,
decapitalizeFields = decapitalizeFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ class IrOptions(

val flattenModels: Boolean,

val flattenModelsExplicitly: String,

val warnOnDeprecatedUsages: Boolean,
val failOnWarnings: Boolean,
val logger: ApolloCompiler.Logger,
Expand Down Expand Up @@ -431,6 +433,7 @@ const val defaultCodegenModels = MODELS_OPERATION_BASED
const val defaultAddTypename = ADD_TYPENAME_IF_FRAGMENTS
const val defaultRequiresOptInAnnotation = "none"
const val defaultFlattenModels = true
const val defaultFlattenModelsExplicitly = ""
val defaultTargetLanguage = TargetLanguage.KOTLIN_1_5
const val defaultGenerateSchema = false
const val defaultGeneratedSchemaName = "__Schema"
Expand Down