javascriptapollo-client

Getting "reobserveAsConcast is not a function" error after updating to Apollo Client 3.12.0


I recently updated my Apollo Client version from 3.5.8 to 3.12.0, and now I'm encountering an error when using the useLazyQuery hook. The error states:

observable.reobserveAsConcast is not a function

This error appears to be triggered within the executeQuery function, which is used internally by useLazyQuery. Here's is the code: https://github.com/apollographql/apollo-client/blob/6ffb5a34a39657568db7f4e42ed60d8679cb817f/src/react/hooks/useLazyQuery.ts#L222

I'm using useLazyQuery like this:

const [
    fetchData,
    { data, loading: isLoading, error: fetchError },
] = useLazyQuery(SOME_QUERY, {
    fetchPolicy: "no-cache",
});

The error occurs whenever I trigger the fetchData function.

I also updated react from version 17 to 18

Are there any changes in how useLazyQuery or ObservableQuery should be used in Apollo Client 3.12.0?

I would greatly appreciate any guidance or insights into resolving this issue. Thank you!


Solution

  • Are there any changes in how useLazyQuery or ObservableQuery should be used in Apollo Client 3.12.0?

    No, there are no such changes, and no changes that should cause this behaviour.

    If I were to guess I would say that you might be combining a modern version of the hook with an outdated instance of ApolloClient here - check your node_modules folder and maybe yarn why @apollo/client/npm ls @apollo/client if by any chance you have more than one version of Apollo Client installed.