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

[compiler] remove unused argument to scalarAdapterInitializer() #5996

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,28 +182,28 @@ internal class KotlinResolver(
is IrListType2 -> adapterInitializer2(type.ofType, jsExport)?.list(jsExport)
is IrScalarType2 -> {
if (scalarMapping.containsKey(type.name)) {
scalarAdapterInitializer(type.name, customScalarAdapters)
scalarAdapterInitializer(type.name)
} else {
null
}
}

is IrEnumType2 -> {
adapterInitializer(IrEnumType(type.name), false, jsExport, "")
adapterInitializer(IrEnumType(type.name), false, jsExport)
}

is IrCompositeType2 -> null
}
}

internal fun adapterInitializer(type: IrType, requiresBuffering: Boolean, jsExport: Boolean, runtimeAdapterPrefix: String): CodeBlock {
internal fun adapterInitializer(type: IrType, requiresBuffering: Boolean, jsExport: Boolean): CodeBlock {
return when {
type.optional -> {
val presentFun = MemberName("com.apollographql.apollo3.api", "present")
CodeBlock.of("%L.%M()", adapterInitializer(type.optional(false), requiresBuffering, jsExport, runtimeAdapterPrefix), presentFun)
CodeBlock.of("%L.%M()", adapterInitializer(type.optional(false), requiresBuffering, jsExport), presentFun)
}
type.catchTo != IrCatchTo.NoCatch -> {
adapterInitializer(type.catchTo(IrCatchTo.NoCatch), requiresBuffering, jsExport, runtimeAdapterPrefix).let {
adapterInitializer(type.catchTo(IrCatchTo.NoCatch), requiresBuffering, jsExport).let {
val member = when (type.catchTo) {
IrCatchTo.Null -> KotlinSymbols.catchToNull
IrCatchTo.Result -> KotlinSymbols.catchToResult
Expand All @@ -213,7 +213,7 @@ internal class KotlinResolver(
}
}
type.maybeError -> {
adapterInitializer(type.maybeError(false), requiresBuffering, jsExport, runtimeAdapterPrefix).let {
adapterInitializer(type.maybeError(false), requiresBuffering, jsExport).let {
CodeBlock.of("%L.%M()", it, KotlinSymbols.errorAware)
}
}
Expand All @@ -232,23 +232,23 @@ internal class KotlinResolver(

else -> {
val nullableFun = MemberName("com.apollographql.apollo3.api", "nullable")
CodeBlock.of("%L.%M()", adapterInitializer(type.nullable(false), requiresBuffering, jsExport, runtimeAdapterPrefix), nullableFun)
CodeBlock.of("%L.%M()", adapterInitializer(type.nullable(false), requiresBuffering, jsExport), nullableFun)
}
}
}
else -> {
when (type) {
is IrListType -> {
adapterInitializer(type.ofType, requiresBuffering, jsExport, runtimeAdapterPrefix).list(jsExport)
adapterInitializer(type.ofType, requiresBuffering, jsExport).list(jsExport)
}

is IrScalarType -> {
scalarAdapterInitializer(type.name, runtimeAdapterPrefix)
scalarAdapterInitializer(type.name)
}

is IrEnumType -> {
if (jsExport) {
scalarAdapterInitializer("String", runtimeAdapterPrefix)
scalarAdapterInitializer("String")
} else {
CodeBlock.of("%T", resolveAndAssert(ResolverKeyKind.SchemaTypeAdapter, type.name))
}
Expand All @@ -272,7 +272,7 @@ internal class KotlinResolver(
return CodeBlock.of("%T.$type", resolveAndAssert(ResolverKeyKind.SchemaType, name))
}

private fun scalarAdapterInitializer(name: String, runtimeAdaptersPrefix: String): CodeBlock {
private fun scalarAdapterInitializer(name: String): CodeBlock {
return when (val adapterInitializer = scalarMapping[name]?.adapterInitializer) {
is ExpressionAdapterInitializer -> {
CodeBlock.of(adapterInitializer.expression)
Expand All @@ -281,7 +281,7 @@ internal class KotlinResolver(
is RuntimeAdapterInitializer -> {
val target = resolveScalarTarget(name)
CodeBlock.of(
"$runtimeAdaptersPrefix.responseAdapterFor<%T>(%L)",
"$customScalarAdapters.responseAdapterFor<%T>(%L)",
target,
resolveCompiledType(name)
)
Expand All @@ -300,7 +300,7 @@ internal class KotlinResolver(
CodeBlock.of("%M", KotlinSymbols.AnyAdapter)
} else {
CodeBlock.of(
"$runtimeAdaptersPrefix.responseAdapterFor<%T>(%L)",
"$customScalarAdapters.responseAdapterFor<%T>(%L)",
target,
resolveCompiledType(name)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal fun readFromResponseCodeBlock(
.add(
regularProperties.mapIndexed { index, property ->
val variableName = property.info.responseName.variableName()
val adapterInitializer = context.resolver.adapterInitializer(property.info.type, property.requiresBuffering, context.jsExport, customScalarAdapters)
val adapterInitializer = context.resolver.adapterInitializer(property.info.type, property.requiresBuffering, context.jsExport)
CodeBlock.of(
"%L·->·%N·=·%L.$fromJson($reader,·${customScalarAdapters})",
index,
Expand Down Expand Up @@ -215,7 +215,7 @@ private fun IrProperty.writeToResponseCodeBlock(context: KotlinContext): CodeBlo
val propertyName = context.layout.propertyName(info.responseName)

if (!isSynthetic) {
val adapterInitializer = context.resolver.adapterInitializer(info.type, requiresBuffering, context.jsExport, customScalarAdapters)
val adapterInitializer = context.resolver.adapterInitializer(info.type, requiresBuffering, context.jsExport)
builder.addStatement("${writer}.name(%S)", info.responseName)
builder.addStatement(
"%L.$toJson($writer, $customScalarAdapters, $value.%N)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private fun List<NamedType>.writeToResponseCodeBlock(context: KotlinContext): Co
}

private fun NamedType.writeToResponseCodeBlock(context: KotlinContext): CodeBlock {
val adapterInitializer = context.resolver.adapterInitializer(type, false, context.jsExport, customScalarAdapters)
val adapterInitializer = context.resolver.adapterInitializer(type, false, context.jsExport)
val builder = CodeBlock.builder()
val propertyName = context.layout.propertyName(graphQlName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal fun adapterFunSpec(
.addCode(
CodeBlock.of(
"return·%L",
context.resolver.adapterInitializer(type, property.requiresBuffering, context.jsExport, "")
context.resolver.adapterInitializer(type, property.requiresBuffering, context.jsExport)
)
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private fun List<IrVariable>.writeToResponseCodeBlock(context: KotlinContext): C
}

private fun IrVariable.writeToResponseCodeBlock(context: KotlinContext): CodeBlock {
val adapterInitializer = context.resolver.adapterInitializer(type, false, context.jsExport, customScalarAdapters)
val adapterInitializer = context.resolver.adapterInitializer(type, false, context.jsExport)
val builder = CodeBlock.builder()
val propertyName = context.layout.propertyName(name)

Expand Down
Loading