Spring Boot GraphQL Tutorial #30 – DataLoader Key Context смотреть онлайн
The dreaded graphql N+1 problem gives most devs the creeps.
By default in GraphQL, a query resolver will resolve a field's nodes sequentially. When you have a list (see connection cursor video linked below) of nodes, It will resolve each node's fields sequentially. For example if you have 2 nodes with field X in the selection set. It will execute the query resolver first, then resolver for Node1 Field X followed by Node2 Field X. This is the N+1 problem.
We figured out how to solve the above dataloader n+1 problem in part 23: https://www.youtube.com/watch?v=tbxskis_ny4
BUT Now we have another problem!
What happens if we require some additional fields from the BankAccount (Context) inside the dataloader function? How do we pass them into the dataloader?
In this example, we may need to enrich the Balance response with another field contained the BankAccount. This final value would then be set into the dataloader's return Map.
To solve this problem, we can load the ID with a context into the dataloader. In this example, the context is BankAccount. The IDs mapped to Contexts are accessible inside the dataloader function via the BatchLoaderEnvironment#getKeyContexts. Unfortunately this returns a Map(Object, Object) instead of the preferred generic types, so we loose type safety. To get around this, we cast this to Map, then we pass the Map into our function with Map(UUID, BankAccount) defined as the method parameters.
But, why don't we just load the BankAccount into the dataloader?
This sounds good and easy - BUT If you do that, then we no-longer get the speed from the UUID hashmap lookups. So we always use the most efficient key possible.
Please check out the github graphql java dataloader docs for more detail and examples!
See you in the next video!
Cheers,
Philip
Spring Boot GraphQL Java: https://github.com/graphql-java-kickstart/graphql-spring-boot
GraphQL Java DataLoader: https://github.com/graphql-java/java-dataloader
Mapped Batch DataLoader: https://github.com/graphql-java/java-dataloader#returning-a-map-of-results-from-your-batch-loader
GraphQL DataLoader from facebook: https://github.com/graphql/dataloader
GraphQL Connection Cursor Pagination Tutorial: https://www.youtube.com/watch?v=J9Nq0Fq7t_8
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Spring Boot GraphQL Tutorial #30 – DataLoader Key Context» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.