【发布时间】:2020-06-14 23:48:19
【问题描述】:
调试更新:
因此,我们在调试方面更进一步,似乎 'client:root' 本身根本无法访问连接。
为了调试完整的 store,我们在从 relay/environment 导出 store 变量后,在 updater 函数中添加了这一行。
console.log(relayEnvStore.getSource().toJSON())
如果我使用带有特定字符串client:root:__ItemList_items_connection 的.get(),我可以访问我一直在寻找的记录,但它肯定不漂亮。
const testStore = store.get('client:root:__ItemList_items_connection')
console.log(testStore.getLinkedRecords('edges'))
原文:
我正在使用 Relay Modern 并尝试在使用更新程序完成 updateItem 突变后更新缓存。对ConnectionHandler.getConnection('client:root', 'ItemList_items') 的调用返回未定义。
我不确定是因为我试图使用 'client:root' 作为我的父记录,还是我的代码有问题。有没有人发现自己有类似的问题?
这是 paginationContainer:
const ItemListPaginationContainer = createPaginationContainer(
ItemList,
{
node: graphql`
fragment ItemList_node on Query
@argumentDefinitions(count: { type: "Int", defaultValue: 3 }, cursor: { type: "String" }) {
items(first: $count, after: $cursor) @connection(key: "ItemList_items") {
edges {
cursor
node {
id
name
}
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
`
},
{
direction: 'forward',
getConnectionFromProps: props => props.node && props.node.items,
getVariables(props, { count, cursor }) {
return {
count,
cursor
}
},
query: graphql`
query ItemListQuery($count: Int!, $cursor: String) {
...ItemList_node @arguments(count: $count, cursor: $cursor)
}
`
}
)
这是突变:
const mutation = graphql`
mutation UpdateItemMutation($id: ID!, $name: String) {
updateItem(id: $id, name: $name) {
id
name
}
}
`
这是更新程序:
updater: (store) => {
const root = store.getRoot()
const conn = ConnectionHandler.getConnection(
root, // parent record
'ItemList_items' // connection key
)
console.log(conn)
},
【问题讨论】:
标签: relayjs relay relaymodern