{"action":"closed","issue":{"url":"https://api.github.com/repos/mattkrick/cashay/issues/154","repository_url":"https://api.github.com/repos/mattkrick/cashay","labels_url":"https://api.github.com/repos/mattkrick/cashay/issues/154/labels{/name}","comments_url":"https://api.github.com/repos/mattkrick/cashay/issues/154/comments","events_url":"https://api.github.com/repos/mattkrick/cashay/issues/154/events","html_url":"https://github.com/mattkrick/cashay/issues/154","id":197851696,"number":154,"title":"Conditionally cached? - part 2","user":{"login":"dustinfarris","id":1087165,"avatar_url":"https://avatars.githubusercontent.com/u/1087165?v=3","gravatar_id":"","url":"https://api.github.com/users/dustinfarris","html_url":"https://github.com/dustinfarris","followers_url":"https://api.github.com/users/dustinfarris/followers","following_url":"https://api.github.com/users/dustinfarris/following{/other_user}","gists_url":"https://api.github.com/users/dustinfarris/gists{/gist_id}","starred_url":"https://api.github.com/users/dustinfarris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dustinfarris/subscriptions","organizations_url":"https://api.github.com/users/dustinfarris/orgs","repos_url":"https://api.github.com/users/dustinfarris/repos","events_url":"https://api.github.com/users/dustinfarris/events{/privacy}","received_events_url":"https://api.github.com/users/dustinfarris/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-12-28T13:15:37Z","updated_at":"2016-12-31T00:21:13Z","closed_at":"2016-12-31T00:21:13Z","body":"Extending #153 \r\n\r\nIf i have an items index route and items detail route.  And I don't know how the user will enter.\r\n\r\nThis is how I'm attempting to use cache when possible:\r\n\r\nIndex component:\r\n\r\n```js\r\nconst itemsQuery = `\r\nquery {\r\n  items {\r\n    id\r\n    name\r\n  }\r\n}\r\n`;\r\n\r\nconst stateToComputed = () => {\r\n  const { data: { items } } = cashay.query(itemsQuery, {\r\n    op: 'items-index'\r\n  });\r\n  return { items };\r\n};\r\n```\r\n\r\nDetail component\r\n\r\n```js\r\nconst itemQuery = `\r\nquery {\r\n  cachedItem @cached(id: $item_id, type: \"Item\") {\r\n    id\r\n    name\r\n  }\r\n  item(id: $item_id) {\r\n    id\r\n    name\r\n  }\r\n};\r\n`;\r\n\r\nconst stateToComputed = (state, { item_id }) => {\r\n  const { data: { cachedItem } } = cashay.query(itemQuery, {\r\n    op: 'item-detail',\r\n    key: item_id,\r\n    variables: { item_id }\r\n  });\r\n  return { item: cachedItem };\r\n};\r\n```\r\n\r\nThis works.  \r\n\r\nIt uses the cache when the user has already seen the index route.  It makes a server request regardless, but the cached data is already rendered.\r\n\r\nIf the user enters the detail route directly, the server request resolves as normal which fills out the cache and, again, the cache is used to render.\r\n\r\nBut it feels clunky.  Am I missing something?"}}
{"actor":{"display_login":"dustinfarris"}}