{"action":"created","issue":{"url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/757","repository_url":"https://api.github.com/repos/react-cosmos/react-cosmos","labels_url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/757/labels{/name}","comments_url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/757/comments","events_url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/757/events","html_url":"https://github.com/react-cosmos/react-cosmos/issues/757","id":341837962,"node_id":"MDU6SXNzdWUzNDE4Mzc5NjI=","number":757,"title":"Mocking apollo InMemoryCache not working","user":{"login":"jeznag","id":1034890,"node_id":"MDQ6VXNlcjEwMzQ4OTA=","avatar_url":"https://avatars3.githubusercontent.com/u/1034890?v=4","gravatar_id":"","url":"https://api.github.com/users/jeznag","html_url":"https://github.com/jeznag","followers_url":"https://api.github.com/users/jeznag/followers","following_url":"https://api.github.com/users/jeznag/following{/other_user}","gists_url":"https://api.github.com/users/jeznag/gists{/gist_id}","starred_url":"https://api.github.com/users/jeznag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeznag/subscriptions","organizations_url":"https://api.github.com/users/jeznag/orgs","repos_url":"https://api.github.com/users/jeznag/repos","events_url":"https://api.github.com/users/jeznag/events{/privacy}","received_events_url":"https://api.github.com/users/jeznag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-17T09:28:49Z","updated_at":"2018-07-23T20:08:20Z","closed_at":null,"author_association":"NONE","body":"### What's wrong?\r\nI'm trying to use the apollo proxy for a unit test.\r\nI'm getting the below error triggered when my code tries to read from the Apollo InMemoryCache\r\n\r\n```\r\nconsole.error node_modules/apollo-utilities/lib/bundle.umd.js:790\r\n    Error: Can't find field availableOptions on object (ROOT_QUERY) undefined.\r\n        at readStoreResolver (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/apollo-cache-inmemory/src/readFromStore.ts:116:13)\r\n        at executeField (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/graphql-anywhere/src/graphql.ts:192:18)\r\n        at /Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/graphql-anywhere/src/graphql.ts:130:27\r\n        at Array.forEach (native)\r\n        at executeSelectionSet (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/graphql-anywhere/src/graphql.ts:123:27)\r\n        at graphql (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/graphql-anywhere/src/graphql.ts:107:10)\r\n        at diffQueryAgainstStore (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/apollo-cache-inmemory/src/readFromStore.ts:198:18)\r\n        at readQueryFromStore (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/apollo-cache-inmemory/src/readFromStore.ts:56:10)\r\n        at InMemoryCache.Object.<anonymous>.InMemoryCache.read (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/apollo-cache-inmemory/src/inMemoryCache.ts:94:12)\r\n        at InMemoryCache.Object.<anonymous>.InMemoryCache.readQuery (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/apollo-cache-inmemory/src/inMemoryCache.ts:225:17)\r\n        at updateCache (/Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/src/RequestData/SubmitForm.tsx:20:11)\r\n        at /Users/jeremynagel/dev/energylink-project/react-components/data-exporter2/node_modules/src/data/store.ts:180:39\r\n```\r\n\r\nHere is the updateCache method (that gets called when the mutation is triggered). The error occurs at `cache.readQuery` (there is no problem when I run the app).\r\n```\r\nconst updateCache = (cache: any) => {\r\n  const { availableOptions } = cache.readQuery({ query: getAvailableOptions });\r\n\r\n  cache.writeQuery({\r\n    query: getAvailableOptions,\r\n    data: {\r\n      availableOptions: {\r\n        ...availableOptions,\r\n        submitted: true\r\n      }\r\n    }\r\n  });\r\n};\r\n```\r\n\r\n```\r\n<Mutation mutation={saveExportDataRequest} update={updateCache}>\r\n....\r\n</Mutation>\r\n```\r\n\r\n### Steps to reproduce\r\n\r\nThis is my fixture:\r\n```\r\nexport default {\r\n  component: SubmitForm,\r\n  context: {\r\n    i18n: i18nInstance\r\n  },\r\n  apollo: {\r\n    resolveWith: (apolloData: any) => {\r\n      const fakeData = {\r\n        availableOptions: {\r\n         //left out for conciseness\r\n        }\r\n      };\r\n      apolloData.cache.writeQuery({\r\n        query: getAvailableOptions,\r\n        data: fakeData\r\n      });\r\n\r\n      return {\r\n        availableOptions: fakeData,\r\n        saveExportDataRequest: {\r\n          NoResponse: null,\r\n          __typename: 'saveExportDataRequest'\r\n        }\r\n      };\r\n    }\r\n  }\r\n};\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/comments/407184448","html_url":"https://github.com/react-cosmos/react-cosmos/issues/757#issuecomment-407184448","issue_url":"https://api.github.com/repos/react-cosmos/react-cosmos/issues/757","id":407184448,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNzE4NDQ0OA==","user":{"login":"skidding","id":250750,"node_id":"MDQ6VXNlcjI1MDc1MA==","avatar_url":"https://avatars0.githubusercontent.com/u/250750?v=4","gravatar_id":"","url":"https://api.github.com/users/skidding","html_url":"https://github.com/skidding","followers_url":"https://api.github.com/users/skidding/followers","following_url":"https://api.github.com/users/skidding/following{/other_user}","gists_url":"https://api.github.com/users/skidding/gists{/gist_id}","starred_url":"https://api.github.com/users/skidding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skidding/subscriptions","organizations_url":"https://api.github.com/users/skidding/orgs","repos_url":"https://api.github.com/users/skidding/repos","events_url":"https://api.github.com/users/skidding/events{/privacy}","received_events_url":"https://api.github.com/users/skidding/received_events","type":"User","site_admin":false},"created_at":"2018-07-23T20:08:19Z","updated_at":"2018-07-23T20:08:19Z","author_association":"MEMBER","body":"@xavczen Do you have any thoughts on this? Unfortunately I don't have knowledge into Apollo's InMemoryCache API. Thanks!"}}
{"actor":{"display_login":"skidding"}}