英文:
Apollo cache updates list when querying item details
问题
-
我遇到了Apollo GraphQL的问题:
-
我有一个名为
categories的列表,每个category都有一个items列表。 -
每个
category都有它自己的id,每个item都有它自己的id。 -
当我拉取带有它们的
items的categories列表时,我只拉取那些可用的items。 -
当我点击一个可用的
item时,我需要拉取带有它的category详细信息,以及不可用的那些。 -
不幸的是,这会更新
categories列表,包括不可用的items。
我不知道如何将list缓存与details缓存分开。不幸的是,这些对象总是被更新。
英文:
I have a problem with Apollo GraphQL:
- I have a list
categoriesand everycategoryhas a list ofitems. - Every
categoryhas itsidand everyitemhas itsid. - When I pull the list of
categorieswith theiritems, I pull only theseitemswhich are available. - When I click an available
item, I need to pull thecategorydetails with itsitems, also the unavailable ones. - This unfortunately updates the
categorieslist 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论