You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Moves the error handler from the Ktor plugin to the schema itself. The
error handler can now be used to map any exception encountered during
execution and delegate to the default implementation.
BREAKING CHANGE: error handler is no longer supported as part of Ktor
plugin configuration
| endpoint | This specifies what route will be delivering the GraphQL endpoint. When `playground` is enabled, it will use this endpoint also. |`/graphql`|
56
-
| context | Refer to example below ||
57
-
| wrap | If you want to wrap the route into something before KGraphQL will install the GraphQL route. You can use this wrapper. See example below for a more in depth on how to use it. ||
58
-
| errorHandler | Allows interaction with exceptions thrown during GraphQL execution and optional mapping to another one — in particular mapping to `GraphQLError` for serialization in the response. ||
59
-
| schema | This is where you are defining your schema. Please refer to [KGraphQL References](../Reference/operations.md) for further documentation on this. |***required***|
| endpoint | This specifies what route will be delivering the GraphQL endpoint. When `playground` is enabled, it will use this endpoint also. |`/graphql`|
56
+
| context | Allows to add call-specific information to the GraphQL context, see example below. ||
57
+
| wrap | If you want to wrap the route into something before KGraphQL will install the GraphQL route. You can use this wrapper. See example below for a more in depth on how to use it. ||
58
+
| schema | This is where you are defining your schema. Please refer to [KGraphQL References](../Reference/operations.md) for further documentation on this. |***required***|
60
59
61
60
### Wrap
62
61
@@ -74,7 +73,7 @@ This works great alongside the [context](#context) to provide a context to the K
74
73
75
74
### Context
76
75
77
-
To get access to the context
76
+
`context` allows to add call-specific information to the GraphQL context:
78
77
79
78
=== "Example"
80
79
```kotlin
@@ -94,35 +93,6 @@ To get access to the context
94
93
}
95
94
```
96
95
97
-
### Error Handler
98
-
99
-
By default, KGraphQL will wrap non-`GraphQLError` exceptions into an `ExecutionException` (when `wrapErrors = true`)
100
-
or rethrow them to be handled by Ktor (when `wrapErrors = false`).
101
-
102
-
The `errorHandler` provides a way to **intercept and transform exceptions** before they are serialized.
103
-
It is always defined — by default it simply returns the same exception instance (`{ e -> e }`),
104
-
but you can override it to map specific exception types to `GraphQLError` or other `Throwable` instances.
105
-
106
-
=== "Example"
107
-
```kotlin
108
-
errorHandler { e ->
109
-
when (e) {
110
-
is ValidationException -> RequestError(e.message, extensions = mapOf("type" to "VALIDATION_ERROR"))
111
-
is DomainException -> RequestError(e.message, extensions = mapOf("type" to "DOMAIN_ERROR"))
112
-
is GraphQLError -> e
113
-
else -> ExecutionException(e.message ?: "Unknown execution error", cause = e)
114
-
}
115
-
}
116
-
schema {
117
-
query("hello") {
118
-
resolver { ctx: Context ->
119
-
val user = ctx.get<User>()!!
120
-
"Hello ${user.name}"
121
-
}
122
-
}
123
-
}
124
-
```
125
-
126
96
## Schema Definition Language (SDL)
127
97
128
98
The [Schema Definition Language](https://graphql.org/learn/schema/#type-language) (or Type System Definition Language) is a human-readable, language-agnostic
| documentParserCacheMaximumSize | Schema document cache maximum size |`1000`|
8
-
| objectMapper | Schema is using Jackson ObjectMapper from this property | result of `jacksonObjectMapper()` from [jackson-kotlin-module](https://github.com/FasterXML/jackson-module-kotlin)|
9
-
| acceptSingleValueAsArray | Schema accepts single argument values as singleton list |`true`|
10
-
| coroutineDispatcher | Schema is using CoroutineDispatcher from this property |[Dispatchers.Default](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/src/Dispatchers.kt)|
11
-
| genericTypeResolver | Schema is using generic type resolver from this property |[GenericTypeResolver.DEFAULT](https://github.com/stuebingerb/KGraphQL/blob/main/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/GenericTypeResolver.kt)|
12
-
| wrapErrors | Schema wraps exceptions from resolvers as GraphQLError ||
13
-
| introspection | Schema allows introspection (also affects SDL). Introspection can be disabled in production to reduce attack surface. |`true`|
| documentParserCacheMaximumSize | Schema document cache maximum size |`1000`|
8
+
| objectMapper | Schema is using Jackson ObjectMapper from this property | result of `jacksonObjectMapper()` from [jackson-kotlin-module](https://github.com/FasterXML/jackson-module-kotlin)|
9
+
| acceptSingleValueAsArray | Schema accepts single argument values as singleton list |`true`|
10
+
| coroutineDispatcher | Schema is using CoroutineDispatcher from this property |[Dispatchers.Default](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/jvm/src/Dispatchers.kt)|
11
+
| genericTypeResolver | Schema is using generic type resolver from this property |[GenericTypeResolver.DEFAULT](https://github.com/stuebingerb/KGraphQL/blob/main/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/GenericTypeResolver.kt)|
12
+
| wrapErrors | Schema wraps exceptions from resolvers as GraphQLError |`true`|
13
+
| introspection | Schema allows introspection (also affects SDL). Introspection can be disabled in production to reduce attack surface. |`true`|
14
+
| errorHandler | Allows interaction with exceptions thrown during GraphQL execution and optional mapping to another one — in particular mapping to `GraphQLError` for serialization in the response. |[ErrorHandler](https://github.com/stuebingerb/KGraphQL/blob/main/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/ErrorHandler.kt)|
Because thrown exceptions are re-thrown, `wrapErrors = false` will not produce partial responses from thrown exceptions, but resolvers can still return partial responses by calling `Context.raiseError`.
224
+
Because thrown exceptions are re-thrown, `wrapErrors = false` will not produce partial responses from thrown exceptions,
225
+
but resolvers can still return partial responses by calling `Context.raiseError`. `wrapErrors = false` will also not
226
+
invoke a custom error handler. If you want to throw exceptions with custom mapping, use `wrapErrors = true` and re-throw
227
+
mapped exceptions from the error handler.
228
+
229
+
## Error Handler
230
+
231
+
In KGraphQL, the schema can [configure a custom _error handler_](configuration.md) that is called for each exception
232
+
encountered during execution. It can be used to customize default error mapping, and to add additional extensions to
233
+
the response.
234
+
235
+
The error handler is supposed to return a subclass of `GraphQLError`, which is either a `RequestError` or an `ExecutionError`
236
+
that will be handled according to the schema. When subclassing from the default `ErrorHandler`, mapping can be delegated
237
+
to the standard implementation, completely replaced, or a mixture of both.
238
+
239
+
=== "Example"
240
+
```kotlin
241
+
val customErrorHandler = object : ErrorHandler() {
Copy file name to clipboardExpand all lines: kgraphql-ktor-stitched/api/kgraphql-ktor-stitched.api
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -56,8 +56,8 @@ public final class com/apurebase/kgraphql/stitched/StitchedKGraphQL {
56
56
}
57
57
58
58
public final class com/apurebase/kgraphql/stitched/schema/configuration/StitchedSchemaConfiguration : com/apurebase/kgraphql/configuration/SchemaConfiguration {
59
-
public fun <init> (ZJLcom/fasterxml/jackson/databind/ObjectMapper;ZLkotlinx/coroutines/CoroutineDispatcher;ZZLcom/apurebase/kgraphql/schema/execution/GenericTypeResolver;Lcom/apurebase/kgraphql/schema/execution/ArgumentTransformer;Lcom/apurebase/kgraphql/stitched/schema/execution/RemoteRequestExecutor;Ljava/lang/String;)V
60
-
public synthetic fun <init> (ZJLcom/fasterxml/jackson/databind/ObjectMapper;ZLkotlinx/coroutines/CoroutineDispatcher;ZZLcom/apurebase/kgraphql/schema/execution/GenericTypeResolver;Lcom/apurebase/kgraphql/schema/execution/ArgumentTransformer;Lcom/apurebase/kgraphql/stitched/schema/execution/RemoteRequestExecutor;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
59
+
public fun <init> (ZJLcom/fasterxml/jackson/databind/ObjectMapper;ZLkotlinx/coroutines/CoroutineDispatcher;ZZLcom/apurebase/kgraphql/schema/execution/GenericTypeResolver;Lcom/apurebase/kgraphql/schema/execution/ArgumentTransformer;Lcom/apurebase/kgraphql/schema/execution/ErrorHandler;Lcom/apurebase/kgraphql/stitched/schema/execution/RemoteRequestExecutor;Ljava/lang/String;)V
60
+
public synthetic fun <init> (ZJLcom/fasterxml/jackson/databind/ObjectMapper;ZLkotlinx/coroutines/CoroutineDispatcher;ZZLcom/apurebase/kgraphql/schema/execution/GenericTypeResolver;Lcom/apurebase/kgraphql/schema/execution/ArgumentTransformer;Lcom/apurebase/kgraphql/schema/execution/ErrorHandler;Lcom/apurebase/kgraphql/stitched/schema/execution/RemoteRequestExecutor;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
61
61
public final fun getLocalUrl ()Ljava/lang/String;
62
62
public final fun getRemoteExecutor ()Lcom/apurebase/kgraphql/stitched/schema/execution/RemoteRequestExecutor;
Copy file name to clipboardExpand all lines: kgraphql-ktor-stitched/src/main/kotlin/com/apurebase/kgraphql/stitched/schema/configuration/StitchedSchemaConfiguration.kt
Copy file name to clipboardExpand all lines: kgraphql-ktor-stitched/src/main/kotlin/com/apurebase/kgraphql/stitched/schema/dsl/StitchedSchemaConfigurationDSL.kt
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ open class StitchedSchemaConfigurationDSL : SchemaConfigurationDSL() {
0 commit comments