diff --git a/demo-projects/meetup/site/lib/initApollo.js b/demo-projects/meetup/site/lib/initApollo.js index fd9c8d3724f..1457c7a3a5d 100644 --- a/demo-projects/meetup/site/lib/initApollo.js +++ b/demo-projects/meetup/site/lib/initApollo.js @@ -8,7 +8,7 @@ const { let apolloClient = null; -function create(initialState) { +function create(initialState, req) { // Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient return new ApolloClient({ connectToDevTools: process.browser, @@ -18,16 +18,17 @@ function create(initialState) { credentials: 'same-origin', // Additional fetch() options like `credentials` or `headers` // Use fetch() polyfill on the server fetch: !process.browser && fetch, + headers: req && req.headers, }), cache: new InMemoryCache().restore(initialState || {}), }); } -export default function initApollo(initialState) { +export default function initApollo(initialState, req) { // Make sure to create a new client for every server-side request so that data // isn't shared between connections (which would be bad) if (!process.browser) { - return create(initialState); + return create(initialState, req); } // Reuse client on the client-side diff --git a/demo-projects/meetup/site/lib/withApollo.js b/demo-projects/meetup/site/lib/withApollo.js index 694759cc0ac..826b7dbc42c 100644 --- a/demo-projects/meetup/site/lib/withApollo.js +++ b/demo-projects/meetup/site/lib/withApollo.js @@ -13,12 +13,12 @@ export default App => { const { Component, router, - ctx: { res }, + ctx: { res, req }, } = ctx; // Run all GraphQL queries in the component tree // and extract the resulting data - const apollo = initApollo(); + const apollo = initApollo(null, req); ctx.ctx.apolloClient = apollo;