From 3cf86d998eed8e270a3011ad08082a13c97cd085 Mon Sep 17 00:00:00 2001 From: Samuel Vazquez Date: Thu, 11 Jul 2024 09:46:33 -0700 Subject: [PATCH] feat(batching): v7 remove execution if a given operation completes with an exception (#2007) ### :pencil: Description https://github.com/ExpediaGroup/graphql-kotlin/pull/2006 Co-authored-by: Samuel Vazquez --- .../level/state/ExecutionLevelDispatchedState.kt | 7 +++---- .../syncexhaustion/state/SyncExecutionExhaustedState.kt | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt index db93a0b514..aa7b3ef807 100644 --- a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt +++ b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/level/state/ExecutionLevelDispatchedState.kt @@ -48,6 +48,7 @@ class ExecutionLevelDispatchedState( * for example: * parsing, validation, execution errors * persisted query errors + * an exception during execution was thrown */ private fun removeExecution(executionId: ExecutionId) { if (executions.containsKey(executionId)) { @@ -70,10 +71,8 @@ class ExecutionLevelDispatchedState( } return object : SimpleInstrumentationContext() { override fun onCompleted(result: ExecutionResult?, t: Throwable?) { - result?.let { - if (result.errors.size > 0) { - removeExecution(parameters.executionInput.executionId) - } + if ((result != null && result.errors.size > 0) || t != null) { + removeExecution(parameters.executionInput.executionId) } } } diff --git a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt index 14d1237585..c8cb8eb599 100644 --- a/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt +++ b/executions/graphql-kotlin-dataloader-instrumentation/src/main/kotlin/com/expediagroup/graphql/dataloader/instrumentation/syncexhaustion/state/SyncExecutionExhaustedState.kt @@ -51,6 +51,7 @@ class SyncExecutionExhaustedState( * for example: * - parsing, validation errors * - persisted query errors + * - an exception during execution was thrown */ private fun removeExecution(executionId: ExecutionId) { if (executions.containsKey(executionId)) { @@ -73,10 +74,8 @@ class SyncExecutionExhaustedState( } return object : SimpleInstrumentationContext() { override fun onCompleted(result: ExecutionResult?, t: Throwable?) { - result?.let { - if (result.errors.size > 0) { - removeExecution(parameters.executionInput.executionId) - } + if ((result != null && result.errors.size > 0) || t != null) { + removeExecution(parameters.executionInput.executionId) } } }