{"action":"created","issue":{"url":"https://api.github.com/repos/apollostack/react-apollo/issues/155","repository_url":"https://api.github.com/repos/apollostack/react-apollo","labels_url":"https://api.github.com/repos/apollostack/react-apollo/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/apollostack/react-apollo/issues/155/comments","events_url":"https://api.github.com/repos/apollostack/react-apollo/issues/155/events","html_url":"https://github.com/apollostack/react-apollo/issues/155","id":172129374,"number":155,"title":"SSR error \"cannot read property 'store' of undefined\" ","user":{"login":"rewop","id":2427222,"avatar_url":"https://avatars.githubusercontent.com/u/2427222?v=3","gravatar_id":"","url":"https://api.github.com/users/rewop","html_url":"https://github.com/rewop","followers_url":"https://api.github.com/users/rewop/followers","following_url":"https://api.github.com/users/rewop/following{/other_user}","gists_url":"https://api.github.com/users/rewop/gists{/gist_id}","starred_url":"https://api.github.com/users/rewop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rewop/subscriptions","organizations_url":"https://api.github.com/users/rewop/orgs","repos_url":"https://api.github.com/users/rewop/repos","events_url":"https://api.github.com/users/rewop/events{/privacy}","received_events_url":"https://api.github.com/users/rewop/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/apollostack/react-apollo/labels/@next","name":"@next","color":"006b75"},{"url":"https://api.github.com/repos/apollostack/react-apollo/labels/bug","name":"bug","color":"ee0701"}],"state":"closed","locked":false,"assignee":{"login":"jbaxleyiii","id":4967600,"avatar_url":"https://avatars.githubusercontent.com/u/4967600?v=3","gravatar_id":"","url":"https://api.github.com/users/jbaxleyiii","html_url":"https://github.com/jbaxleyiii","followers_url":"https://api.github.com/users/jbaxleyiii/followers","following_url":"https://api.github.com/users/jbaxleyiii/following{/other_user}","gists_url":"https://api.github.com/users/jbaxleyiii/gists{/gist_id}","starred_url":"https://api.github.com/users/jbaxleyiii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbaxleyiii/subscriptions","organizations_url":"https://api.github.com/users/jbaxleyiii/orgs","repos_url":"https://api.github.com/users/jbaxleyiii/repos","events_url":"https://api.github.com/users/jbaxleyiii/events{/privacy}","received_events_url":"https://api.github.com/users/jbaxleyiii/received_events","type":"User","site_admin":false},"assignees":[{"login":"jbaxleyiii","id":4967600,"avatar_url":"https://avatars.githubusercontent.com/u/4967600?v=3","gravatar_id":"","url":"https://api.github.com/users/jbaxleyiii","html_url":"https://github.com/jbaxleyiii","followers_url":"https://api.github.com/users/jbaxleyiii/followers","following_url":"https://api.github.com/users/jbaxleyiii/following{/other_user}","gists_url":"https://api.github.com/users/jbaxleyiii/gists{/gist_id}","starred_url":"https://api.github.com/users/jbaxleyiii/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbaxleyiii/subscriptions","organizations_url":"https://api.github.com/users/jbaxleyiii/orgs","repos_url":"https://api.github.com/users/jbaxleyiii/repos","events_url":"https://api.github.com/users/jbaxleyiii/events{/privacy}","received_events_url":"https://api.github.com/users/jbaxleyiii/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2016-08-19T13:18:21Z","updated_at":"2016-08-23T07:24:31Z","closed_at":"2016-08-23T01:45:59Z","body":"Hi, \r\n\r\nI am using `react-apollo` to perform server side rendering and I am receiving the error\r\n\r\n```\r\nTypeError: Cannot read property 'store' of undefined\r\n   at new GraphQL (graphql.tsx:255:14)\r\n   at getQueriesFromTree (server.ts:48:11)\r\n   at getDataFromTree (server.ts:82:3)\r\n   at server.ts:89:60\r\n   at Array.map (native)\r\n   at server.ts:89:46\r\n   ...\r\n```\r\n\r\nThis error is only present server side, and not client side. When I disable SSR client side works perfectly.\r\n\r\nI looked into the code and I found out that the error is thrown from the function `getDataFromTree` in the `server.ts` file. \r\n\r\nBasically when the function `getQueriesFromTree` tries to get the queries from the tree, when encounter the `GraphQL` component it throws the error.\r\n\r\nI see that the `GraphQL` component is created by the decorator `graphql` that handles the call to the serevr. It looks like that when the component is initialised, it cannot find the client neither from the context nor from the props (despite I have the root wrapped in `ApolloProvider`). \r\n\r\nAlso I found another small bug. When this kind of situation arises, a warning should be shown, instead of a uncaught exception. The problem is that [this line](https://github.com/apollostack/react-apollo/blob/master/src/graphql.tsx#L255) should be after the invariant check against the client prop in the line soon after.\r\n\r\nI haven't managed to find out yet why the client is not in the context. The following is how my application is set up.\r\n\r\nIn my application I am using `react-router`, `redux` and `react-apollo`. My root component looks like this:\r\n\r\n```jsx\r\nconst Root = ({\r\n    history: _history,\r\n    routes,\r\n    routerState,\r\n    client,\r\n    store\r\n}) => {\r\n    let component;\r\n    if (__SERVER__)\r\n        component = <RouterContext {...routerState} />;\r\n    else\r\n        component = <Router history={_history} routes={routes} render={scrollHandlingMiddleware} />;\r\n\r\n    return (\r\n        <ApolloProvider client={client} store={store}>\r\n            {component}\r\n        </ApolloProvider>\r\n    );\r\n};\r\n```\r\n\r\nMy client is created with this function, and passed to the `Root` component:\r\n\r\n```javascript\r\nimport ApolloClient, { createNetworkInterface } from \"apollo-client\";\r\n\r\nexport default () => {\r\n    const networkInterface = createNetworkInterface(process.env.GRAPH_URL);\r\n    return new ApolloClient({\r\n        networkInterface,\r\n        ssrMode: __SERVER__\r\n    });\r\n};\r\n```\r\n\r\nThe only container I am using with `react-apollo` at the moment looks like this:\r\n\r\n```jsx\r\nimport React, { PropTypes } from \"react\";\r\nimport MyComponent from \"../components/MyComponent\";\r\nimport { graphql } from \"react-apollo\";\r\nimport gql from \"graphql-tag\";\r\n\r\nconst MY_QUERY = gql`\r\n     ...\r\n`;\r\n\r\nconst dataToProps = ({ data }) => {\r\n    return {\r\n        ...\r\n    };\r\n};\r\n\r\nconst withData = graphql(MY_QUERY, {\r\n    props: dataToProps\r\n});\r\n\r\nconst MyContainer = ({ error, loading, ...rest }) => {\r\n    if (error) return <span />;\r\n    if (loading) return <h2>Loading</h2>;\r\n    return <MyComponent ...rest />;\r\n};\r\n\r\nMyContainer.propTypes = {\r\n    loading: PropTypes.bool,\r\n    error: PropTypes.bool,\r\n    ...\r\n};\r\n\r\nexport default withData(MyContainer);\r\n\r\n```\r\n \r\nAny idea what the problem could be? Am I doing something wrong?\r\n\r\nI am willing to contribute on this one if we find the problem."},"comment":{"url":"https://api.github.com/repos/apollostack/react-apollo/issues/comments/241648973","html_url":"https://github.com/apollostack/react-apollo/issues/155#issuecomment-241648973","issue_url":"https://api.github.com/repos/apollostack/react-apollo/issues/155","id":241648973,"user":{"login":"stubailo","id":448783,"avatar_url":"https://avatars.githubusercontent.com/u/448783?v=3","gravatar_id":"","url":"https://api.github.com/users/stubailo","html_url":"https://github.com/stubailo","followers_url":"https://api.github.com/users/stubailo/followers","following_url":"https://api.github.com/users/stubailo/following{/other_user}","gists_url":"https://api.github.com/users/stubailo/gists{/gist_id}","starred_url":"https://api.github.com/users/stubailo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stubailo/subscriptions","organizations_url":"https://api.github.com/users/stubailo/orgs","repos_url":"https://api.github.com/users/stubailo/repos","events_url":"https://api.github.com/users/stubailo/events{/privacy}","received_events_url":"https://api.github.com/users/stubailo/received_events","type":"User","site_admin":false},"created_at":"2016-08-23T07:24:31Z","updated_at":"2016-08-23T07:24:31Z","body":"Also, another heads up, I just split up the API server and the React frontend into separate repos, since we want to share the server between all of the example frontends."}}
{"actor":{"display_login":"stubailo"}}