javascript - 在缓存类型策略中添加嵌套字段 - Apollo v3
问题描述
我想知道是否可以使用 InMemoryCache 的 typePolicies 来嵌套值 现在您可以定义平面字段策略
new InMemoryCache({
typePolicies: {
Query: {
fields: {
hello: {
read() {
return 'hello'
},
},
hola: {
read() {
return 'hola'
},
},
},
},
},
})
// query flat local field using apollo
const QUERY_USER_PAGE = gql`
query UserPage {
hello
hola
}
`
如果我想要 typePolicies 来反映我的应用程序的结构,这似乎是一个很好的做法。
扁平结构将在大型项目的扩展和维护方面受到限制。
new InMemoryCache({
typePolicies: {
Query: {
fields: {
userPage: {
hello: {
read() {
return 'hello'
},
},
hola: {
read() {
return 'hola'
},
},
},
},
},
},
})
// query nested local field using apollo:
const QUERY_USER_PAGE = gql`
query UserPage {
userPage @client {
hello
hola
}
}
`
解决方案
推荐阅读
- javascript - 如何在 React 中添加透明滚动条?
- javascript - 异步等待承诺的正确输出?
- laravel - I have problem when i logout from admin "Trying to get property 'id' of non-object" using laravel
- shell - 请告诉我这个 shell 脚本中的问题?它没有运行条件语句....结果仅显示在 unsub 类别中?
- javascript - 在 Jest 测试中模拟 auth0-spa-js 的安全来源
- opengl - 无法创建多重采样帧缓冲区
- python - 我可以模糊 qwidget “menu_pos_” 后面的背景吗?
- flutter - 如何在颤动中禁用 Cupertinopicker?
- mysql-workbench - 错误代码:1582。调用本机函数“SUBSTRING_INDEX”时的参数计数不正确
- azure-pipelines - 天蓝色管道中 timeoutInMinutes 的条件