我试图对突变进行更新并且它不能正常工作它告诉我,“setValue”不是函数',当在newEvent和relayEvent上执行console.log时给我回复正确的数据可以有人帮助我!
我的突变工作但不知何故数据没有更新,所以我需要做一个无效的更新程序
继承我的代码:
/* @flow */
import { graphql, commitMutation } from "react-relay";
import environment from "../../../relay/environment";
import type { EventSetAttendedInput } from "./__generated__/EventSetAttendedMutation.graphql";
import { connectionUpdater } from "../../../relay/mutationUtils";
const mutation = graphql`
mutation EventSetAttendedMutation($input: EventSetAttendedInput!) {
EventSetAttended(input: $input) {
event {
id
_id
attended(first: 10000) {
__typename
edges {
node {
person {
name
_id
id
}
}
}
}
invitations(first: 10000) {
__typename
edges {
node {
attended
person {
name
_id
id
}
}
}
}
}
error
}
}
`;
let tempID = 0;
const commit = (input: EventSetAttendedInput, onCompleted, onError) => {
return commitMutation(environment, {
mutation,
variables: {
input: {
...input,
clientMutationId: tempID++
}
},
onCompleted,
onError,
updater: store => {
let createAttendedField = store.getRootField("EventSetAttended");
let newEvent = createAttendedField.getLinkedRecord("event");
const relayEvent = store.get(input.eventId);
console.log(`eventStore: `, newEvent);
console.log(`relayEvent: `, relayEvent);
store.setValue(newEvent, "event");
}
});
};
export default { commit };
答案 0 :(得分:1)
updater: (store, data) => {
let createAttendedField = store.getRootField("EventSetAttended");
let newEvent = createAttendedField.getLinkedRecord("event");
const relayEvent = store.get(input.eventId);
relayEvent.setLinkedRecord(newEvent, "event");
}