neetkee
06/25/2020, 4:01 PMLenny
06/25/2020, 4:59 PMDariusz Kuc
06/25/2020, 5:56 PMDariusz Kuc
06/25/2020, 5:57 PMDariusz Kuc
06/25/2020, 5:57 PMDariusz Kuc
06/25/2020, 5:59 PMtype Query {
products: [Products]
}
type Product {
description: ProductDescription
price: ProductPrice
reviews: [ProductReview]
}
Dariusz Kuc
06/25/2020, 6:01 PMfun products(): List<Product> {
// fetch product ids
// fetch description
// fetch price
// fetch reviews
return listOf(products)
}
or something like thatDariusz Kuc
06/25/2020, 6:02 PMProduct
would expose those fields as functions
class Product {
fun description(): ProductDescription { ... }
fun price(): ProductPrice { ... }
fun reviews(): List<ProductReview> { ... }
}
Dariusz Kuc
06/25/2020, 6:03 PMDariusz Kuc
06/25/2020, 6:03 PMDariusz Kuc
06/25/2020, 6:04 PMDariusz Kuc
06/25/2020, 6:05 PMProduct
are calculated based on some common data -> if you expose those fields as functions (so they are only calculated when requested) how do you share the common data?Dariusz Kuc
06/25/2020, 6:08 PMclass Product {
private val deferredServiceData = async {
slowCallGoesHere
}
fun description(): ProductDescription {
val sharedData = deferredServiceData.await()
// other logic
...
}
fun price(): ProductPrice {
val sharedData = deferredServiceData.await() // reuses same
// price logic
...
}
...
}
Dariusz Kuc
06/25/2020, 6:09 PMDariusz Kuc
06/25/2020, 6:10 PMneetkee
06/25/2020, 6:27 PMso it becomes problematic if your underlying services don’t support batch apisbut what if this underlying services support batching api? For example if price field requires a network call to ReviewService, and this service has a method like this:
fun getReviews(productIds: List<Long>)
neetkee
06/25/2020, 6:28 PMneetkee
06/25/2020, 6:30 PMneetkee
06/25/2020, 6:32 PManalyttics {
reviews {
star
}
}
Dariusz Kuc
06/25/2020, 6:34 PMfun products(): List<Product> {
// fetch product ids
// fetch description
// fetch price
// fetch reviews
return listOf(products)
}
neetkee
06/25/2020, 6:34 PManalytics {
reviews {
star
}
}
products {
reviews {
star
}
}
that will be handled too, and there will be only 1 network callDariusz Kuc
06/25/2020, 6:34 PMDariusz Kuc
06/25/2020, 6:35 PManalytics
and products
would generally reside in separate microservicesneetkee
06/25/2020, 6:40 PMproduct
needs to access external api in order to fetch reviews
, will be some reviewsClient
injected right into it?Dariusz Kuc
06/25/2020, 6:42 PMneetkee
06/25/2020, 6:49 PMneetkee
06/25/2020, 6:54 PMit depends how you structure your graphSo, if my graph may contain different objects, that use some shared source of data, is there any way to make less external calls? These objects could contain different arguments that were passed by our clients, or resolved during execution. I’m not sure if deffered variable can help here
Dariusz Kuc
06/25/2020, 6:55 PManalytics
and products
example I don’t think some common deferred would work as they dont share common parentDariusz Kuc
06/25/2020, 6:57 PM