2 years ago
#902

Andross
Mutate a result from "useResult" (Vue Apollo)
I am using the Composition API. I have a component which queries the backend and returns a list of events:
const { result, loading, error } = useQuery(FindEvents, variables, { fetchPolicy: 'cache-and-network' })
let events = useResult(result, [], data => data.events)
This works fine, however, I have a child component with a form where the user can edit the data of a single event, which is then mutated back to the backend, and emits an update to the Event list. However my function which handles the update on the list throws an error saying that it cannot update a computed value:
onEventUpdate (mutableEvent) {
try {
const index = _.findIndex(events.value, ({id}) => id === mutableEvent.id) // lodash
if (index < 0) {
events.value.push(mutableEvent);
} else {
events.value[index] = mutableEvent;
}
} catch (err) {
console.error(`Couldn't assign value: ${err}`) // TypeError: Cannot assign to read only property '12' of object '[object Array]'
}
}
Is there some way to update this property?
javascript
vuejs3
apollo-client
vue-apollo
0 Answers
Your Answer