Skip to content

Commit 76bad6a

Browse files
committed
Adapter throwException testcase
1 parent 778e4b5 commit 76bad6a

10 files changed

Lines changed: 23 additions & 127 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ plugins {
2020
kobby {
2121
kotlin {
2222
adapter {
23-
extendedApi = true // todo
23+
throwException = false
24+
}
25+
entity {
26+
errorsFunName = "myErrors"
27+
extensionsFunName = "myExtensions"
2428
}
2529
}
2630
}

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

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.
2424
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryClientMessagePing
2525
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryClientMessagePong
2626
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryClientMessageSubscribe
27-
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryMutationException
2827
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryMutationResult
29-
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryQueryException
3028
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryQueryResult
3129
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryRequest
3230
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryServerMessage
@@ -58,15 +56,12 @@ import kotlin.Unit
5856
import kotlin.collections.Map
5957
import kotlin.collections.contains
6058
import kotlin.collections.forEach
61-
import kotlin.collections.isNotEmpty
6259
import kotlin.collections.mapOf
6360
import kotlin.collections.plus
6461
import kotlin.coroutines.cancellation.CancellationException
6562
import kotlin.error
66-
import kotlin.let
6763
import kotlin.random.Random
6864
import kotlin.require
69-
import kotlin.takeIf
7065
import kotlin.to
7166
import kotlinx.coroutines.withTimeoutOrNull
7267

@@ -101,24 +96,6 @@ public open class CountryCompositeKtorAdapter(
10196

10297
val result = mapper.deserialize(content, CountryQueryResult::class)
10398

104-
result.errors?.takeIf { it.isNotEmpty() }?.let {
105-
throw CountryQueryException(
106-
"GraphQL query failed",
107-
request,
108-
it,
109-
result.extensions,
110-
result.data
111-
)
112-
}
113-
if (result.data == null) {
114-
throw CountryQueryException(
115-
"GraphQL query completes successfully but returns no data",
116-
request,
117-
result.errors,
118-
result.extensions,
119-
null
120-
)
121-
}
12299
return result
123100
}
124101

@@ -140,24 +117,6 @@ public open class CountryCompositeKtorAdapter(
140117

141118
val result = mapper.deserialize(content, CountryMutationResult::class)
142119

143-
result.errors?.takeIf { it.isNotEmpty() }?.let {
144-
throw CountryMutationException(
145-
"GraphQL mutation failed",
146-
request,
147-
it,
148-
result.extensions,
149-
result.data
150-
)
151-
}
152-
if (result.data == null) {
153-
throw CountryMutationException(
154-
"GraphQL mutation completes successfully but returns no data",
155-
request,
156-
result.errors,
157-
result.extensions,
158-
null
159-
)
160-
}
161120
return result
162121
}
163122

@@ -239,24 +198,6 @@ public open class CountryCompositeKtorAdapter(
239198
require(reply.id == subscriptionId)
240199

241200
val result = reply.payload
242-
result.errors?.takeIf { it.isNotEmpty() }?.let {
243-
throw CountrySubscriptionException(
244-
"GraphQL subscription failed",
245-
request,
246-
it,
247-
result.extensions,
248-
result.data
249-
)
250-
}
251-
if (result.data == null) {
252-
throw CountrySubscriptionException(
253-
"GraphQL subscription completes successfully but returns no data",
254-
request,
255-
result.errors,
256-
result.extensions,
257-
null
258-
)
259-
}
260201
return result
261202
}
262203
is CountryServerMessageError -> {

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
package io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.adapter.ktor
1717

1818
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.CountryAdapter
19-
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryMutationException
2019
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryMutationResult
21-
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryQueryException
2220
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryQueryResult
2321
import io.github.ermadmi78.kobby.testcases.adapter_throw_exception.kobby.kotlin.dto.graphql.CountryRequest
2422
import io.ktor.client.HttpClient
@@ -34,10 +32,7 @@ import kotlin.Suppress
3432
import kotlin.Unit
3533
import kotlin.also
3634
import kotlin.collections.Map
37-
import kotlin.collections.isNotEmpty
3835
import kotlin.collections.mapOf
39-
import kotlin.let
40-
import kotlin.takeIf
4136

4237
public open class CountrySimpleKtorAdapter(
4338
protected val client: HttpClient,
@@ -63,24 +58,6 @@ public open class CountrySimpleKtorAdapter(
6358
}
6459
.body<CountryQueryResult>()
6560

66-
result.errors?.takeIf { it.isNotEmpty() }?.let {
67-
throw CountryQueryException(
68-
"GraphQL query failed",
69-
request,
70-
it,
71-
result.extensions,
72-
result.data
73-
)
74-
}
75-
if (result.data == null) {
76-
throw CountryQueryException(
77-
"GraphQL query completes successfully but returns no data",
78-
request,
79-
result.errors,
80-
result.extensions,
81-
null
82-
)
83-
}
8461
return result
8562
}
8663

@@ -102,24 +79,6 @@ public open class CountrySimpleKtorAdapter(
10279
}
10380
.body<CountryMutationResult>()
10481

105-
result.errors?.takeIf { it.isNotEmpty() }?.let {
106-
throw CountryMutationException(
107-
"GraphQL mutation failed",
108-
request,
109-
it,
110-
result.extensions,
111-
result.data
112-
)
113-
}
114-
if (result.data == null) {
115-
throw CountryMutationException(
116-
"GraphQL mutation completes successfully but returns no data",
117-
request,
118-
result.errors,
119-
result.extensions,
120-
null
121-
)
122-
}
12382
return result
12483
}
12584
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,14 @@ public fun interface CountryReceiver<out T> {
130130

131131
public interface CountryResponse {
132132
/**
133-
* GraphQL response errors access function generated for adapters with extended API. To enable
134-
* GraphQL error propagation to the entity layer, set Kobby configuration property
135-
* `adapter.throwException` to `false`.
133+
* GraphQL response errors access function generated for adapters with extended API.
136134
*/
137-
public fun __errors(): List<CountryError>
135+
public fun myErrors(): List<CountryError>
138136

139137
/**
140138
* GraphQL response extensions access function generated for adapters with extended API.
141139
*/
142-
public fun __extensions(): Map<String, Any?>
140+
public fun myExtensions(): Map<String, Any?>
143141
}
144142

145143
public interface CountryAdapter {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ public interface Mutation : CountryResponse {
3030
public val createCountry: Country
3131

3232
/**
33-
* GraphQL response errors access function generated for adapters with extended API. To enable
34-
* GraphQL error propagation to the entity layer, set Kobby configuration property
35-
* `adapter.throwException` to `false`.
33+
* GraphQL response errors access function generated for adapters with extended API.
3634
*/
37-
override fun __errors(): List<CountryError>
35+
override fun myErrors(): List<CountryError>
3836

3937
/**
4038
* GraphQL response extensions access function generated for adapters with extended API.
4139
*/
42-
override fun __extensions(): Map<String, Any?>
40+
override fun myExtensions(): Map<String, Any?>
4341

4442
public fun __context(): CountryContext
4543

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ public interface Query : CountryResponse {
3030
public val countries: List<Country>
3131

3232
/**
33-
* GraphQL response errors access function generated for adapters with extended API. To enable
34-
* GraphQL error propagation to the entity layer, set Kobby configuration property
35-
* `adapter.throwException` to `false`.
33+
* GraphQL response errors access function generated for adapters with extended API.
3634
*/
37-
override fun __errors(): List<CountryError>
35+
override fun myErrors(): List<CountryError>
3836

3937
/**
4038
* GraphQL response extensions access function generated for adapters with extended API.
4139
*/
42-
override fun __extensions(): Map<String, Any?>
40+
override fun myExtensions(): Map<String, Any?>
4341

4442
public fun __context(): CountryContext
4543

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ public interface Subscription : CountryResponse {
3030
public val countryCreated: Country
3131

3232
/**
33-
* GraphQL response errors access function generated for adapters with extended API. To enable
34-
* GraphQL error propagation to the entity layer, set Kobby configuration property
35-
* `adapter.throwException` to `false`.
33+
* GraphQL response errors access function generated for adapters with extended API.
3634
*/
37-
override fun __errors(): List<CountryError>
35+
override fun myErrors(): List<CountryError>
3836

3937
/**
4038
* GraphQL response extensions access function generated for adapters with extended API.
4139
*/
42-
override fun __extensions(): Map<String, Any?>
40+
override fun myExtensions(): Map<String, Any?>
4341

4442
public fun __context(): CountryContext
4543

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/expected/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/kobby/kotlin/entity/impl/MutationImpl.kt.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ internal class MutationImpl(
7070
append(')')
7171
}
7272

73-
override fun __errors(): List<CountryError> = __innerErrors
73+
override fun myErrors(): List<CountryError> = __innerErrors
7474

75-
override fun __extensions(): Map<String, Any?> = __innerExtensions
75+
override fun myExtensions(): Map<String, Any?> = __innerExtensions
7676

7777
override fun __context(): CountryContext = __innerContext
7878

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/expected/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/kobby/kotlin/entity/impl/QueryImpl.kt.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ internal class QueryImpl(
7171
append(')')
7272
}
7373

74-
override fun __errors(): List<CountryError> = __innerErrors
74+
override fun myErrors(): List<CountryError> = __innerErrors
7575

76-
override fun __extensions(): Map<String, Any?> = __innerExtensions
76+
override fun myExtensions(): Map<String, Any?> = __innerExtensions
7777

7878
override fun __context(): CountryContext = __innerContext
7979

kobby-gradle-plugin/src/test/resources/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/expected/io/github/ermadmi78/kobby/testcases/adapter_throw_exception/kobby/kotlin/entity/impl/SubscriptionImpl.kt.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ internal class SubscriptionImpl(
6969
append(')')
7070
}
7171

72-
override fun __errors(): List<CountryError> = __innerErrors
72+
override fun myErrors(): List<CountryError> = __innerErrors
7373

74-
override fun __extensions(): Map<String, Any?> = __innerExtensions
74+
override fun myExtensions(): Map<String, Any?> = __innerExtensions
7575

7676
override fun __context(): CountryContext = __innerContext
7777

0 commit comments

Comments
 (0)