Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
apolloState={apolloState}
apollo={apollo}
/>
);
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
if (process.env.NODE_ENV !== 'production') {
// tslint:disable-next-line no-console This is a necessary debugging log
console.error('GraphQL error occurred [getDataFromTree]', error);
}
}
if (ssrMode) {
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind();
}
apolloState.data = apollo.cache.extract();
}
// To avoid calling initApollo() twice in the server we send the Apollo Client as a prop
// to the component, otherwise the component would have to call initApollo() again but this
// time without the context, once that happens the following code will make sure we send
// the prop as `null` to the browser
(apollo as any).toJSON = () => {
return null;
};
return {
...appProps,
apolloState,
{...appProps}
apolloClient={apollo}
headers={headers}
serverContext={ctx}
/>
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-query-data-error
console.error('Error while running `getDataFromTree`', error)
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
// Extract query data from the Apollo store
apolloState = apollo.cache.extract()
}
return {
...appProps,
apolloState,
headers
}
}
router={router}
apolloState={apolloState}
apolloClient={apollo}
/>
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
console.error('Error while running `getDataFromTree`', error)
}
if (!process.browser) {
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
}
// Extract query data from the Apollo store
apolloState.data = apollo.cache.extract()
return {
...appProps,
apolloState
}
} catch (ex) {
console.error(ex)
}
}
}}
/>,
);
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-query-data-error
console.error(
'Error while running `getDataFromTree`',
error,
);
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind();
}
}
// Extract query data from the Apollo store
const apolloState = ctx.apolloClient.cache.extract();
return {
...pageProps,
apolloState,
ssrComplete: true,
};
};
}
try {
const { getDataFromTree } = await import('@apollo/react-ssr')
await getDataFromTree(
)
} catch (error) {
// Prevent crash from GraphQL errors.
console.error(error)
}
Head.rewind()
props.apolloCache = apolloClient.cache.extract()
}
return props
}
{...appProps}
Component={Component}
router={router}
apolloClient={apollo}
/>
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// https://www.apollographql.com/docs/react/api/react-apollo.html#graphql-query-data-error
console.error('Error while running `getDataFromTree`', error)
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
}
// Extract query data from the Apollo store
const apolloState = apollo.cache.extract()
return {
...appProps,
apolloState
}
}
if (error.networkError.response.status === 401 && res) {
// eslint-disable-next-line no-console
console.log("Received 401 error from the GraphQL API due to invalid or expired authentication credentials. Triggering token refresh via redirect flow");
res.writeHead(302, { Location: "/signin" });
res.end();
return {};
}
logger.error(`Unable to access the GraphQL API. Is it running and accessible at ${serverRuntimeConfig.graphqlUrl} from the Storefront UI server?`);
} else {
logger.error("Error while running `getDataFromTree`:", error);
}
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind();
// Extract query data from the Apollo's store
apolloState.data = apollo.cache.extract();
} else {
apolloState.data = {};
}
return {
...wrappedComponentProps,
apolloState,
accessToken: user && user.accessToken
};
}
const url = {query: ctx.query, pathname: ctx.pathname}
try {
// Run all GraphQL queries
await getDataFromTree(
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
// Extract query data from the Apollo store
serverState = {
apollo: {
data: apollo.cache.extract()
}
}
}
return {
serverState,
...composedInitialProps
}
}
{
router: {
asPath: ctx.asPath,
pathname: ctx.pathname,
query: ctx.query
}
}
)
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
}
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind()
// Extract query data from the Apollo store
stateApollo = {
apollo: {
data: apollo.cache.extract()
}
}
}
return {
stateApollo,
...composedInitialProps
}
}
pathname: ctx.pathname,
query: ctx.query
},
client: apollo
}
);
} catch (error) {
// Prevent Apollo Client GraphQL errors from crashing SSR.
// Handle them in components via the data.error prop:
// http://dev.apollodata.com/react/api-queries.html#graphql-query-data-error
}
if (!process.browser) {
// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind();
}
// Extract query data from the Apollo store
serverState = {
apollo: {
data: apollo.cache.extract()
}
};
return {
serverState,
...composedInitialProps
};
}