-
Notifications
You must be signed in to change notification settings - Fork 79
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
WIP feat: apollo-client@2 → @apollo/client@3 #132
base: main
Are you sure you want to change the base?
Conversation
Changes work for my project over How to fix tests? :)
|
What's the progress on this issue, would like to upgrade my application to Apollo Client 3.0 |
@mvantoorn |
What's the status of this pull request? |
next-with-apollo works fine with Apollo Client 3.0. It's independent of apollo version. What's your problem with Apollo 3? Doesn't work? |
@chemicalkosek The current version (5.1.0) still imports from packages like |
Tips for getting it workI've successfully set up This is my import React from 'react';
import { ApolloProvider, ApolloClient } from '@apollo/client';
import NextApp, { AppProps } from 'next/app';
import { getApolloClient } from '../utils/apolloClient';
import withApollo from '@sotnikov/next-with-apollo';
import { getDataFromTree } from '@apollo/client/react/ssr';
type Props = AppProps & {
apollo: ApolloClient<{}>;
};
const App = ({ Component, pageProps, apollo }: Props) => (
<ApolloProvider client={apollo}>
<Component {...pageProps} />
</ApolloProvider>
);
App.getInitialProps = async (appContext: any) => {
const appProps = await NextApp.getInitialProps(appContext);
return { ...appProps };
};
export default withApollo(getApolloClient, { getDataFromTree })(App); ❗️
Importing from Another gotcha was getting "Loading..." instead of the rendered output from import React from "react";
import { gql, useQuery } from "@apollo/client";
const PRODUCTS_QUERY = gql`
query {
products {
id
name
}
}
`;
const IndexPage = () => {
const { loading, error, data } = useQuery(PRODUCTS_QUERY);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {JSON.stringify(error)}</p>;
return (
<ul>
{data.products.map((p) => (
<li key={p.id}>{p.name}</li>
))}
</ul>
);
};
export default IndexPage; The problem here is the condition With that, I got properly rendered SSR page. |
Hi @borekb , I'm really interested what you did in "import { getApolloClient } from '../utils/apolloClient';" I'm stuck and can't get withApollo to work, I'm stuck with Invalid hook call even tho I tried to reproduce what you mentioned in your post. I would really appreciate it ! This is my version of apolloClient:
Error that I get is : Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
@ilackovic Actually we've moved import React from 'react';
import { ApolloProvider, ApolloClient, HttpLink, InMemoryCache } from '@apollo/client';
import NextApp, { AppProps } from 'next/app';
import withApollo, { InitApolloOptions } from '@sotnikov/next-with-apollo';
import { getDataFromTree } from '@apollo/client/react/ssr';
type Props = AppProps & {
apollo: ApolloClient<{}>;
};
const App = ({ Component, pageProps, apollo }: Props) => (
<ApolloProvider client={apollo}>
<Component {...pageProps} />
</ApolloProvider>
);
App.getInitialProps = async (appContext: any) => {
const appProps = await NextApp.getInitialProps(appContext);
return { ...appProps };
};
export default withApollo(
({ initialState }: InitApolloOptions<any>): ApolloClient<any> => {
return new ApolloClient({
link: new HttpLink({
uri: 'http://localhost:3000/api/graphql',
}),
cache: new InMemoryCache().restore(initialState || {}),
});
},
{ getDataFromTree }
)(App); |
@borekb , Thank you for answering ! Sadly, this doesn't work for me, I just can't get SSR to work. I even created a new Next project and tried to reproduce your code exactly as you posted it, but no luck. Since I literally went ahead and copy pasted anything, I really don't understand what I'm missing if it works for you... I saw a lot of posts in the last few months where people have issues with SSR and Apollo... |
I use SSR and it works. |
You are right. I tweaked the example repo I created and I managed to make it work there. But, with the same configuration, same query, same package.json, it doesn't work in my main project... My only conclusion here is that something in my project is blocking SSR somehow. Thank you for your help ! |
Any plans to merge this PR? |
@Uniiq The PR still has some conflicts and it hasn't been updated since April. Personally I haven't had the time to try out Apollo 3 but I'll be happy to review a PR that adds support for it. |
@lfades is there any movement on this? The PR looks really good, and doesn't seem to conflict with the main branch. |
@dyyyl Yeah looks like it was updated. I'll try to review it soon and get it merged. In the meantime please remember that the package itself only uses Apollo to get TS types and for tests, so getting this PR merged doesn't change any actual functionality. The package should already work with the latest Apollo version. |
@lfades this is the error I get, after cleaning up the package.json and only using "@apollo/client" with yours It's dev mode, so I am assuming that you expect apollo-client being installed as peerDependencies. However like I said, when you clean up the obsolete packages you'll face these errors. Update: "@sotnikov/next-with-apollo" works 🎉 |
works also for me on "@apollo/client": "^3.2.9" - any plans on merging that soon? |
@lfades please merge, this will be helpful ! |
There there is a |
"@apollo/client": "^3.0.0-beta.43", | ||
"@apollo/react-components": "^4.0.0-beta.1", | ||
"@apollo/react-ssr": "^4.0.0-beta.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we switch to the latest versions?
Any plans to merge this? Seems to be breaking for me w/r/t this issue: apollographql/apollo-client#9122 |
Co-authored-by: Luis Alvarez D. <[email protected]>
Move from apollo-client@2 to @apollo/client@3 by manual:
https://www.apollographql.com/docs/react/v3.0-beta/migrating/apollo-client-3-migration/