-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Kotlin generated resolver interface open class methods throw NotImplementedError
by default for both nullable and non-nullable fields. This default implementation might lead to runtime errors (explained below) , especially for nullable fields.
Another limitation, if we need resolver methods only for specific fields which require heavy operation, that is not possible as per current generated code. Resolver methods are created for all the fields in the type.
Suggestion: If we generate abstract class instead of open class, that will help resolve both the issues.
We can have:
- abstract val for non-nullable fields (must be initialized by child class)
- abstract fun for non-nullable fields requiring heavy operation (must be overridden by child class)
- open fun for nullable fields which return null by default (optionally overridden by child class)
Explanation of issues that can be caused due to current default implementation:
If we use the generated resolver interface, it provides default implementation for fields with NotImplementedError() like this:
open class MyTypeInterface {
open suspend fun field1(): Type? = throw NotImplementedError()
open suspend fun field2(): Type? = throw NotImplementedError()
}
and in the implementation when we extend the open class and may or may not override the methods
class MyType : MyTypeInterface() {
override suspend fun field1(): Type? = resolveField1()
override suspend fun field2(): Type? = resolveField2()
}
Now, let's say field2 is no longer required, so the override is removed from implementation OR we force update the schema and remove field2
Since the old versions of native clients which have the older schema may still query the field, this will fallback to the base implementation to throw NotImplementedError() which will cause runtime exception and maybe even app crash.
Especially for nullable fields, the default implementation should be to return null.