I'm building an app with VueJS and I'm using Apollo client to fetch data from a database through a GrapgQL server. I have code that looks like this:
apollo.query({
query,
variables
})
// context.commit('populateComments', payload) triggers the mutation
.then(payload => context.commit('populateComments', payload))
Then, in my mutations I have the following
populateComments: (state, payload) => {
state.comments = payload.data.comments
}
When I try to push another object into the comments array in another mutation I get an error that reads "Cannot add property 300, object is not extensible". I have found that the following works
state.comments = Array.from(payload.data.comments)
But.. I'm not sure how effective it is to repeatedly copy large arrays like this? Is this the preferred way to do it?