absinthe dataloader 简单说明

dataloader 核心是为了解决graphql 对于后段服务的频繁调用,absinthe 基于graphql的dataloader 实现了elixir 版本的

参考使用

  • 代码
source = Dataloader.Ecto.new(MyApp.Repo)
 
# setup the loader
loader = Dataloader.new |> Dataloader.add_source(:db, source)
 
# load some things
loader =
  loader
  |> Dataloader.load(:db, Organization, 1)
  |> Dataloader.load_many(:db, Organization, [4, 9])
 
# actually retrieve them
loader = Dataloader.run(loader)
 
# Now we can get whatever values out we want
organizations = Dataloader.get_many(loader, :db, Organization, [1,4])

简单说明: 上边使用了Dataloader 查询数据库的数据,对于数据的查询,可以一个查询就能解决Organization 查询1,4,9 id 的问题
目前dataloader 包含了两类source,ecto 的以及kv 的

参考资料

https://hexdocs.pm/absinthe/dataloader.html
https://github.com/graphql/dataloader
https://hexdocs.pm/dataloader/2.0.0/Dataloader.KV.html

posted on   荣锋亮  阅读(4)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2023-01-03 nginx-clojure 调试简单试用
2023-01-03 dremio 表函数简单说明
2023-01-03 nginx-clojure java 集成试用
2023-01-03 apache drill 提供的physical-operators 以及说明
2023-01-03 dremio 数据存储结构示例
2022-01-03 castled 运行试用
2022-01-03 反向ETL 一些参考知识

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示