Akash Amin
12/20/2024, 8:43 PMInteger
overflows it never threw an error, but v3 throws an error e.g java.lang.IllegalStateException: 2927716020 cannot be converted to Int
seemingly related to the exactInt check here. We are under the process of migrating that field to Long by introducing a new scalar type on our graph, but while we migrate to it, is there a workaround that could be used to safely cast to Integer with overflow on v3?mbonnin
12/20/2024, 9:13 PMmbonnin
12/20/2024, 9:14 PMAkash Amin
12/20/2024, 9:19 PM3.8.5
, I'll try the custom implementationAkash Amin
12/20/2024, 9:35 PMaddCustomScalarAdapter(GraphQLInt.type, CustomIntegerAdapter)
) itself does not work do I have to set something on the apollo task on the build.gradle?
2. I am using a nextString
to read the value from the reader would that make sense?
class CustomIntegerAdapter : Adapter<Int> {
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters) =
reader.nextString()?.toInt() ?: 0
override fun toJson(
writer: JsonWriter,
customScalarAdapters: CustomScalarAdapters,
value: Int
) {
writer.value(value)
}
}
mbonnin
12/20/2024, 9:37 PMdo I have to set something on the apollo task on the build.gradle?Probably yes. If not the compiler will hardcode the IntAdapter, let me check quicly
mbonnin
12/20/2024, 9:38 PMI am using aYes. This is how arbitrary precision numbers are readto read the value from the reader would that make sense?nextString
mbonnin
12/20/2024, 9:38 PMmbonnin
12/20/2024, 9:41 PMmapScalar("Int", "<http://kotlin.Int|kotlin.Int>", "com.example.MyIntAdapter")
mbonnin
12/20/2024, 9:41 PMobject MyIntAdapter: Adapter<Int> {
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): Int {
return reader.nextString()!!.toLong().toInt()
}
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: Int) {
writer.value(value)
}
}
Akash Amin
12/20/2024, 9:42 PMmbonnin
12/20/2024, 9:42 PMtoLong().toInt()
, arithmetic is hard but I think this is what you wantAkash Amin
12/20/2024, 9:43 PMmbonnin
12/20/2024, 9:43 PM