Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

TypeError: forward is not a function @apollo/client@3.0.0-beta.24, @apollo/link-error@2.0.0-beta.3 #1246

Open
bwhitty opened this issue Feb 11, 2020 · 3 comments

Comments

@bwhitty
Copy link

bwhitty commented Feb 11, 2020

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

@Klemensas
Copy link

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?

@Aposhian
Copy link

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()
})

@aonamrata
Copy link

aonamrata commented Jul 9, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants