Skip to content

Commit

Permalink
Bug Fix: Prevent Apollo Client GraphQL errors from crashing SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
gufranmirza committed Jan 26, 2019
1 parent db78fa2 commit 5eef7f5
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions libraries/withData.js
Expand Up @@ -41,7 +41,7 @@ export default (
};

static defaultProps = {
accessToken: null
accessToken: ''
};

constructor(props: Props) {
Expand All @@ -67,17 +67,24 @@ export default (
};

if (!process.browser) {
const client = apolloClient(headers || {}, token || '', {});
const client = apolloClient(headers || {}, token || '', {}, ctx);
const store = reduxStore();

const app = (
<ApolloProvider client={client}>
<ReduxProvider store={store}>
<Component {...props} />
</ReduxProvider>
</ApolloProvider>
);
await getDataFromTree(app);
try {
const app = (
<ApolloProvider client={client}>
<ReduxProvider store={store}>
<Component {...props} />
</ReduxProvider>
</ApolloProvider>
);
await getDataFromTree(app);
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// https://github.com/apollographql/react-apollo/issues/406
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
}

apolloState = client.cache.extract();
serverState = store.getState();
Expand Down

0 comments on commit 5eef7f5

Please sign in to comment.