https://kotlinlang.org logo
Title
h

herder

01/12/2021, 3:39 PM
Hey, I'm trying to register a
FederatedTypeResolver
in a Boot applications, but how ever I do it I can't get it to kick in. I wonder if I'm misunderstanding somehing - I have a simple schema like this
@KeyDirective(FieldSet("id"))
data class MySubThing(val id: Int?, val extraThing: String)

data class MyThing(@ExtendsDirective val id: String, val subThings: List<MySubThing>) {
}
, and register this resolver class as a bean:
class MySubThingResolver: FederatedTypeResolver<MySubThing> {
    override suspend fun resolve(
      environment: DataFetchingEnvironment,
      representations: List<Map<String, Any>>
    ): List<MySubThing?> {
      return representations.stream().map {
        MySubThing(it["id"]?.toString()?.toInt(), "WOOOP")
      }.collect(Collectors.toList())
    }
But I can't get the resolver to be called however I try. What is the recommended way of registering resolvers for a schema in a Boot app? (I have set the
graphql.federation.enabled
to
true
)
d

Dariusz Kuc

01/12/2021, 3:46 PM
hi 👋 I believe in 3.x you have to explicitly create
FederatedTypeRegistry
bean that holds the mapping for those resolvers (https://github.com/ExpediaGroup/graphql-kotlin/blob/3.x.x/graphql-kotlin-spring-se[…]expediagroup/graphql/spring/FederatedSchemaAutoConfiguration.kt)
*in 4.x we simplified that to automatically wire up the federated resolvers
h

herder

01/12/2021, 3:47 PM
Yeah, I did that too, but it wasn't called anyway.
@Bean
  fun federatedTypeRegistry(federatedTypeResolvers: List<FederatedTypeResolver<*>>): FederatedTypeRegistry {
    return FederatedTypeRegistry(federatedTypeResolvers.map { "MySubThing" to it }.toMap())
  }
But the principle I'm using is what is recommended at least, right?
The schema is ok, and the resolver should kick in if everything is set up correclty?
I'll bump to 4.x and see if it works better
d

Dariusz Kuc

01/12/2021, 3:50 PM
i think your schema might be missing some directives
h

herder

01/12/2021, 3:51 PM
That might very well be true - I have moved stuff around wildly to experimient 🙂
d

Dariusz Kuc

01/12/2021, 3:51 PM
if i remember right all federated entities will need
@key
(which is missing on
MyThing
federated schema generator hook will validate it
so if it can generate the schema (and it should generate the schema without the resolvers) it should be good
h

herder

01/12/2021, 3:52 PM
Yeah, I did get an error with some variants of my annotation placements, so it seems to validate
d

Dariusz Kuc

01/12/2021, 3:53 PM
@KeyDirective(fields = FieldSet("id"))
@ExtendsDirective
class MyThing(@ExternalDirective val id: String, val subThings: List<MySubThing>)
h

herder

01/12/2021, 4:00 PM
Made no difference with 3.7.0 - i'll check the 4.x branch and get back. But thanks for the confirmation that I'm not totally off!