变异后不影响现有查询的自动更新apollo客户端缓存 [英] Auto-update of apollo client cache after mutation not affecting existing queries
问题描述
我有一个变异(UploadTransaction),它返回某些名为Transaction的对象的某些列表.
I have a mutation (UploadTransaction) returning certain list of certain object named Transaction.
#import "TransactionFields.gql"
mutation UploadTransaction($files: [Upload!]!) {
uploadFile(files: $files){
transactions {
...TransactionFields
}
}
}
从后端(石墨烯)返回的事务具有id和typename字段.因此,它应该自动更新缓存中的Transaction.在用于Apollo的chrome开发工具中,我可以看到新的事务:
Transaction returned from backend (graphene) has id and typename field. Hence it should automatically update Transaction in the cache. In chrome dev tools for Apollo, I can see new transactions:
我还有一个查询GetTransactions,可获取所有Transaction对象.
I also have a query GetTransactions fetching all Transaction objects.
#import "TransactionFields.gql"
query GetTransactions {
transactions {
...TransactionFields
}
}
但是,我没有看到查询返回新添加的事务.在初始加载期间,Apollo客户端加载了292个事务,该事务在ROOT_QUERY下显示.它不断返回相同的292笔交易. UploadTransaction变异会在开发人员工具的缓存中添加类型为事务"的新对象,而不会影响开发人员工具中的ROOT_QUERY或代码中的查询.
However I don't see newly added Transaction being returned by the query. During initial load, Apollo client loaded 292 transactions which it shows under ROOT_QUERY. It keeps returning same 292 transactions. UploadTransaction mutation add new object of type "Transaction" in cache in dev-tools without affecting ROOT_QUERY in dev-tools or my query in code.
TransactionFields.gql是
TransactionFields.gql is
fragment TransactionFields on Transaction {
id
timestamp
description
amount
category {
id
name
}
currency
}
知道我在做什么错吗?我是apollo客户端和graphql的新手
Any idea what am I doing wrong? I am new to apollo client and graphql