Apollo 客户端:Redux 工具包“transformResponse()”在 Apollo 客户端中的对应物是什么?

问题描述 投票:0回答:2

在 Apollo Client 中,我想在 GraphQL 查询的响应到达缓存之前使用自定义方法

transformResponse()
转换它。

在 Redux Toolkit (RTK) 中,此功能可用,称为

transformResponse()
(https://redux-toolkit.js.org/rtk-query/usage/customizing-queries#customizing-query-responses-with -转换响应).

那么问题来了:RTK中

transformResponse()
的对应物在Apollo Client中存在吗?无论答案是或否,执行此类操作的正确方法是什么?

graphql apollo-client redux-toolkit
2个回答
0
投票

是的,你不能用 Apollo Client 做到这一点,因为它真的模仿了你的查询结构。
不过,您可以让查询包含片段,并使用实验性(自 AC 3.7 起)

useFragment
挂钩直接从您的组件访问这些片段(同时父组件获取查询)。这可能是你最接近的。

对于其他一切,您必须创建一个自定义挂钩,在

useMemo
挂钩调用中执行此转换。


0
投票

我觉得,你可以试试

afterware
修改回复

这里是同一期的详细线程: https://github.com/apollographql/apollo-client/issues/2534

© www.soinside.com 2019 - 2024. All rights reserved.