Apollo查询项目详细信息时更新缓存列表

huangapple go评论84阅读模式
英文:

Apollo cache updates list when querying item details

问题

  1. 我遇到了Apollo GraphQL的问题:

  2. 我有一个名为categories的列表,每个category都有一个items列表。

  3. 每个category都有它自己的id,每个item都有它自己的id

  4. 当我拉取带有它们的itemscategories列表时,我只拉取那些可用的items

  5. 当我点击一个可用的item时,我需要拉取带有它的category详细信息,以及不可用的那些。

  6. 不幸的是,这会更新categories列表,包括不可用的items

我不知道如何将list缓存与details缓存分开。不幸的是,这些对象总是被更新。

英文:

I have a problem with Apollo GraphQL:

  1. I have a list categories and every category has a list of items.
  2. Every category has its id and every item has its id.
  3. When I pull the list of categories with their items, I pull only these items which are available.
  4. When I click an available item, I need to pull the category details with its items, also the unavailable ones.
  5. This unfortunately updates the categories list with unavailable items.

I don't know how to separate list cache from the details cache. Unfortunately the objects are always updated.

答案1

得分: 1

您的类型定义存在一个模糊性,缓存无法自动处理。您可以选择 (a) 直接操作缓存以获得所需的行为(实际上较困难),或者 (b) 在 categories 下定义一个名为 availableItems 的新字段,其中只包含可用物品。

英文:

Your type definitions have an ambiguity that the cache cannot deal with automatically. You can either (a) directly manipulate the cache to get the behavior you want (hard here actually) or (b) define a new field called availableItems under categories that only has available items.

huangapple
  • 本文由 发表于 2023年2月23日 22:49:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546429.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定