我试图对突变进行更新,但它运行不正常,它告诉我“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 };