next-with-apollo icon indicating copy to clipboard operation
next-with-apollo copied to clipboard

Type Error Using New Apollo

Open guilhermeccrz opened this issue 3 years ago • 2 comments

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'. Type 'ApolloClient<NormalizedCacheObject>' is missing the following properties from type 'ApolloClient': store, writeData, initQueryManager"

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>
      );
    },
  }
);

guilhermeccrz avatar Nov 25 '21 17:11 guilhermeccrz

Be sure to name your file with .tsx not .ts.

tiwari-ai-harsh avatar Apr 29 '22 10:04 tiwari-ai-harsh

Also can try this: https://github.com/TomDoesTech/NextJS-With-Apollo-Client-Tutorial

tiwari-ai-harsh avatar Apr 29 '22 10:04 tiwari-ai-harsh