Hi all, we are exploring using graphql-kotlin for ...
# graphql-kotlin
j
Hi all, we are exploring using graphql-kotlin for a new set of services. We want to start with a monolith (single deployable artifact) but divide it internally into subdomains (like bounded contexts). Each subdomain (or bounded context) will have a graphql layer with the types exposed in the schema. We wanted to use type extensions to link the types across subdomains, but I believe it is not supported. Any thoughts on a way to implement something like type extensions? Down the road, we will break down the subdomains into microservices, and we will use federation, but we want to start with a componentized monolith.
s
If you are starting with a monolith there is no need to do extensions. You can just have all the types declared. The Apollo Gateway also supports the
extends
keyword with the
@extends
directive: https://github.com/ExpediaGroup/graphql-kotlin/blob/fac1e41914f6a8a0a494082752a4e3[…]xpediagroup/graphql/examples/federation/extend/schema/Widget.kt
j
I want the packages to be boundaries between subdomains. I'm trying to avoid a horizontal package with all types. To use the @extends directive, I'll have to use federation from the beginning, right?
@Shane Myrick Is there any reason to not support the type extension in kotlin-graphql? E.g., it seems like Java supports it (see Modularising the Schema SDL)
s
Answered in another slack community, cross posting here: Currently there isn't a way in the library to use the 
extend
 key word. If we wanted to add support it would have to look like that example you linked to for the library 
graphql-java-annotations
 since we can't have a type with the same name. I recommend that a feature request be added and PRs are always welcome fore review. The quick alternative is that you can manually extend the type with extra fields using the hooks but obviously that is not as simple
j
Thanks, @Shane Myrick. Do you have any examples to explore the hooks option?
s
You would have to use the hook
willAddGraphQLTypeToSchema
where you can look at the KClass and the current generated type and modify it to add another field based off of some other class that you can do a find using the class scanner that has some annotation and that
KClass
as the argument https://github.com/ExpediaGroup/graphql-kotlin/blob/fac1e41914f6a8a0a494082752a4e3[…]om/expediagroup/graphql/generator/hooks/SchemaGeneratorHooks.kt