bjartek
01/09/2020, 6:05 PMDariusz Kuc
01/09/2020, 6:20 PMDariusz Kuc
01/09/2020, 6:20 PMDariusz Kuc
01/09/2020, 6:21 PMDariusz Kuc
01/09/2020, 6:21 PMDariusz Kuc
01/09/2020, 6:22 PMDariusz Kuc
01/09/2020, 6:23 PMDataFetcherResult
(see https://www.graphql-java.com/documentation/v13/execution/)bjartek
01/09/2020, 6:31 PMbjartek
01/09/2020, 7:38 PMDariusz Kuc
01/09/2020, 7:42 PMCompletableFuture
is a wrapper around the actual response I'd assume something like
fun whatever(): CompletableFuture<Whatever?>
should workDariusz Kuc
01/09/2020, 7:44 PMbjartek
01/09/2020, 7:45 PMfun company(dfe: DataFetchingEnvironment): CompletableFuture<DataFetcherResult<Company>?> = dfe.load<Int, Company>(companyId)
Dariusz Kuc
01/09/2020, 7:45 PMbjartek
01/09/2020, 7:45 PMDariusz Kuc
01/09/2020, 7:45 PMfun company(dfe: DataFetchingEnvironment): CompletableFuture<DataFetcherResult<Company?>> = dfe.load<Int, Company>(companyId)
bjartek
01/09/2020, 7:45 PMDariusz Kuc
01/09/2020, 7:45 PMDariusz Kuc
01/09/2020, 7:46 PMbjartek
01/09/2020, 7:46 PMbjartek
01/09/2020, 7:47 PMbjartek
01/09/2020, 7:48 PMbjartek
01/09/2020, 7:48 PM{
"data": {
"employees": [
{
"name": "Mike",
"company": {
"id": 1,
"name": "FirstCompany"
}
},
{
"name": "John",
"company": {
"id": 1,
"name": "FirstCompany"
}
},
{
"name": "Steve",
"company": null
}
]
},
"errors": [
{
"locations": [],
"path": null,
"errorType": "DataFetchingException",
"extensions": {},
"message": "Exception while fetching data () : java.lang.RuntimeException: Failed"
}
]
}
bjartek
01/09/2020, 7:49 PMbjartek
01/09/2020, 7:49 PMbjartek
01/09/2020, 7:50 PMinline fun <Key, reified Value> DataFetchingEnvironment.load(key:Key): CompletableFuture<DataFetcherResult<Value?>> {
val loaderName = "${Value::class.java.simpleName}DataLoader"
return this.getDataLoader<Key, Value>(loaderName).load(key).thenApply {
DataFetcherResult.newResult<Value>().data(it).build()
}.exceptionally {
DataFetcherResult.newResult<Value>().error(SimpleKotlinGraphQLError(it)).build()
}
}
bjartek
01/09/2020, 7:52 PMDariusz Kuc
01/09/2020, 7:55 PMWould it make sense to be able to say to a suspended function that if this throws and error I want to report and error and allow optional reponse? Or keep the current behavior of just erroring out the entire query if there is an error?It really depends on your use case - errors could be critical or not, if returned data is not useable by the end user then it should fail the entire qwuery
bjartek
01/09/2020, 7:57 PMbjartek
01/09/2020, 7:57 PMDariusz Kuc
01/09/2020, 7:57 PMnot complete victory though, missing the path and stuff from that exceptionyou should be able to get that through custom exception handler or by populating it in the data loader error handling block
Dariusz Kuc
01/09/2020, 7:58 PMI guess i could make my own FunctionDataFetcher and get that working without all the wrappers?you definitely can create custom data fetcher (we do in order to correctly build our coroutine context) but unsure if it will help much with the data loaders + error handling
bjartek
01/09/2020, 8:03 PMbjartek
01/09/2020, 8:03 PMDariusz Kuc
01/09/2020, 8:05 PMbjartek
01/09/2020, 8:16 PMbjartek
01/09/2020, 9:25 PMbjartek
01/09/2020, 9:25 PMDariusz Kuc
01/09/2020, 9:33 PM