Skip to content

Commit

Permalink
make nested adapter classes private. Fixes #2926 (#3188)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbonnin authored Jun 25, 2021
1 parent f233416 commit f911f23
Show file tree
Hide file tree
Showing 161 changed files with 407 additions and 372 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asTypeName

/**
* For responseBased codegen, generates an adapter for an implementation
*/
class ImplementationAdapterBuilder(
val context: CgContext,
val model: IrModel,
Expand All @@ -24,7 +27,8 @@ class ImplementationAdapterBuilder(
ResponseAdapterBuilder.create(
context,
it,
path + adapterName
path + adapterName,
false
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.apollographql.apollo3.api.Adapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.compiler.applyIf
import com.apollographql.apollo3.compiler.codegen.Identifier
import com.apollographql.apollo3.compiler.codegen.CgContext
import com.apollographql.apollo3.compiler.ir.IrModel
Expand All @@ -18,6 +19,7 @@ class MonomorphicFieldResponseAdapterBuilder(
val context: CgContext,
val model: IrModel,
val path: List<String>,
val public: Boolean,
) : ResponseAdapterBuilder {

private val adapterName = model.modelName
Expand All @@ -29,7 +31,8 @@ class MonomorphicFieldResponseAdapterBuilder(
ResponseAdapterBuilder.create(
context,
it,
path + adapterName
path + adapterName,
false
)
}

Expand All @@ -52,6 +55,9 @@ class MonomorphicFieldResponseAdapterBuilder(
context.resolver.resolveModel(model.id)
)
)
.applyIf(!public) {
addModifiers(KModifier.PRIVATE)
}
.addProperty(responseNamesPropertySpec(model))
.addFunction(readFromResponseFunSpec())
.addFunction(writeToResponseFunSpec())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.apollographql.apollo3.api.Adapter
import com.apollographql.apollo3.api.CustomScalarAdapters
import com.apollographql.apollo3.api.json.JsonReader
import com.apollographql.apollo3.api.json.JsonWriter
import com.apollographql.apollo3.compiler.applyIf
import com.apollographql.apollo3.compiler.codegen.Identifier
import com.apollographql.apollo3.compiler.codegen.Identifier.__typename
import com.apollographql.apollo3.compiler.codegen.Identifier.fromJson
Expand All @@ -27,6 +28,7 @@ class PolymorphicFieldResponseAdapterBuilder(
val context: CgContext,
val modelGroup: IrModelGroup,
val path: List<String>,
val public: Boolean,
) : ResponseAdapterBuilder {
private val baseModel = modelGroup.models.first {
it.id == modelGroup.baseModelId
Expand Down Expand Up @@ -70,6 +72,9 @@ class PolymorphicFieldResponseAdapterBuilder(
.addSuperinterface(
Adapter::class.asTypeName().parameterizedBy(adaptedClassName)
)
.applyIf(!public) {
addModifiers(KModifier.PRIVATE)
}
.addProperty(responseNamesPropertySpec())
.addFunction(readFromResponseFunSpec())
.addFunction(writeToResponseFunSpec())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ interface ResponseAdapterBuilder {
fun create(
context: CgContext,
modelGroup: IrModelGroup,
path: List<String>
path: List<String>,
public: Boolean
): ResponseAdapterBuilder = when(modelGroup.models.size) {
0 -> error("Don't know how to create an adapter for a scalar type")
1 -> MonomorphicFieldResponseAdapterBuilder(
context = context,
model = modelGroup.models.first(),
path = path
path = path,
public = public
)
else -> PolymorphicFieldResponseAdapterBuilder(
context = context,
modelGroup = modelGroup,
path = path
path = path,
public = public
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class FragmentResponseAdapterBuilder(
ResponseAdapterBuilder.create(
context = context,
modelGroup = it,
path = listOf(packageName, simpleName)
path = listOf(packageName, simpleName),
true
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class OperationResponseAdapterBuilder(
ResponseAdapterBuilder.create(
context = context,
modelGroup = it,
path = listOf(packageName, simpleName)
path = listOf(packageName, simpleName),
true
)
}

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.

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.

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.

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.

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.

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.

Loading

0 comments on commit f911f23

Please sign in to comment.