Apollo-link: TypeError: forward is not a function @apollo/[email protected], @apollo/[email protected]

Created on 11 Feb 2020  ·  3Comments  ·  Source: apollographql/apollo-link

Expected Behavior
When using onError() from @apollo/link-error we do not get an error upon GraphQL request.

Actual Behavior

Deps:

"dependencies": {
    "@apollo/client": "^3.0.0-beta.34",
    "@apollo/link-error": "2.0.0-beta.3",

Setup:

import {
  ApolloClient,
  ApolloProvider,
  InMemoryCache,
} from '@apollo/client';
import { onError } from '@apollo/link-error';

const apolloClient = new ApolloClient({
  uri: '/graphql',
  // rehydration using the initial state
  cache: new InMemoryCache().restore(apolloState),

  link: onError(({ graphQLErrors, networkError }) => {
    console.log(graphQLErrors, networkError);
  }),
});

Upon interacting with a component which makes a GraphQL request, unfortunately this is all I get.
Screen Shot 2020-02-11 at 10 28 41 AM
Breaking on exception, I get this in my bundle:
Screen Shot 2020-02-11 at 10 36 34 AM
Screen Shot 2020-02-11 at 10 38 48 AM

A _simple_ reproduction
I tried to set up a Codesanbox, but it fails for AC 3.0 with a cryptic dependency problem:
https://codesandbox.io/s/apolloclient-3-local-state-management-before-reactive-variables-nr1kg

Most helpful comment

I am getting this error when a networkError happens with apollo-link-context, apollo-link-error, and apollo-link-http:

import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { onError } from 'apollo-link-error'
import { InMemoryCache } from 'apollo-cache-inmemory'

const httpLink = new HttpLink({
  uri: // my api URI
})

const authLink = setContext((_, { headers }) => {
  // my authorization stuff
})

const errorLink = onError(({ graphQLErrors, networkError }) => {
  // my error handling logic
})

const apolloClient = new ApolloClient({
  link: authLink.concat(errorLink, httpLink),
  cache: new InMemoryCache()
})

All 3 comments

I've encountered the same issue when upgrading to beta.

Seems like it goes away if a HttpLink is included instead of the direct uri usage.
So maybe the lib is incorrectly expecting to always have subsequent items in the chain and a forward function present?

I am getting this error when a networkError happens with apollo-link-context, apollo-link-error, and apollo-link-http:

import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { setContext } from 'apollo-link-context'
import { onError } from 'apollo-link-error'
import { InMemoryCache } from 'apollo-cache-inmemory'

const httpLink = new HttpLink({
  uri: // my api URI
})

const authLink = setContext((_, { headers }) => {
  // my authorization stuff
})

const errorLink = onError(({ graphQLErrors, networkError }) => {
  // my error handling logic
})

const apolloClient = new ApolloClient({
  link: authLink.concat(errorLink, httpLink),
  cache: new InMemoryCache()
})

[edited] Any update on this? I am on RC version and still get the same error without HTTPLINK

        "@apollo/client": "^3.0.0-rc.10",
        "@apollo/link-batch-http": "^2.0.0-beta.3",
        "@apollo/link-context": "^2.0.0-beta.3",
        "@apollo/link-error": "^2.0.0-beta.3",
        "@apollo/link-retry": "^2.0.0-beta.3",

But to unblock, this works for me

    const link = from([ authLink, logoutLink,  new HttpLink({ uri }) ]);
    return new ApolloClient({
        name: APOLLO_CLIENT_NAME,
        version: config.appVersion,
        connectToDevTools: true,
        link,
        cache
    });
Was this page helpful?
0 / 5 - 0 ratings