-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSR: Absolute URI for HttpLink handling? #188
Comments
Sorry, I missed this issue! When your Next.js server is also your GraphQL server, you can get around a network request completely by using a Schema link. You can see an example of that here: https://github.com/apollographql/apollo-client-nextjs/pull/36/files |
Hmm, that's an interesting problem. Can you maybe work with a top-level If we were to allow |
Top-level await usually gets troublesome in one way or another, I tend to avoid it, will give that a try as well. |
I created an issue in apollographql/federation#2942 just to try and get some feedback. I think what happens is that even with the I believe this is where the error in So I'm left with an issue here where I can't properly build the schema. |
I think the problem might be your That said, I don't believe |
As for function ParentWrapper({children}){
const [promise] = useState(clientFactory)
return <Suspense><ChildWrapper promise={promise}>{children}</ChildWrapper></Suspense>
}
function ChildWrapper({promise, children}){
const makeClient = use(promise)
return <ApolloNextAppProvider makeClient={makeClient}>{children}</ApolloNextAppProvider>
} We can't do that on a library level since it would wrap all our user's applications into an additional suspense boundary and that changes general UX, so it the developer needs to be very aware of that. |
I'll try removing the |
Hmm, would it matter if the factory is called again if I move the |
Then all your SSR-rendered requests share one instance of ApolloClient, potentially leaking sensitive data between requests, which I would really not recommend. |
Ah right this is the client instance, would be a different matter with a server instance right? |
That might be a misconception: Even though they are called "Client" Components, they will still run on the server for SSR on the first request of a user session. |
Yes, I meant that it's supposed to be a client-level instance because of And now that I think about it, wouldn't that mean the |
Yes, the All we are talking about in this issue pretty much only has relevance in that "first render on the server" - that's why I'm saying you shouldn't use a global variable for it. |
Tried the |
Ah yes I remember now, I knew I saw it somewhere, but I already put the |
The SSR part is broken indeed, the HTML of the SSR part (the first request that should be using the |
And I realized we went out of the scope of the original issue, do you want me to close this one and create a new one? |
@luchillo17 Yes please open a new issue - it's hard to keep track otherwise :) |
TLDR to avoid having to define an absolute URL ideally we use |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
Is this the only way to handle the absolute URL requirement for SSR?:
It seems to me like the only other way is with ENV variables based on environment, for example in development
HOST
grabslocalhost:4200
but in production, the hostname (either IP or DNS name) should be known by the CI pipeline to embed in the env variables, such a pain for such a simple need...The text was updated successfully, but these errors were encountered: