From cc5c076c5600b0a8da1953bea92d78a91cf06d63 Mon Sep 17 00:00:00 2001 From: Benoit 'BoD' Lubek Date: Tue, 22 Oct 2024 10:54:41 +0200 Subject: [PATCH] Do not add internal to private members (#6213) --- .../codegen/kotlin/helpers/add_internal.kt | 32 +++++++++++++------ .../enum_field/TestQuery.kt.expected | 2 +- .../TestQuery_ResponseAdapter.kt.expected | 2 +- .../TestQuerySelections.kt.expected | 2 +- .../type/GraphQLBoolean.kt.expected | 2 +- .../enum_field/type/GraphQLFloat.kt.expected | 2 +- .../enum_field/type/GraphQLID.kt.expected | 2 +- .../enum_field/type/GraphQLInt.kt.expected | 2 +- .../enum_field/type/GraphQLString.kt.expected | 2 +- .../enum_field/type/Gravity.kt.expected | 2 +- .../enum_field/type/GravityAsEnum.kt.expected | 2 +- .../enum_field/type/Query.kt.expected | 2 +- .../GravityAsEnum_ResponseAdapter.kt.expected | 2 +- .../Gravity_ResponseAdapter.kt.expected | 2 +- .../apollo/compiler/CodegenTest.kt | 2 +- 15 files changed, 36 insertions(+), 24 deletions(-) diff --git a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/helpers/add_internal.kt b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/helpers/add_internal.kt index d236376a1c8..497fda86c1d 100644 --- a/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/helpers/add_internal.kt +++ b/libraries/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/helpers/add_internal.kt @@ -28,24 +28,36 @@ fun FileSpec.Builder.addInternal(patterns: List): FileSpec.Builder = app } when (member) { is TypeSpec -> { - member.toBuilder() - .addModifiers(KModifier.INTERNAL) - .build() + if (member.modifiers.contains(KModifier.PRIVATE)) { + member + } else { + member.toBuilder() + .addModifiers(KModifier.INTERNAL) + .build() + } } is FunSpec -> { - member.toBuilder() - .addModifiers(KModifier.INTERNAL) - .build() + if (member.modifiers.contains(KModifier.PRIVATE)) { + member + } else { + member.toBuilder() + .addModifiers(KModifier.INTERNAL) + .build() + } } is PropertySpec -> { - member.toBuilder() - .addModifiers(KModifier.INTERNAL) - .build() + if (member.modifiers.contains(KModifier.PRIVATE)) { + member + } else { + member.toBuilder() + .addModifiers(KModifier.INTERNAL) + .build() + } } else -> error("Top Level $member is not supported") } } -} \ No newline at end of file +} diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/TestQuery.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/TestQuery.kt.expected index b3c1b65dc43..b5397a14041 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/TestQuery.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/TestQuery.kt.expected @@ -22,7 +22,7 @@ import kotlin.Int import kotlin.String import com.example.enum_field.type.Query as CompiledQuery -public class TestQuery() : Query { +internal class TestQuery() : Query { override fun equals(other: Any?): Boolean = other != null && other::class == this::class override fun hashCode(): Int = this::class.hashCode() diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/adapter/TestQuery_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/adapter/TestQuery_ResponseAdapter.kt.expected index 18a5358f2aa..a32f6341d0d 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/adapter/TestQuery_ResponseAdapter.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/adapter/TestQuery_ResponseAdapter.kt.expected @@ -18,7 +18,7 @@ import com.example.enum_field.type.adapter.Gravity_ResponseAdapter import kotlin.String import kotlin.collections.List -public object TestQuery_ResponseAdapter { +internal object TestQuery_ResponseAdapter { public object Data : Adapter { public val RESPONSE_NAMES: List = listOf("gravity", "gravityAsEnum") diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/selections/TestQuerySelections.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/selections/TestQuerySelections.kt.expected index 3d47d1ac809..5cf621e118b 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/selections/TestQuerySelections.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/selections/TestQuerySelections.kt.expected @@ -11,7 +11,7 @@ import com.example.enum_field.type.Gravity import com.example.enum_field.type.GravityAsEnum import kotlin.collections.List -public object TestQuerySelections { +internal object TestQuerySelections { public val __root: List = listOf( CompiledField.Builder( name = "gravity", diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLBoolean.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLBoolean.kt.expected index 2b8f79162c6..c9c1ee28e75 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLBoolean.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLBoolean.kt.expected @@ -10,7 +10,7 @@ import com.apollographql.apollo.api.CustomScalarType /** * The `Boolean` scalar type represents `true` or `false`. */ -public class GraphQLBoolean { +internal class GraphQLBoolean { public companion object { public val type: CustomScalarType = CustomScalarType("Boolean", "kotlin.Boolean") } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLFloat.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLFloat.kt.expected index 26eb09c2064..15a794081f0 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLFloat.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLFloat.kt.expected @@ -11,7 +11,7 @@ import com.apollographql.apollo.api.CustomScalarType * The `Float` scalar type represents signed double-precision fractional values as specified by * [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point). */ -public class GraphQLFloat { +internal class GraphQLFloat { public companion object { public val type: CustomScalarType = CustomScalarType("Float", "kotlin.Double") } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLID.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLID.kt.expected index 5410d9ca416..020507a33a0 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLID.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLID.kt.expected @@ -13,7 +13,7 @@ import com.apollographql.apollo.api.CustomScalarType * human-readable. When expected as an input type, any string (such as `"4"`) or integer (such as `4`) * input value will be accepted as an ID. */ -public class GraphQLID { +internal class GraphQLID { public companion object { public val type: CustomScalarType = CustomScalarType("ID", "kotlin.String") } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLInt.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLInt.kt.expected index 26ae7e79a44..b7ff16d6df5 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLInt.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLInt.kt.expected @@ -11,7 +11,7 @@ import com.apollographql.apollo.api.CustomScalarType * The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent * values between -(2^31) and 2^31 - 1. */ -public class GraphQLInt { +internal class GraphQLInt { public companion object { public val type: CustomScalarType = CustomScalarType("Int", "kotlin.Int") } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLString.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLString.kt.expected index 6005ba6fa6c..db17d6dd1ac 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLString.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GraphQLString.kt.expected @@ -11,7 +11,7 @@ import com.apollographql.apollo.api.CustomScalarType * The `String` scalar type represents textual data, represented as UTF-8 character sequences. The * String type is most often used by GraphQL to represent free-form human-readable text. */ -public class GraphQLString { +internal class GraphQLString { public companion object { public val type: CustomScalarType = CustomScalarType("String", "kotlin.String") } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected index d5e59d51872..9bd820a6312 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Gravity.kt.expected @@ -14,7 +14,7 @@ import kotlin.Int import kotlin.String import kotlin.Suppress -public sealed interface Gravity { +internal sealed interface Gravity { public val rawValue: kotlin.String public companion object { diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected index 274c3f4f0e1..3654005ee80 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/GravityAsEnum.kt.expected @@ -11,7 +11,7 @@ import kotlin.Deprecated import kotlin.Suppress import kotlin.collections.List -public enum class GravityAsEnum( +internal enum class GravityAsEnum( public val rawValue: kotlin.String, ) { TOP("TOP"), diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Query.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Query.kt.expected index dff04f11528..cb704155291 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Query.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/Query.kt.expected @@ -7,7 +7,7 @@ package com.example.enum_field.type import com.apollographql.apollo.api.ObjectType -public class Query { +internal class Query { public companion object { public val type: ObjectType = ObjectType.Builder(name = "Query").build() } diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/GravityAsEnum_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/GravityAsEnum_ResponseAdapter.kt.expected index 9dca6f59136..973e0c959ef 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/GravityAsEnum_ResponseAdapter.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/GravityAsEnum_ResponseAdapter.kt.expected @@ -11,7 +11,7 @@ import com.apollographql.apollo.api.json.JsonReader import com.apollographql.apollo.api.json.JsonWriter import com.example.enum_field.type.GravityAsEnum -public object GravityAsEnum_ResponseAdapter : Adapter { +internal object GravityAsEnum_ResponseAdapter : Adapter { override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): GravityAsEnum { val rawValue = reader.nextString()!! diff --git a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/Gravity_ResponseAdapter.kt.expected b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/Gravity_ResponseAdapter.kt.expected index f080c88d1a9..986ab4c32fe 100644 --- a/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/Gravity_ResponseAdapter.kt.expected +++ b/libraries/apollo-compiler/src/test/graphql/com/example/enum_field/kotlin/responseBased/enum_field/type/adapter/Gravity_ResponseAdapter.kt.expected @@ -11,7 +11,7 @@ import com.apollographql.apollo.api.json.JsonReader import com.apollographql.apollo.api.json.JsonWriter import com.example.enum_field.type.Gravity -public object Gravity_ResponseAdapter : Adapter { +internal object Gravity_ResponseAdapter : Adapter { override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Gravity { val rawValue = reader.nextString()!! return Gravity.safeValueOf(rawValue) diff --git a/libraries/apollo-compiler/src/test/kotlin/com/apollographql/apollo/compiler/CodegenTest.kt b/libraries/apollo-compiler/src/test/kotlin/com/apollographql/apollo/compiler/CodegenTest.kt index 88ea2f17f57..b474967cc28 100644 --- a/libraries/apollo-compiler/src/test/kotlin/com/apollographql/apollo/compiler/CodegenTest.kt +++ b/libraries/apollo-compiler/src/test/kotlin/com/apollographql/apollo/compiler/CodegenTest.kt @@ -391,7 +391,7 @@ class CodegenTest { } val generateAsInternal = when (folder.name) { - "mutation_create_review", "simple_fragment" -> true + "mutation_create_review", "simple_fragment", "enum_field" -> true else -> false }