Hey guys - we are thinking about reorganization of...
# graphql-kotlin
m
Hey guys - we are thinking about reorganization of our spring boot project from a single gradle module to multiple modules where the most of the modules will not depend on each other - only on a "common" module which contains most of the common functionality. However we are facing a complication with our graphql classes. Some of the GraphQL entities should be split into multiple modules - data for one part of the entity will be fetched from one module and for the other part from another module. An obvious solution to this would be federation, however we do not want to run federated gateway (yet) - the whole project will be still run as a monolithic system for the time being. So I'm wondering if there is any mechanism which would allow us to source code federation for organizational purposes, but still keep the schema as a monolith. Thinking about something as following:
Copy code
module1/src/domain1/Entity.kt:
class Entity {
    fun fieldFromDomain1() = Domain1Component.fetchField()
}

module2/src/domain2/Entity.kt:
class Entity {
    fun fieldFromDomain2() = Domain2Component.fetchField()
}
The result would be the following type in the schema:
Copy code
type Entity {
    fieldFromDomain1: String!
    fieldFromDomain2: String!
}
Is something like this doable? Or is federation the only option we have?
d
Are those individual modules standalone graphql servers? Or you have single graphql app that pulls in other modules as jar dependencies?
If those are separate servers -> you will have to use gateway to combine them into a single schema. We do support Apollo Federation spec so it might be the easiest.
m
It is multiple gradle modules, but the output is a single springboot server - so these modules are dependencies for that server.
I would prefer not to go with federation for the time being.
d
graphql-kotlin
uses reflection to generate your schema -> as long as your GraphQL server module exposes stuff (can call into other modules) then it will be part of the same schema
m
That is pretty clear, but what is not clear is if one GraphQL type can be composed out of multiple Kotlin types (each type in a different module) as in the example in the original message. Pretty much the scenario is one gradle module defines the GraphQL entity and other modules might add more fields to the entity without having a direct dependency. Pretty much exactly what is federation trying to do in a multiple services scenario, but we still plan to run this in a single service as a monolith.
So in other words - I do not want to have a GraphQL module, which would be depending on all other modules. I was hoping I would be able to define parts of the schema in the individual modules (and mix them together)
d
Each one of your modules can define top level queries that are independent of each other
graphql-kotlin
does not offer functionality to merge types from different modules/jars
m
Bummer. Would it be possible to add this feature in the future? It would help us a lot to modularize our system without going full federation yet.
d
Highly doubtful. You could raise an issue asking for the feature (guessing if extension functions were supported maybe it would be enough) but unsure if it would be picked up any time soon.
Contributions are always welcome though
m
Sounds good, thanks.