aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
298 stars 58 forks source link

Ktor Feature: Exceptions throw in a DataProperty loader or accessRule are not caught #169

Open zypus opened 2 years ago

zypus commented 2 years ago

Exceptions throw in a DataProperty loader or accessRule are not caught if wrapError = true is set. Instead they bubble up to the application level.

As I'm not sure where the best place would be to do the catching I didn't open a pull request. However in my tests I had to wrap the call as far up as the DefaultSchema in order to catch the exceptions.

https://github.com/aPureBase/KGraphQL/blob/3a31874a1bea6b5d1b21e21d4cdf9a8366f79e9d/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/DefaultSchema.kt#L51

try {
    executor.suspendExecute(
        plan = requestInterpreter.createExecutionPlan(document, parsedVariables, options),
        variables = parsedVariables,
        context = context
    )
} catch (e: Exception) {
    if (configuration.wrapErrors && e !is GraphQLError) {
        throw GraphQLError(e.message ?: "", nodes = listOf(), originalError = e)
    } else throw e
}