|
16 | 16 |
|
17 | 17 | package com.expediagroup.graphql.generator.execution
|
18 | 18 |
|
| 19 | +import com.expediagroup.graphql.generator.extensions.getOrDefault |
19 | 20 | import com.expediagroup.graphql.generator.internal.extensions.getJavaClass
|
20 | 21 | import com.expediagroup.graphql.generator.internal.extensions.getName
|
21 | 22 | import com.expediagroup.graphql.generator.internal.extensions.getTypeOfFirstArgument
|
@@ -83,11 +84,10 @@ open class FunctionDataFetcher(
|
83 | 84 | * in a value for this optional parameter. This allows for the default Kotlin values to be used if no mapping is added.
|
84 | 85 | * You can override this behaviour by providing a value for a specific [KParameter] when [mapParameterToValue] is called.
|
85 | 86 | */
|
86 |
| - protected open fun getParameters(fn: KFunction<*>, environment: DataFetchingEnvironment): Map<KParameter, Any?> { |
87 |
| - return fn.valueParameters |
| 87 | + protected open fun getParameters(fn: KFunction<*>, environment: DataFetchingEnvironment): Map<KParameter, Any?> = |
| 88 | + fn.valueParameters |
88 | 89 | .mapNotNull { mapParameterToValue(it, environment) }
|
89 | 90 | .toMap()
|
90 |
| - } |
91 | 91 |
|
92 | 92 | /**
|
93 | 93 | * Retrieves the provided parameter value in the operation input to pass to the function to execute.
|
@@ -168,26 +168,22 @@ open class FunctionDataFetcher(
|
168 | 168 | protected open fun runSuspendingFunction(
|
169 | 169 | environment: DataFetchingEnvironment,
|
170 | 170 | parameterValues: Map<KParameter, Any?>
|
171 |
| - ): CompletableFuture<Any?> { |
172 |
| - val scope = environment.graphQlContext.getOrDefault(CoroutineScope::class, CoroutineScope(EmptyCoroutineContext)) |
173 |
| - return scope.future { |
| 171 | + ): CompletableFuture<Any?> = |
| 172 | + environment.graphQlContext.getOrDefault(CoroutineScope(EmptyCoroutineContext)).future { |
174 | 173 | try {
|
175 | 174 | fn.callSuspendBy(parameterValues)
|
176 | 175 | } catch (exception: InvocationTargetException) {
|
177 | 176 | throw exception.cause ?: exception
|
178 | 177 | }
|
179 | 178 | }
|
180 |
| - } |
181 | 179 |
|
182 | 180 | /**
|
183 | 181 | * Once all parameters values are properly converted, this function will be called to run a simple blocking function.
|
184 | 182 | * If you need to override the exception handling you can override this method.
|
185 | 183 | */
|
186 |
| - protected open fun runBlockingFunction(parameterValues: Map<KParameter, Any?>): Any? { |
187 |
| - try { |
188 |
| - return fn.callBy(parameterValues) |
189 |
| - } catch (exception: InvocationTargetException) { |
190 |
| - throw exception.cause ?: exception |
191 |
| - } |
| 184 | + protected open fun runBlockingFunction(parameterValues: Map<KParameter, Any?>): Any? = try { |
| 185 | + fn.callBy(parameterValues) |
| 186 | + } catch (exception: InvocationTargetException) { |
| 187 | + throw exception.cause ?: exception |
192 | 188 | }
|
193 | 189 | }
|
0 commit comments