{"action":"created","issue":{"url":"https://api.github.com/repos/apollographql/graphql-tag/issues/200","repository_url":"https://api.github.com/repos/apollographql/graphql-tag","labels_url":"https://api.github.com/repos/apollographql/graphql-tag/issues/200/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/graphql-tag/issues/200/comments","events_url":"https://api.github.com/repos/apollographql/graphql-tag/issues/200/events","html_url":"https://github.com/apollographql/graphql-tag/issues/200","id":346854040,"node_id":"MDU6SXNzdWUzNDY4NTQwNDA=","number":200,"title":"Cannot assign to read only property 'items' of object","user":{"login":"skolliecool","id":40667110,"node_id":"MDQ6VXNlcjQwNjY3MTEw","avatar_url":"https://avatars2.githubusercontent.com/u/40667110?v=4","gravatar_id":"","url":"https://api.github.com/users/skolliecool","html_url":"https://github.com/skolliecool","followers_url":"https://api.github.com/users/skolliecool/followers","following_url":"https://api.github.com/users/skolliecool/following{/other_user}","gists_url":"https://api.github.com/users/skolliecool/gists{/gist_id}","starred_url":"https://api.github.com/users/skolliecool/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skolliecool/subscriptions","organizations_url":"https://api.github.com/users/skolliecool/orgs","repos_url":"https://api.github.com/users/skolliecool/repos","events_url":"https://api.github.com/users/skolliecool/events{/privacy}","received_events_url":"https://api.github.com/users/skolliecool/received_events","type":"User","site_admin":false},"labels":[{"id":854172174,"node_id":"MDU6TGFiZWw4NTQxNzIxNzQ=","url":"https://api.github.com/repos/apollographql/graphql-tag/labels/has-reproduction","name":"has-reproduction","color":"42f44e","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-02T04:21:19Z","updated_at":"2018-10-09T19:54:39Z","closed_at":null,"author_association":"NONE","body":"**Issue Labels**\r\n\r\n<!--\r\nWhile not necessary, you can help organize our issues by labeling this issue when you open it.  To add a label automatically, simply [x] mark the appropriate box below:\r\n-->\r\n\r\n- [x] has-reproduction\r\n\r\nAfter a mutation, when updating my cache, I need to re-parse my query through `gql` again otherwise I get the error: `Cannot assign to read only property 'items' of object`\r\n\r\nA picture paints a thousand words...\r\n\r\nThis code example will elicit the error\r\n```\r\n    import { QUERY_GET_CHATMESSAGE, MUTATION_SEND_CHATMESSAGE } from 'client/graphql/messenger.gql';\r\n    \r\n    // MUTATION_SEND_CHATMESSAGE used below in a <Mutation /> tag to get to...\r\n     \r\n    sendChatMessage({\r\n      variables: { message },\r\n      optimisticResponse: {\r\n        __typename: 'Mutation',\r\n        sendChatMessage: {\r\n          __typename: 'ChatMessage',\r\n          id: Math.round(Math.random() * -1000000),\r\n          subId,\r\n          message,\r\n          username,\r\n          createdAt: new Date().toDateString(),\r\n        },\r\n      },\r\n      // eslint-disable-next-line no-shadow\r\n      update: (cache, { data: { sendChatMessage } }) => {\r\n        const { getChatMessages } = cache.readQuery({ query: QUERY_GET_CHATMESSAGE });\r\n\r\n        getChatMessages.items = [sendChatMessage, ...getChatMessages.items];\r\n\r\n        cache.writeQuery({\r\n          query: QUERY_GET_CHATMESSAGE,\r\n          data: { getChatMessages },\r\n        });\r\n      },\r\n    });\r\n  }\r\n```\r\nNow the above `Cannot assign to read only property 'items' of object` always happen. This however will work:\r\n```\r\n    import { MUTATION_SEND_CHATMESSAGE } from 'client/graphql/messenger.gql';\r\n    \r\n    // MUTATION_SEND_CHATMESSAGE used below in a <Mutation /> tag to get to...\r\n     \r\n    sendChatMessage({\r\n      variables: { message },\r\n      optimisticResponse: {\r\n        __typename: 'Mutation',\r\n        sendChatMessage: {\r\n          __typename: 'ChatMessage',\r\n          id: Math.round(Math.random() * -1000000),\r\n          subId,\r\n          message,\r\n          username,\r\n          createdAt: new Date().toDateString(),\r\n        },\r\n      },\r\n      // eslint-disable-next-line no-shadow\r\n      update: (cache, { data: { sendChatMessage } }) => {\r\n        const query = gql`\r\n         query {\r\n          getChatMessages {\r\n           items {\r\n            __typename\r\n            id\r\n            message\r\n            subId\r\n            username\r\n            createdAt\r\n          }\r\n         }\r\n        }`;\r\n        const { getChatMessages } = cache.readQuery({ query });\r\n\r\n        getChatMessages.items = [sendChatMessage, ...getChatMessages.items];\r\n\r\n        cache.writeQuery({\r\n          query: QUERY_GET_CHATMESSAGE,\r\n          data: { getChatMessages },\r\n        });\r\n      },\r\n    });\r\n  }\r\n``` \r\n\r\nThe second version (code directly above) works, but I have to wrap the query around `gql` before I do anything. I can't re-use the query that I imported.\r\n\r\nWHY? How can I get passed this?\r\n\r\n\r\n<!--\r\nYou are also able to add labels by placing /label on a new line\r\nfollowed by the label you would like to add. ex: /label discussion\r\n-->\r\n"},"comment":{"url":"https://api.github.com/repos/apollographql/graphql-tag/issues/comments/428328529","html_url":"https://github.com/apollographql/graphql-tag/issues/200#issuecomment-428328529","issue_url":"https://api.github.com/repos/apollographql/graphql-tag/issues/200","id":428328529,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODMyODUyOQ==","user":{"login":"ramsaylanier","id":2359852,"node_id":"MDQ6VXNlcjIzNTk4NTI=","avatar_url":"https://avatars1.githubusercontent.com/u/2359852?v=4","gravatar_id":"","url":"https://api.github.com/users/ramsaylanier","html_url":"https://github.com/ramsaylanier","followers_url":"https://api.github.com/users/ramsaylanier/followers","following_url":"https://api.github.com/users/ramsaylanier/following{/other_user}","gists_url":"https://api.github.com/users/ramsaylanier/gists{/gist_id}","starred_url":"https://api.github.com/users/ramsaylanier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramsaylanier/subscriptions","organizations_url":"https://api.github.com/users/ramsaylanier/orgs","repos_url":"https://api.github.com/users/ramsaylanier/repos","events_url":"https://api.github.com/users/ramsaylanier/events{/privacy}","received_events_url":"https://api.github.com/users/ramsaylanier/received_events","type":"User","site_admin":false},"created_at":"2018-10-09T19:54:39Z","updated_at":"2018-10-09T19:54:39Z","author_association":"NONE","body":"I'm having this same issue as well"}}
{"actor":{"display_login":"ramsaylanier"}}