oti*_*ssv 5 javascript relay graphql
如何使用现代接力中的新项目更新ui?
我有所有其他CRUD工作,但无法弄清楚新项目的提交突变的更新程序.当我刷新页面时.所有示例都使用查看器对象,我的架构中没有查看器对象.
schema.graphql
type Note {
id: String
avatar: String
message: String
date: String
}
Run Code Online (Sandbox Code Playgroud)
create_mutation.js
export function createMutation({ mutation, variables, environment, create }) {
const fragment = mutation().fragment;
const operation = fragment.selections[0].name;
const mutationName = fragment.name;
const type = fragment.selections[0].concreteType;
const id = 'client:${operation}:${cuid()}';
const config = {
mutation,
variables,
optimisticUpdater: proxyStore => {
// 1. Create mock record that to be added to the store
const record = proxyStore.create(id, type);
Object.keys({ ...variables, id }).forEach(key =>
record.setValue(key, `${key}`)
);
const viewerProxy = proxyStore.get(operation);
const connection = ConnectionHandler.getConnection(record, mutationName);
if (connection) {
ConnectionHandler.insertEdgeAfter(viewerProxy, record);
}
},
updater: proxyStore => {},
onError: error => console.log(error)
};
commitMutation(environment, config);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
365 次 |
| 最近记录: |