I haven’t been able to correctly apply my scalar type adapter.
For my first try, I get an exception indicating “Check failed” from toJson(). I’m not performing any mutations so I was surprised but I assume it expects the output to match the input value.
val timeAdapter = object : Adapter<LocalDateTime> {
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): LocalDateTime {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
val time = reader.nextString()
return LocalDateTime.parse(time, formatter)
}
// If you do not expect your scalar to be used as input, you can leave this method as TODO()
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: LocalDateTime) {
writer.beginObject()
writer.writeAny(value.toString())
writer.endObject()
}
}
If I declare the function as TODO() I get an unimplemented exception
override fun toJson(writer: JsonWriter, customScalarAdapters: CustomScalarAdapters, value: LocalDateTime) {
TODO("Not yet implemented")
}
The documentation indicates that this is allowed if the adapter won’t be used to convert input values. What can I do to fix these?
I also tried the default adapter provided by Apollo, but it fails I think because my times are RFC3339, not ISO 8601.