next-with-apollo
next-with-apollo copied to clipboard
Type Error Using New Apollo
The code above works when run dev, but when try to build, types are incorrect right in the () => {, what should i do?
"Argument of type '() => ApolloClient<NormalizedCacheObject>' is not assignable to parameter of type 'InitApolloClient
import withApollo from "next-with-apollo";
import { ApolloClient, InMemoryCache, ApolloProvider } from "@apollo/client";
const cache = new InMemoryCache();
export default withApollo(
() => {
return new ApolloClient({
uri: process.env.API_URL,
cache: cache,
name: "react-web-client",
version: "1.3",
queryDeduplication: false,
defaultOptions: {
watchQuery: {
fetchPolicy: "cache-and-network",
},
},
});
},
{
render: ({ Page, props }) => {
if (process.env.NODE_ENV === "test") {
return <Page />;
}
return (
<ApolloProvider client={props.apollo}>
<Page />
</ApolloProvider>
);
},
}
);
Be sure to name your file with .tsx not .ts.
Also can try this: https://github.com/TomDoesTech/NextJS-With-Apollo-Client-Tutorial