Jackon Annotation Configurations and Simpler Query Generation #8
Replies: 4 comments 7 replies
-
Hi, @lewisenator I'm glad you liked the DSL generated by the Kobby Plugin. And thank you for the suggested ideas!
|
Beta Was this translation helpful? Give feedback.
-
@lewisenator public interface CinemaContext {
public suspend fun query(__projection: QueryProjection.() -> Unit): Query
public suspend fun mutation(__projection: MutationProjection.() -> Unit): Mutation
public fun subscription(__projection: SubscriptionProjection.() -> Unit):
CinemaSubscriber<Subscription>
} To provide an ability to instantiate this interface Kobby generates builder function: public fun cinemaContextOf(adapter: CinemaAdapter): CinemaContext = CinemaContextImpl(adapter) And also every generated entity implements this interface, to provide an ability to use Kotlin extension functions for smart customization of the generated DSL. The interface implementation looks like following: private class CinemaContextImpl(
private val adapter: CinemaAdapter
) : CinemaContext {
/**
* https://youtrack.jetbrains.com/issue/KTIJ-844
*/
@Suppress("BlockingMethodInNonBlockingContext")
public override suspend fun query(__projection: QueryProjection.() -> Unit): Query {
val projectionRef = QueryProjectionImpl().apply(__projection)
val header = StringBuilder()
val body = StringBuilder(64)
val arguments: MutableMap<String, Any> = mutableMapOf()
projectionRef.___innerBuild(setOf(), header, body, arguments)
val query = buildString(header.length + body.length + 7) {
append("query")
if (header.isNotEmpty()) {
append('(').append(header).append(')')
}
append(body)
}
val queryDto: QueryDto = adapter.executeQuery(query, arguments)
return queryDto.buildEntity(this, projectionRef)
}
/**
* https://youtrack.jetbrains.com/issue/KTIJ-844
*/
@Suppress("BlockingMethodInNonBlockingContext")
public override suspend fun mutation(__projection: MutationProjection.() -> Unit): Mutation {
val projectionRef = MutationProjectionImpl().apply(__projection)
val header = StringBuilder()
val body = StringBuilder(64)
val arguments: MutableMap<String, Any> = mutableMapOf()
projectionRef.___innerBuild(setOf(), header, body, arguments)
val mutation = buildString(header.length + body.length + 10) {
append("mutation")
if (header.isNotEmpty()) {
append('(').append(header).append(')')
}
append(body)
}
val mutationDto: MutationDto = adapter.executeMutation(mutation, arguments)
return mutationDto.buildEntity(this, projectionRef)
}
public override fun subscription(__projection: SubscriptionProjection.() -> Unit):
CinemaSubscriber<Subscription> {
val projectionRef = SubscriptionProjectionImpl().apply(__projection)
val header = StringBuilder()
val body = StringBuilder(64)
val arguments: MutableMap<String, Any> = mutableMapOf()
projectionRef.___innerBuild(setOf(), header, body, arguments)
val subscription = buildString(header.length + body.length + 14) {
append("subscription")
if (header.isNotEmpty()) {
append('(').append(header).append(')')
}
append(body)
}
return CinemaSubscriber<Subscription> {
adapter.executeSubscription(subscription, arguments) {
val receiver = CinemaReceiver<Subscription> {
val subscriptionDto: SubscriptionDto = receive()
subscriptionDto.buildEntity(this@CinemaContextImpl, projectionRef)
}
it.invoke(receiver)
}
}
}
} Could you please describe your suggestions in more detail? |
Beta Was this translation helpful? Give feedback.
-
@lewisenator, I have created a builder issue. Could you please implement this task if you do not mind the API design I proposed? |
Beta Was this translation helpful? Give feedback.
-
@lewisenator I have posted example with your builders in the tutorial. Looks great! :) |
Beta Was this translation helpful? Give feedback.
-
First off, thanks so much for making this excellent library available to the community. This is easily the best Kotlin GraphQL client code generation library. I've found it very configurable and easy to use.
I have a few small ideas that would make this library easier to adopt for my organization:
Maven build plugin options to configure the Jackson annotations on the generated DTO classes. Specifically, I want to be able to configure the
@JsonTypeInfo
annotation'suse
,include
, andproperty
fields, as well as the@JsonInclude
annotation'svalue
field.Separate the interface for query/mutation generation from execution. I would like to leverage the generated context impl code to generate queries and mutations without executing the actual query/mutation. As is, the generated context impl requires you to implement an adapter and execute the queries/mutations.
Would you allow contributions from the community? These small changes are something I would feel comfortable submitting a pull request for. Perhaps a
contributing.md
with instructions for the community. setting-guidelines-for-repository-contributorsBeta Was this translation helpful? Give feedback.
All reactions