Cannot edit response object - Object frozen
See original GitHub issueHi, I have the following code:
const GetChatsQuery = gql query($withBlocked: Boolean) { userChats(withBlocked: $withBlocked) { ${ GetChatGraphQL(10) } } }
;
` return this.apollo.query({
query: GetChatsQuery,
variables: {
withBlocked: withBlocked
}
}).map(res => {
let response = <GetChatsResponse>res.data;
// I get here the error
response.userChats[0].messages.push(null);
return response.userChats;
})`
The thing is that I’m getting an error on the push method:
Cannot add property 2, object is not extensible
As I understood from the internet it means that the object is frozen (Object.freeze
).
Have anyone had that problem before? how can I solve it?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:15 (3 by maintainers)
Top Results From Across the Web
Cannot edit response object - Object frozen · Issue #329
Hi, I have the following code: const GetChatsQuery = gql query($withBlocked: Boolean) { userChats(withBlocked: $withBlocked) ...
Read more >Object.freeze() - JavaScript - MDN Web Docs
As an object, an array can be frozen; after doing so, its elements cannot be altered and no elements can be added to...
Read more >Opposite of Object.freeze or Object.seal in JavaScript
There is no way to do this, once an object has been frozen there is no way to unfreeze it. Source. Freezing an...
Read more >JavaScript object immutability: Object.freeze vs. Object.seal
When we freeze an object using Object.freeze , it can no longer be modified. Essentially, new properties can no longer be added to...
Read more >JavaScript Immutability – Frozen Objects in JS Explained ...
When an object is immutable, you can't add a new property to it, modify it, or delete an existing property. There is no...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s by design. You don’t want to touch store directly so Apollo Client freezes the result. It’s the same behaviour as in Redux, Ngrx and so on. They don’t freeze the results but they say to not mutate it. This won’t change anytime soon.
Messes things up, I’ll just deep-copy the response like this: