{"action":"created","issue":{"url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/185","repository_url":"https://api.github.com/repos/apollographql/apollo-link-state","labels_url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/185/labels{/name}","comments_url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/185/comments","events_url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/185/events","html_url":"https://github.com/apollographql/apollo-link-state/issues/185","id":292354930,"number":185,"title":"Next.js + link-state + SSR","user":{"login":"f2net","id":5776052,"avatar_url":"https://avatars1.githubusercontent.com/u/5776052?v=4","gravatar_id":"","url":"https://api.github.com/users/f2net","html_url":"https://github.com/f2net","followers_url":"https://api.github.com/users/f2net/followers","following_url":"https://api.github.com/users/f2net/following{/other_user}","gists_url":"https://api.github.com/users/f2net/gists{/gist_id}","starred_url":"https://api.github.com/users/f2net/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f2net/subscriptions","organizations_url":"https://api.github.com/users/f2net/orgs","repos_url":"https://api.github.com/users/f2net/repos","events_url":"https://api.github.com/users/f2net/events{/privacy}","received_events_url":"https://api.github.com/users/f2net/received_events","type":"User","site_admin":false},"labels":[{"id":733614095,"url":"https://api.github.com/repos/apollographql/apollo-link-state/labels/question","name":"question","color":"cc317c","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2018-01-29T10:29:10Z","updated_at":"2018-03-27T23:08:52Z","closed_at":null,"author_association":"NONE","body":"I receive an error when using apollo-link-state with Next.js/Apollo (modifying the \"with Apollo\" example in Next.js repository). I'm not sure it is an issue really: I may be missing something.\r\nSee the original \"with Apollo\" example:\r\nhttps://github.com/zeit/next.js/tree/canary/examples/with-apollo\r\n\r\nHere's my code for initApollo:\r\n\r\n```javascript\r\nimport { ApolloClient } from 'apollo-client'\r\nimport { HttpLink } from 'apollo-link-http'\r\nimport { InMemoryCache } from 'apollo-cache-inmemory'\r\nimport fetch from 'isomorphic-fetch'\r\n\r\nimport { ApolloLink } from 'apollo-link'\r\nimport { withClientState } from 'apollo-link-state'\r\n\r\nimport config from '../config'\r\n\r\nlet apolloClient = null\r\n\r\n// Polyfill fetch() on the server (used by apollo-client)\r\nif (!process.browser) {\r\n  global.fetch = fetch\r\n}\r\n\r\nconst cache = new InMemoryCache()\r\n\r\nconst defaultState = {\r\n  currentView: {\r\n    __typename: 'CurrentView',\r\n    view: 'list'\r\n  }\r\n}\r\n\r\nconst stateLink = withClientState({\r\n  cache,\r\n  defaults: defaultState\r\n  // resolvers: {\r\n  //   Mutation: {\r\n  //     switchView: (_, { currentView }, { cache }) => {\r\n  //       const query = gql`\r\n  //         query getCurrentView {\r\n  //           getCurrentView @client {\r\n  //             currentView\r\n  //           }\r\n  //         }\r\n  //       `\r\n  //       const previous = cache.readQuery({ query })\r\n  //       const data = {\r\n  //         currentView: {\r\n  //           ...previous.currentView,\r\n  //           currentView: view\r\n  //         }\r\n  //       }\r\n\r\n  //       cache.writeQuery({ query, data })\r\n  //     }\r\n  //   }\r\n  // }\r\n})\r\n\r\nfunction create (initialState) {\r\n  return new ApolloClient({\r\n    connectToDevTools: process.browser,\r\n    ssrMode: !process.browser, // Disables forceFetch on the server (so queries are only run once)\r\n    link: ApolloLink.from([\r\n      stateLink,\r\n      new HttpLink({\r\n        uri: config.apiUrl,\r\n        opts: {\r\n          credentials: 'same-origin' // Additional fetch() options like `credentials` or `headers`\r\n        }\r\n      })\r\n    ]),\r\n    cache: cache.restore(initialState || {}),\r\n  })\r\n}\r\n\r\nexport default function initApollo (initialState) {\r\n  // Make sure to create a new client for every server-side request so that data\r\n  // isn't shared between connections (which would be bad)\r\n  if (!process.browser) {\r\n    return create(initialState)\r\n  }\r\n\r\n  // Reuse client on the client-side\r\n  if (!apolloClient) {\r\n    apolloClient = create(initialState)\r\n  }\r\n\r\n  return apolloClient\r\n}\r\n```\r\n\r\nThen I have a gql query in getCurrentView.js:\r\n```javascript\r\nimport gql from 'graphql-tag'\r\n\r\nexport default gql`\r\n  query getCurrentView {\r\n    currentView @client {\r\n      view\r\n    }\r\n  }\r\n```\r\n\r\nAnd then I have the component composed with withData (the same file as in the Next.js example), the http queries and the local query:\r\n```javascript\r\nimport { Component } from 'react'\r\nimport withData from '../../lib/withData'\r\n\r\nimport config from '../../config'\r\n\r\nimport { graphql, compose } from 'react-apollo'\r\nimport allProducts from '../../graphql/allProducts'\r\nimport getCategoryBySeoName from '../../graphql/getCategoryBySeoName'\r\nimport { getCurrentView } from '../../graphql'\r\n// [other imports cut...]\r\n\r\nclass Categoria extends Component {\r\n//...\r\n}\r\n\r\nexport default compose(\r\n  withData,\r\n  graphql(getCurrentView, {\r\n    name: 'currentView'\r\n  }),\r\n  graphql(allProducts, {\r\n    name: 'allProducts',\r\n    options: ({ url }) => ({ variables: { categorySeoName: url.query.categorySeoName, limit: config.itemsPerPage, offset: 0 } })\r\n  }),\r\n  graphql(getCategoryBySeoName, {\r\n    name: 'getCategoryBySeoName',\r\n    options: ({ url }) => ({ variables: { seoName: url.query.categorySeoName } })\r\n  })\r\n)(Categoria)\r\n\r\n```\r\n\r\nI receive the following error:\r\n```\r\nUnhandled (in react-apollo:Apollo(Apollo(Apollo(Categoria)))) Error: Network error: Cannot read property 'Query' of undefined\r\n    at new ApolloError (http://localhost:3001/_next/1517221068041/page/categoria.js:21154:28)\r\n    at ObservableQuery.module.exports.ObservableQuery.currentResult (http://localhost:3001/_next/1517221068041/page/categoria.js:20361:24)\r\n    at GraphQL.dataForChild (http://localhost:3001/_next/1517221068041/page/categoria.js:18856:62)\r\n    at GraphQL.render (http://localhost:3001/_next/1517221068041/page/categoria.js:18906:33)\r\n    at finishClassComponent (http://localhost:3001/_next/1517221068041/commons.js:7879:31)\r\n    at updateClassComponent (http://localhost:3001/_next/1517221068041/commons.js:7856:12)\r\n    at beginWork (http://localhost:3001/_next/1517221068041/commons.js:8231:16)\r\n    at performUnitOfWork (http://localhost:3001/_next/1517221068041/commons.js:10230:16)\r\n    at workLoop (http://localhost:3001/_next/1517221068041/commons.js:10294:26)\r\n    at HTMLUnknownElement.callCallback (http://localhost:3001/_next/1517221068041/commons.js:548:14)\r\n```\r\n\r\nThank you very much for your support.\r\nIf I can find a way to solve this issue I may post a PR for a \"with Apollo and apollo-link-state\" on Next.js.\r\n"},"comment":{"url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/comments/376704797","html_url":"https://github.com/apollographql/apollo-link-state/issues/185#issuecomment-376704797","issue_url":"https://api.github.com/repos/apollographql/apollo-link-state/issues/185","id":376704797,"user":{"login":"fbartho","id":209712,"avatar_url":"https://avatars2.githubusercontent.com/u/209712?v=4","gravatar_id":"","url":"https://api.github.com/users/fbartho","html_url":"https://github.com/fbartho","followers_url":"https://api.github.com/users/fbartho/followers","following_url":"https://api.github.com/users/fbartho/following{/other_user}","gists_url":"https://api.github.com/users/fbartho/gists{/gist_id}","starred_url":"https://api.github.com/users/fbartho/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fbartho/subscriptions","organizations_url":"https://api.github.com/users/fbartho/orgs","repos_url":"https://api.github.com/users/fbartho/repos","events_url":"https://api.github.com/users/fbartho/events{/privacy}","received_events_url":"https://api.github.com/users/fbartho/received_events","type":"User","site_admin":false},"created_at":"2018-03-27T23:08:52Z","updated_at":"2018-03-27T23:08:52Z","author_association":"COLLABORATOR","body":"@dav-is Reopening because I didn't understand :P"}}
{"actor":{"display_login":"fbartho"}}