如何使用relay now中的新项目更新ui?
我有其他所有CRUD工作,但无法找出新项目的提交突变的更新程序。当我刷新页面时。所有示例都使用查看器对象,而我的架构中没有这个对象。
schema.graphql
type Note {
id: String
avatar: String
message: String
date: String
}
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);
}