Skip to content

Commit 9b68bfd

Browse files
committed
Adapter extendedApi testcase
1 parent 5170cbe commit 9b68bfd

10 files changed

Lines changed: 203 additions & 73 deletions

File tree

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/build.gradle.kts.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121
kobby {
2222
kotlin {
2323
adapter {
24-
// todo
24+
extendedApi = true
2525
}
2626
}
2727
}

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/expected/io/github/ermadmi78/kobby/testcases/adapter_extended_api/kobby/kotlin/adapter/ktor/CountryCompositeKtorAdapter.kt.txt

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ package io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.ad
1818
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryAdapter
1919
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryReceiver
2020
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.countryJson
21-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.MutationDto
22-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.QueryDto
23-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.SubscriptionDto
2421
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryClientMessage
2522
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryClientMessageComplete
2623
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryClientMessageConnectionInit
@@ -40,6 +37,7 @@ import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto
4037
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryServerMessagePing
4138
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryServerMessagePong
4239
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountrySubscriptionException
40+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountrySubscriptionResult
4341
import io.ktor.client.HttpClient
4442
import io.ktor.client.plugins.websocket.webSocket
4543
import io.ktor.client.request.post
@@ -89,7 +87,7 @@ public open class CountryCompositeKtorAdapter(
8987
protected val idGenerator: () -> String = { Random.nextLong().toString() },
9088
protected val listener: (CountryRequest) -> Unit = {},
9189
) : CountryAdapter {
92-
override suspend fun executeQuery(query: String, variables: JsonObject): QueryDto {
90+
override suspend fun executeQuery(query: String, variables: JsonObject): CountryQueryResult {
9391
val request = CountryRequest(query, variables)
9492
listener(request)
9593

@@ -115,16 +113,20 @@ public open class CountryCompositeKtorAdapter(
115113
result.data
116114
)
117115
}
118-
return result.data ?: throw CountryQueryException(
119-
"GraphQL query completes successfully but returns no data",
120-
request,
121-
result.errors,
122-
result.extensions,
123-
null
124-
)
116+
if (result.data == null) {
117+
throw CountryQueryException(
118+
"GraphQL query completes successfully but returns no data",
119+
request,
120+
result.errors,
121+
result.extensions,
122+
null
123+
)
124+
}
125+
return result
125126
}
126127

127-
override suspend fun executeMutation(query: String, variables: JsonObject): MutationDto {
128+
override suspend fun executeMutation(query: String, variables: JsonObject):
129+
CountryMutationResult {
128130
val request = CountryRequest(query, variables)
129131
listener(request)
130132

@@ -150,19 +152,22 @@ public open class CountryCompositeKtorAdapter(
150152
result.data
151153
)
152154
}
153-
return result.data ?: throw CountryMutationException(
154-
"GraphQL mutation completes successfully but returns no data",
155-
request,
156-
result.errors,
157-
result.extensions,
158-
null
159-
)
155+
if (result.data == null) {
156+
throw CountryMutationException(
157+
"GraphQL mutation completes successfully but returns no data",
158+
request,
159+
result.errors,
160+
result.extensions,
161+
null
162+
)
163+
}
164+
return result
160165
}
161166

162167
override suspend fun executeSubscription(
163168
query: String,
164169
variables: JsonObject,
165-
block: suspend CountryReceiver<SubscriptionDto>.() -> Unit,
170+
block: suspend CountryReceiver<CountrySubscriptionResult>.() -> Unit,
166171
) {
167172
val httpHeaders: Map<String, String> = requestHeaders()
168173
val payload: JsonObject? = subscriptionPayload()
@@ -195,7 +200,7 @@ public open class CountryCompositeKtorAdapter(
195200
protected open suspend fun WebSocketSession.executeSubscriptionImpl(
196201
initPayload: JsonObject?,
197202
request: CountryRequest,
198-
block: suspend CountryReceiver<SubscriptionDto>.() -> Unit,
203+
block: suspend CountryReceiver<CountrySubscriptionResult>.() -> Unit,
199204
) {
200205
val socket = this
201206
sendMessage(socket, CountryClientMessageConnectionInit(initPayload))
@@ -221,8 +226,8 @@ public open class CountryCompositeKtorAdapter(
221226
sendMessage(socket, CountryClientMessageSubscribe(subscriptionId, request))
222227

223228
try {
224-
block.invoke(object : CountryReceiver<SubscriptionDto> {
225-
override suspend fun receive(): SubscriptionDto {
229+
block.invoke(object : CountryReceiver<CountrySubscriptionResult> {
230+
override suspend fun receive(): CountrySubscriptionResult {
226231
while (true) {
227232
var reply = receiveMessage(socket)
228233
if (reply == null) {
@@ -244,13 +249,16 @@ public open class CountryCompositeKtorAdapter(
244249
result.data
245250
)
246251
}
247-
return result.data ?: throw CountrySubscriptionException(
248-
"GraphQL subscription completes successfully but returns no data",
249-
request,
250-
result.errors,
251-
result.extensions,
252-
null
253-
)
252+
if (result.data == null) {
253+
throw CountrySubscriptionException(
254+
"GraphQL subscription completes successfully but returns no data",
255+
request,
256+
result.errors,
257+
result.extensions,
258+
null
259+
)
260+
}
261+
return result
254262
}
255263
is CountryServerMessageError -> {
256264
require(reply.id == subscriptionId)

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/expected/io/github/ermadmi78/kobby/testcases/adapter_extended_api/kobby/kotlin/adapter/ktor/CountrySimpleKtorAdapter.kt.txt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
package io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.adapter.ktor
1717

1818
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryAdapter
19-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.MutationDto
20-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.QueryDto
2119
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryMutationException
2220
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryMutationResult
2321
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryQueryException
@@ -47,7 +45,7 @@ public open class CountrySimpleKtorAdapter(
4745
protected val headers: suspend () -> Map<String, String> = { mapOf<String, String>() },
4846
protected val listener: (CountryRequest) -> Unit = {},
4947
) : CountryAdapter {
50-
override suspend fun executeQuery(query: String, variables: JsonObject): QueryDto {
48+
override suspend fun executeQuery(query: String, variables: JsonObject): CountryQueryResult {
5149
val request = CountryRequest(query, variables)
5250
listener(request)
5351

@@ -73,16 +71,20 @@ public open class CountrySimpleKtorAdapter(
7371
result.data
7472
)
7573
}
76-
return result.data ?: throw CountryQueryException(
77-
"GraphQL query completes successfully but returns no data",
78-
request,
79-
result.errors,
80-
result.extensions,
81-
null
82-
)
74+
if (result.data == null) {
75+
throw CountryQueryException(
76+
"GraphQL query completes successfully but returns no data",
77+
request,
78+
result.errors,
79+
result.extensions,
80+
null
81+
)
82+
}
83+
return result
8384
}
8485

85-
override suspend fun executeMutation(query: String, variables: JsonObject): MutationDto {
86+
override suspend fun executeMutation(query: String, variables: JsonObject):
87+
CountryMutationResult {
8688
val request = CountryRequest(query, variables)
8789
listener(request)
8890

@@ -108,12 +110,15 @@ public open class CountrySimpleKtorAdapter(
108110
result.data
109111
)
110112
}
111-
return result.data ?: throw CountryMutationException(
112-
"GraphQL mutation completes successfully but returns no data",
113-
request,
114-
result.errors,
115-
result.extensions,
116-
null
117-
)
113+
if (result.data == null) {
114+
throw CountryMutationException(
115+
"GraphQL mutation completes successfully but returns no data",
116+
request,
117+
result.errors,
118+
result.extensions,
119+
null
120+
)
121+
}
122+
return result
118123
}
119124
}

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/expected/io/github/ermadmi78/kobby/testcases/adapter_extended_api/kobby/kotlin/country.kt.txt

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
package io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin
1717

18-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.MutationDto
19-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.QueryDto
20-
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.SubscriptionDto
18+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryError
19+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryMutationResult
20+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryQueryResult
21+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountrySubscriptionResult
2122
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.entity.Mutation
2223
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.entity.MutationProjection
2324
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.entity.Query
@@ -35,7 +36,9 @@ import kotlin.String
3536
import kotlin.Suppress
3637
import kotlin.Unit
3738
import kotlin.apply
39+
import kotlin.collections.List
3840
import kotlin.collections.MutableMap
41+
import kotlin.collections.emptyMap
3942
import kotlin.collections.mutableMapOf
4043
import kotlin.collections.setOf
4144
import kotlin.text.StringBuilder
@@ -138,17 +141,31 @@ public fun interface CountryReceiver<out T> {
138141
public suspend fun receive(): T
139142
}
140143

144+
public interface CountryResponse {
145+
/**
146+
* GraphQL response errors access function generated for adapters with extended API. To enable
147+
* GraphQL error propagation to the entity layer, set Kobby configuration property
148+
* `adapter.throwException` to `false`.
149+
*/
150+
public fun __errors(): List<CountryError>
151+
152+
/**
153+
* GraphQL response extensions access function generated for adapters with extended API.
154+
*/
155+
public fun __extensions(): JsonObject
156+
}
157+
141158
public interface CountryAdapter {
142-
public suspend fun executeQuery(query: String, variables: JsonObject): QueryDto =
159+
public suspend fun executeQuery(query: String, variables: JsonObject): CountryQueryResult =
143160
throw NotImplementedError("Adapter function executeQuery is not implemented")
144161

145-
public suspend fun executeMutation(query: String, variables: JsonObject): MutationDto =
162+
public suspend fun executeMutation(query: String, variables: JsonObject): CountryMutationResult =
146163
throw NotImplementedError("Adapter function executeMutation is not implemented")
147164

148165
public suspend fun executeSubscription(
149166
query: String,
150167
variables: JsonObject,
151-
block: suspend CountryReceiver<SubscriptionDto>.() -> Unit,
168+
block: suspend CountryReceiver<CountrySubscriptionResult>.() -> Unit,
152169
): Unit = throw NotImplementedError("Adapter function executeSubscription is not implemented")
153170
}
154171

@@ -175,8 +192,8 @@ private class CountryContextImpl(
175192
append(body)
176193
}
177194

178-
val queryDto: QueryDto = adapter.executeQuery(query, JsonObject(arguments))
179-
return queryDto.buildEntity(this, projectionRef)
195+
val queryResult: CountryQueryResult = adapter.executeQuery(query, JsonObject(arguments))
196+
return queryResult.buildEntity(this, projectionRef)
180197
}
181198

182199
/**
@@ -199,8 +216,9 @@ private class CountryContextImpl(
199216
append(body)
200217
}
201218

202-
val mutationDto: MutationDto = adapter.executeMutation(mutation, JsonObject(arguments))
203-
return mutationDto.buildEntity(this, projectionRef)
219+
val mutationResult: CountryMutationResult = adapter.executeMutation(mutation,
220+
JsonObject(arguments))
221+
return mutationResult.buildEntity(this, projectionRef)
204222
}
205223

206224
override fun subscription(__projection: SubscriptionProjection.() -> Unit):
@@ -224,14 +242,16 @@ private class CountryContextImpl(
224242
adapter.executeSubscription(subscription, JsonObject(arguments)) {
225243
it.invoke(object : CountryReceiver<Subscription> {
226244
override suspend fun receive(): Subscription {
227-
val subscriptionDto: SubscriptionDto = this@executeSubscription.receive()
228-
return subscriptionDto.buildEntity(this@CountryContextImpl, projectionRef)
245+
val subscriptionResult: CountrySubscriptionResult = this@executeSubscription.receive()
246+
return subscriptionResult.buildEntity(this@CountryContextImpl, projectionRef)
229247
}
230248
})
231249
}
232250
}
233251
}
234252
}
235253

254+
public val countryEmptyJsonObject: JsonObject = JsonObject(emptyMap())
255+
236256
@DslMarker
237257
public annotation class CountryDSL

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/expected/io/github/ermadmi78/kobby/testcases/adapter_extended_api/kobby/kotlin/entity/Mutation.kt.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,29 @@ package io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.en
1717

1818
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryContext
1919
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryDSL
20+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryResponse
21+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryError
2022
import kotlin.String
2123
import kotlin.Suppress
2224
import kotlin.Unit
25+
import kotlin.collections.List
26+
import kotlinx.serialization.json.JsonObject
2327

24-
public interface Mutation {
28+
public interface Mutation : CountryResponse {
2529
public val createCountry: Country
2630

31+
/**
32+
* GraphQL response errors access function generated for adapters with extended API. To enable
33+
* GraphQL error propagation to the entity layer, set Kobby configuration property
34+
* `adapter.throwException` to `false`.
35+
*/
36+
override fun __errors(): List<CountryError>
37+
38+
/**
39+
* GraphQL response extensions access function generated for adapters with extended API.
40+
*/
41+
override fun __extensions(): JsonObject
42+
2743
public fun __context(): CountryContext
2844

2945
public fun MutationProjection.__withCurrentProjection()

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_extended_api/expected/io/github/ermadmi78/kobby/testcases/adapter_extended_api/kobby/kotlin/entity/Query.kt.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ package io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.en
1717

1818
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryContext
1919
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryDSL
20+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.CountryResponse
21+
import io.github.ermadmi78.kobby.testcases.adapter_extended_api.kobby.kotlin.dto.graphql.CountryError
2022
import kotlin.Suppress
2123
import kotlin.Unit
2224
import kotlin.collections.List
25+
import kotlinx.serialization.json.JsonObject
2326

24-
public interface Query {
27+
public interface Query : CountryResponse {
2528
public val countries: List<Country>
2629

30+
/**
31+
* GraphQL response errors access function generated for adapters with extended API. To enable
32+
* GraphQL error propagation to the entity layer, set Kobby configuration property
33+
* `adapter.throwException` to `false`.
34+
*/
35+
override fun __errors(): List<CountryError>
36+
37+
/**
38+
* GraphQL response extensions access function generated for adapters with extended API.
39+
*/
40+
override fun __extensions(): JsonObject
41+
2742
public fun __context(): CountryContext
2843

2944
public fun QueryProjection.__withCurrentProjection()

0 commit comments

Comments
 (0)