question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

with-apollo & with-apollo-auth

See original GitHub issue

with-apollo & with-apollo-auth example - request

Hey!

So we’re using Next.js with Apollo & are updating our app with the new example in with-apollo[-auth] & want to be able to use it in a default on + opt-out way rather than default off + opt-in way.

Is your feature request related to a problem? Please describe.

Currently, the examples are all in an opt-in mode - meaning if you need apollo, you will need to wrap your page component with withApollo explicitly. Similarly for the with-apollo-auth example, the pages add their getInitialProps for each page that needs to do something with user context.

Describe the solution you’d like

In our case, a lot more of the pages will need apollo + auth rather than not - eg maybe just 2 pages will not need auth and all other pages will; and almost ALL pages will need apollo. So we’re looking for a way to go back to the _app wrapping example but we’re unable to use the current withApollo implementation with _app.

Describe alternatives you’ve considered

In order to use the same example with _app, we tried changing the return pageProps in all places to { pageProps }, but we’re getting a bunch of errors regarding circular structure in JSON. Looks like App does get passed the same AppTree component we’re using but could not find any documentation regarding this AppTree and slightly stuck here.

Any help would be appreciated. Thanks 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
huv1kcommented, Sep 10, 2019

Hey @rheaditi, you can check old examples in the GitHub history. We changed this example to reflect our prioritization of automatic prerendering.

People were blindly copying this example without knowing of its downsides. This reflected that all pages were not automatically exported and getInitialProps was executed even that page was static. This resulted in bad use practice, which is not our intention.

1reaction
huv1kcommented, Sep 17, 2019

Hey @rheaditi, yes for questions we have spectrum, so please ask your questions there next time. I will close this issue because it’s not how we want to examples looks like. Regarding your questions:

  1. You can use HoC component for auth, this component could have your Layout for these pages.
  2. Yes, if you add top-level getInitialProps in your page/app your pages lose static option until we introduce prerendering during build time.
Read more comments on GitHub >

github_iconTop Results From Across the Web

with-apollo-auth example not working #7418 - vercel/next.js
I implemented the with-apollo-auth example. See this repo. Every query is now Server Side Rendered using getDataFromTree , but... not one query.
Read more >
HOC - Apollo GraphQL Docs
withApollo (component) ... An enhancer that provides direct access to your ApolloClient instance. This is useful if you want to do custom logic...
Read more >
Nexjs with apollo auth, cannot read property 'query' of ...
My API does not work with json web tokens but I've defined the ApolloProvider correctly with cookies... You can check the complete code...
Read more >
React Newsletter #174
next-with-apollo-auth. A demonstration and starting point for applications using Next.js + Apollo GraphQL (hooks) + Prisma / GraphQL Yoga + JWT for ...
Read more >
ReasonReact login/authentication token example projects?
... and React/Next https://github.com/zeit/next.js/tree/canary/examples/with-apollo-auth or https://github.com/iaincollins/nextjs-starter, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found