Open mr-nothing opened 9 months ago
Hi @mr-nothing! Thanks for providing context on this, and we definitely understand that this would be valuable for Kotlin. We will add this to our backlog for future enhancements. However, due to other priorities, we most likely will not be able to get to it immediately. If this is a time-sensitive requirement for your project, we always welcome contributions from our community.
If we would have interfaces for data classes, weren't we then able to automatically extend them when the extend
keyword is used?
Example:
In my core library I have a type Acommodation
with one field id
.
In one of my subgraphs I use extend Accommodation
to add a field name: String
.
On Kotlin side there could be then an Interface for both Accommodation
types. The one in the subgraph can then extend the one from the core library (or whereever the type was initally declared)
Hey, @bjoernmayer!
Yeah, this is kind of a problem, but that Accomodation
interface could have as-is name, Accomodatiton
but that helper Accomodation
interface could have a name with some suffix attached Helper
, Interface
, Util
, Base
, etc.
I think there will be more corner cases to take into accountt but this can be easily solved like this imo
When I'm trying to
generateInterfaces
forkotlin
language with use ofgenerateJava
task, they are not generated.I saw ticket here that touch on this topic and it was stated that it is probably a feature of not a first priority.
I could probably add some context to highlight that this is pretty vital thing to have in kotlin based projects.
Let's take a look at the following setup:
Now I'm trying to organize my dataloaders and data fetchers as optimal as possible. In kotlin projects I have the following options and none of them looks optimal to me:
Option 1: manually create interface for your types (not optimal from contract/schema perspective)
ITeam
interface:Then data fetcher will be something like this:
I case of relational database on
val parentTeamId = dfe.getSource<Team>()?.parentTeam?.id
line I have access to parent team id since it is...toOne
relation and I don't need additional db queries to find it out.Also in data loader I do this:
Looks good so far but the query for such a schema is not that concise as it could be:
From client perspective it looks weird and doesn't feel right when performance backend stuff affects contract with external clients (another backend services, frontend, etc)
Team
type we need to remember to pass local context in all data/entity fetchers. If we don't do that we got an error. Moreover if we get an additional field in schema liketeamLead
we need to populate it everywhere we populate local context. If project's graphql contract is not 100% covered with tests it could lead to errors on test/prod environments and with graphql request variety it is pretty difficult to keep test coverage on these high levels.parentTeam
with use of separate join db query and separate data loader logic but it is obviously not that fast and produces extra load on microservice itself and database.Could you please share if there any plans to make
generateInterfaces
available for kotlin?Thank you very much!