Skip to content

Commit 7adc0ce

Browse files
committed
feat: wrap fetchedValue in a completableFuture
1 parent 52474bb commit 7adc0ce

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/execution/FlowSubscriptionExecutionStrategy.kt

+9-13
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,22 @@ class FlowSubscriptionExecutionStrategy(dfe: DataFetcherExceptionHandler) : Exec
111111
): CompletableFuture<Flow<*>?> {
112112
val newParameters = firstFieldOfSubscriptionSelection(parameters)
113113

114-
val fieldFetched = fetchField(executionContext, newParameters)
115-
return if (fieldFetched is CompletableFuture<*>) {
116-
val promiseFieldFetched = fieldFetched as CompletableFuture<FetchedValue>
117-
promiseFieldFetched.thenApply { fetchedValue ->
118-
when (val publisherOrFlow: Any? = fetchedValue.fetchedValue) {
119-
is Publisher<*> -> publisherOrFlow.asFlow()
120-
// below explicit cast is required due to the type erasure and Kotlin declaration-site variance vs Java use-site variance
121-
is Flow<*> -> publisherOrFlow
122-
else -> null
123-
}
114+
115+
val fieldFetched: CompletableFuture<FetchedValue> = fetchField(executionContext, newParameters).let { fetchedValue ->
116+
if (fetchedValue is CompletableFuture<*>) {
117+
fetchedValue as CompletableFuture<FetchedValue>
118+
} else {
119+
CompletableFuture.completedFuture(fetchedValue as FetchedValue)
124120
}
125-
} else {
126-
val fetchedValue = fieldFetched as FetchedValue
121+
}
122+
return fieldFetched.thenApply { fetchedValue ->
127123
val flow = when (val publisherOrFlow: Any? = fetchedValue.fetchedValue) {
128124
is Publisher<*> -> publisherOrFlow.asFlow()
129125
// below explicit cast is required due to the type erasure and Kotlin declaration-site variance vs Java use-site variance
130126
is Flow<*> -> publisherOrFlow
131127
else -> null
132128
}
133-
CompletableFuture.completedFuture(flow)
129+
flow
134130
}
135131
}
136132

0 commit comments

Comments
 (0)