Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Example for Next.js #295

Closed
sedubois opened this issue Oct 29, 2016 · 10 comments
Closed

Example for Next.js #295

sedubois opened this issue Oct 29, 2016 · 10 comments

Comments

@sedubois
Copy link

sedubois commented Oct 29, 2016

The new next.js framework looks quite promising, it would be awesome to have an example of integration with Apollo 😃 Especially as it does not (currently) expose a root-level routing component. (please close issue if you think it should be figured out on next.js side...)

@jbaxleyiii
Copy link
Contributor

I'd love that! Been wanting to try out next.js!

@jbaxleyiii
Copy link
Contributor

@sedubois do you have any links or any idea what would need to be added?

@sedubois
Copy link
Author

sedubois commented Oct 29, 2016

@jbaxleyiii Well, this works but I guess it creates a separate Apollo store per page...

https://github.com/sedubois/realate

@jbaxleyiii
Copy link
Contributor

Does that work with SSR out of the box?

@sedubois
Copy link
Author

@jbaxleyiii yes, at least that is the claim

@stubailo
Copy link
Contributor

Does Next have an example with Redux? I imagine Apollo would be initialized and provided in exactly the same way.

@sedubois
Copy link
Author

Indeed, here it is: https://github.com/zeit/next.js/wiki/Redux-example

The Redux client-side trick is:

if (!window.store) {
  window.store = createStore(reducer, initialState, middleware);
}

So I guess the only choice is to manually configure Apollo with such an external store: <ApolloProvider store={store} client={client}>.

I propose to close this and any next.js Apollo example could be added in their wiki.

@sedubois
Copy link
Author

The example is being developed here, and it's not trivial:

vercel/next.js#106

@stubailo
Copy link
Contributor

Cool, let me know if I can help at all, other than the SSR bug. But yeah, attaching the store as a global variable could work I suppose. Just need to make sure it doesn't end up setting a global variable on the server during SSR!

@sedubois
Copy link
Author

Thanks 😊 discussion continues in that other thread.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants