Skip to content

Commit 4f7d236

Browse files
feat: pass graphQLContext as fallback if deprecated context is null (#1652)
1 parent 46a7c77 commit 4f7d236

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

servers/graphql-kotlin-server/src/main/kotlin/com/expediagroup/graphql/server/extensions/dataFetchingEnvironmentExtensions.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,20 @@ import java.util.concurrent.CompletableFuture
2929
* Helper method to get a value from a registered DataLoader.
3030
* The provided key should be the cache key object used to save the value for that particular data loader.
3131
*/
32-
fun <K, V> DataFetchingEnvironment.getValueFromDataLoader(dataLoaderName: String, key: K): CompletableFuture<V> {
33-
val loader = getDataLoader<K, V>(dataLoaderName) ?: throw MissingDataLoaderException(dataLoaderName)
34-
return loader.load(key, this.getContext())
35-
}
32+
fun <K, V> DataFetchingEnvironment.getValueFromDataLoader(dataLoaderName: String, key: K): CompletableFuture<V> =
33+
getDataLoader<K, V>(dataLoaderName)?.load(
34+
key,
35+
this.getContext() ?: this.graphQlContext
36+
) ?: throw MissingDataLoaderException(dataLoaderName)
3637

3738
/**
3839
* Helper method to get values from a registered DataLoader.
3940
*/
40-
fun <K, V> DataFetchingEnvironment.getValuesFromDataLoader(dataLoaderName: String, keys: List<K>): CompletableFuture<List<V>> {
41-
val loader = getDataLoader<K, V>(dataLoaderName) ?: throw MissingDataLoaderException(dataLoaderName)
42-
return loader.loadMany(keys, listOf(this.getContext()))
43-
}
41+
fun <K, V> DataFetchingEnvironment.getValuesFromDataLoader(dataLoaderName: String, keys: List<K>): CompletableFuture<List<V>> =
42+
getDataLoader<K, V>(dataLoaderName)?.loadMany(
43+
keys,
44+
listOf(this.getContext() ?: this.graphQlContext)
45+
) ?: throw MissingDataLoaderException(dataLoaderName)
4446

4547
/**
4648
* Returns a value from the graphQLContext by KClass key

0 commit comments

Comments
 (0)