https://kotlinlang.org logo
#graphql-kotlin
Title
# graphql-kotlin
r

rocketraman

02/15/2022, 5:25 AM
I'm thinking about having my query response types use functions to load data as needed. For example:
Copy code
data class SomeSuccessType(
  val foo: Foo,
  @property:GraphQLIgnore val bar: suspend () -> Bar?,
) {
  suspend fun bar() = bar.invoke()
}
With this approach my data model does not need to know anything about the various services and such being used to look up this data (like in the example given at https://opensource.expediagroup.com/graphql-kotlin/docs/server/data-loaders, the model class needs a reference to
friendService
and
userService
, which I think is messy to say the least). Instead, the loader logic here exists outside the data class/model and is simply injected via a function. However, when trying this approach, I am confronted with:
Copy code
Exception in thread "main" kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Cannot calculate JVM erasure for type: suspend () -> Bar?
  at kotlin.reflect.jvm.KTypesJvm.getJvmErasure(KTypesJvm.kt:36)
  at com.expediagroup.graphql.generator.internal.extensions.KTypeExtensionsKt.getKClass(kTypeExtensions.kt:38)
  at com.expediagroup.graphql.generator.internal.extensions.KTypeExtensionsKt.getQualifiedName(kTypeExtensions.kt:73)
  ...
Any work-around for this? If not, what other techniques are people using to do data loading without all the messiness?
Defining
isValidProperty
in the generator hooks to exclude that proeprty works, but I would have thought any
@GraphQLIgnore
annotated property would already have been excluded by default?
Making it
private
works. Also manually looking for the
GraphQLIgnore
annotation in
isValidProperty
and excluding it works, so it certainly seems like a bug.
d

Dariusz Kuc

02/15/2022, 4:21 PM
if making it
private
works then it sounds like a bug
r

rocketraman

02/15/2022, 6:47 PM
Thanks for the confirmation. I've created https://github.com/ExpediaGroup/graphql-kotlin/issues/1364.
👍 1
7 Views