stuebingerb / KGraphQL

Pure Kotlin GraphQL implementation
MIT License
4 stars 1 forks source link

Proposal: Make `resolver` DSLs Explicitly Return Values #67

Open Taskeren opened 2 weeks ago

Taskeren commented 2 weeks ago

In current resolver DSLs, It is not easy to tell what is returned in a complicated logic. I think there should be something like emit in Flow to return values, so that we can tell which value is returned at a glance.

resolver { ->
  emit("My Value")
}

With this, it is also better to inject context without declaring it.

resolver { -> // this: TheResolverContext
  emit("The context: {this.context.get<WhateverContext>()}")
}

Also, return@resolver "My Value" looks ugly, but it works.

stuebingerb commented 2 weeks ago

Thanks for the idea, although I'm not sure if I fully agree - at least enough to introduce a breaking change to all resolvers, even in a pre-1.0.0 version.

I personally haven't had such issues so far but I usually keep my resolvers short and delegate complex work to dedicated services. I do like making the context more easily available but there might be other (non-breaking) options as well.

I'll leave this open to foster a discussion and let others join if interested.