question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot edit response object - Object frozen

See original GitHub issue

Hi, 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:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
kamilkisielacommented, May 11, 2018

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.

3reactions
ranbuchcommented, Jul 19, 2018
Object.freeze = () => {}

Messes things up, I’ll just deep-copy the response like this:

let unFreeze = JSON.parse(JSON.stringify(response));
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found