{"action":"created","issue":{"url":"https://api.github.com/repos/apollographql/apollo-client/issues/3030","repository_url":"https://api.github.com/repos/apollographql/apollo-client","labels_url":"https://api.github.com/repos/apollographql/apollo-client/issues/3030/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/apollo-client/issues/3030/comments","events_url":"https://api.github.com/repos/apollographql/apollo-client/issues/3030/events","html_url":"https://github.com/apollographql/apollo-client/issues/3030","id":297698892,"number":3030,"title":"Fetch policy no-cache returns null data","user":{"login":"razor-x","id":721372,"avatar_url":"https://avatars3.githubusercontent.com/u/721372?v=4","gravatar_id":"","url":"https://api.github.com/users/razor-x","html_url":"https://github.com/razor-x","followers_url":"https://api.github.com/users/razor-x/followers","following_url":"https://api.github.com/users/razor-x/following{/other_user}","gists_url":"https://api.github.com/users/razor-x/gists{/gist_id}","starred_url":"https://api.github.com/users/razor-x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razor-x/subscriptions","organizations_url":"https://api.github.com/users/razor-x/orgs","repos_url":"https://api.github.com/users/razor-x/repos","events_url":"https://api.github.com/users/razor-x/events{/privacy}","received_events_url":"https://api.github.com/users/razor-x/received_events","type":"User","site_admin":false},"labels":[{"id":332593317,"url":"https://api.github.com/repos/apollographql/apollo-client/labels/bug","name":"bug","color":"fc2929","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-16T07:13:49Z","updated_at":"2018-02-20T19:57:56Z","closed_at":null,"author_association":"NONE","body":"**Intended outcome:**\r\n\r\nRun a query and receive non-null data when using `fetchPolicy: 'no-cache'`. Tested on Node and in Browser.\r\n\r\n```js\r\nclient.query({query, fetchPolicy: 'no-cache'})\r\n```\r\n\r\n**Actual outcome:**\r\n\r\nThe `data` property is `null`:\r\n\r\n```js\r\n{\r\n  data: null\r\n  loading: false\r\n  networkStatus: 7\r\n  stale: true\r\n}\r\n```\r\n\r\n**How to reproduce the issue:**\r\n\r\n#### Node.js\r\n\r\n1. Visit this runkit and fork it: https://runkit.com/razorx/apollo-client-no-cache/4.0.1\r\n2. Run the first box to initialize.\r\n3. Run the second box to run a query with the default fetch policy: the Promise will eventually resolve with good data (`data: {...}` ). (expected)\r\n4. Run the second box to run a query with the `no-cache` fetch policy: the Promise will eventually resolve with no data (`data: null`). (unexpected)\r\n5. Run the second box to run a query with the `network-only` fetch policy: the Promise will eventually resolve with good data. (expected)\r\n\r\n#### Browser\r\n\r\n1. Visit https://codesandbox.io/s/znx9n9x943\r\n2. Run the code with the \"refresh\" button in the right pane.\r\n    - `clientA` works with default fetch policy: returns non-null data. (expected)\r\n    - `clientB` does not work with `no-cache` fetch policy: returns `null` data. (unexpected)\r\n    - `clientC` works with default fetch policy (returns non-null data), then the **query is repeated again with `clientC`, this time with `no-cache` fetch policy, and the data returns non-null!** (what?)\r\n\r\n**Version**\r\n- apollo-client@2.2.3\r\n\r\n**Contents of the runkit for reference**\r\n\r\n```js\r\nrequire('isomorphic-fetch')\r\nrequire('graphql')\r\nconst { ApolloClient } = require('apollo-client')\r\nconst { HttpLink } = require('apollo-link-http')\r\nconst { InMemoryCache } = require('apollo-cache-inmemory')\r\nconst gql = require('graphql-tag')\r\n\r\nconst uri = 'https://graphql-pokemon.now.sh/graphql'\r\n\r\nconst query = gql`{\r\n  pokemon(name: \"Pikachu\") {\r\n    id\r\n    number\r\n    name\r\n  }\r\n}`\r\n\r\nconst client = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n})\r\n\r\nclient.query({query})\r\n  .then(data => console.log(data))\r\n  .catch(error => console.error(error))\r\n  \r\n// => gives good data\r\n  \r\n const clientNoCache = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n})\r\n\r\nclientNoCache.query({query, fetchPolicy: 'no-cache'})\r\n  .then(data => console.log(data))\r\n  .catch(error => console.error(error))\r\n  \r\n// => gives NULL data\r\n\r\nconst clientNetworkOnly = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n})\r\n\r\nclientNoCache.query({query, fetchPolicy: 'network-only'})\r\n  .then(data => console.log(data))\r\n  .catch(error => console.error(error))\r\n  \r\n// => gives good data\r\n```\r\n\r\n**Contents of the browser example for reference**\r\n\r\n```js\r\nimport { gql, graphql } from 'react-apollo';\r\nimport { ApolloClient } from 'apollo-client';\r\nimport { HttpLink } from 'apollo-link-http';\r\nimport { InMemoryCache } from 'apollo-cache-inmemory';\r\nimport { ApolloProvider } from 'react-apollo';\r\nimport App from './App';\r\n\r\nconst uri = 'https://qkv3mq9rp.lp.gql.zone/graphql'\r\n\r\nconst clientA = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n});\r\n\r\nconst clientB = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n});\r\n\r\nconst clientC = new ApolloClient({\r\n  link: new HttpLink({uri}),\r\n  cache: new InMemoryCache()\r\n});\r\n\r\nconst query = gql`{\r\n  people {\r\n    id\r\n    name\r\n  }\r\n}\r\n`\r\n\r\nclientA.query({query})\r\n  .then(data => document.write('A cache<br \\><br \\>' + JSON.stringify(data)))\r\n  .then(() => clientB.query({query, fetchPolicy: 'no-cache'}))\r\n  .then(data => document.write('<br \\><br \\>B no-cache<br \\><br \\>' + JSON.stringify(data)))\r\n  .then(() => clientC.query({query}))\r\n  .then(data => document.write('<br \\><br \\>C cache<br \\><br \\>' + JSON.stringify(data)))\r\n  .then(() => clientC.query({query, fetchPolicy: 'no-cache'}))\r\n  .then(data => document.write('<br \\><br \\>C no-cache<br \\><br \\>' + JSON.stringify(data)))\r\n  .catch(error => console.error(error))\r\n```"},"comment":{"url":"https://api.github.com/repos/apollographql/apollo-client/issues/comments/367100177","html_url":"https://github.com/apollographql/apollo-client/issues/3030#issuecomment-367100177","issue_url":"https://api.github.com/repos/apollographql/apollo-client/issues/3030","id":367100177,"user":{"login":"razor-x","id":721372,"avatar_url":"https://avatars3.githubusercontent.com/u/721372?v=4","gravatar_id":"","url":"https://api.github.com/users/razor-x","html_url":"https://github.com/razor-x","followers_url":"https://api.github.com/users/razor-x/followers","following_url":"https://api.github.com/users/razor-x/following{/other_user}","gists_url":"https://api.github.com/users/razor-x/gists{/gist_id}","starred_url":"https://api.github.com/users/razor-x/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/razor-x/subscriptions","organizations_url":"https://api.github.com/users/razor-x/orgs","repos_url":"https://api.github.com/users/razor-x/repos","events_url":"https://api.github.com/users/razor-x/events{/privacy}","received_events_url":"https://api.github.com/users/razor-x/received_events","type":"User","site_admin":false},"created_at":"2018-02-20T19:57:55Z","updated_at":"2018-02-20T19:57:55Z","author_association":"NONE","body":"@rschef I need this to work in a system which doesn't know about react and uses this client directly, so unfortunately that workaround won't be an option for me.\r\n\r\nI poked around a little in [QueryManager.ts](https://github.com/apollographql/apollo-client/blob/master/packages/apollo-client/src/core/QueryManager.ts) but I couldn't find an obvious reason for this bug. \r\n\r\nI'm hoping someone more familiar with the code will be able to prioritize and find this quickly. I would consider this a serious bug as I could rephrase the issue as  **apollo-client does not support the most basic GraphQL operation: running a query and returning the correct result** (without the added complexity of caching)."}}
{"actor":{"display_login":"razor-x"}}