How to update ui with a new element in a relay?
All the other CRUDs work for me, but I can’t figure out how to update the update to commit for a new item. When I refresh the page there. All examples use a viewer, which I do not have in my schema.
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 => {
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);
}
source
share