[Network error]: TypeError: forward is not a function

See original GitHub issue

I tried to use Error Link as in document’s example

const link = onError(({ graphQLErrors, networkError }) => {
  if (graphQLErrors)
    graphQLErrors.map(({ message, locations, path }) =>
      console.log(
        `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
      )
    )
  if (networkError) console.log(`[Network error]: ${networkError}`)
})
const apolloClient = new ApolloClient({
  uri: '/graphql',
  cache: new InMemoryCache(),
  link: ApolloLink.from([link])
})

but got the following in the console.

[Network error]: TypeError: forward is not a function

After some try, I found adding HttpLink would work

const apolloClient = new ApolloClient({
  cache: new InMemoryCache(),
  link: ApolloLink.from([link, new HttpLink({uri: '/graphql'})])
})

Probably worth mention it in the doc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:31
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
Marcohjcommented, Aug 25, 2020

Same issue here. The example in the Docs seems “unfinished” in how ApolloClient 3 expects us to handle onError.


Seems like you need to do:

const cache = new InMemoryCache()

const errorLink = onError(({ graphQLErrors, operation, forward }) => {
  if (graphQLErrors) {
    // Handle Errors
  }

  forward(operation)
})

const httpLink = new HttpLink({
  uri: URI_PATH
})

export const apolloClient = new ApolloClient({
  cache,
  link: from([errorLink, httpLink])
})
6reactions
atstoyanovcommented, Oct 5, 2020

It seems that the errorLink must not be the first link in the chain. I’ve moved the error link between my authentication and http link and the error disappeared.

  return new ApolloClient({
    link: from([authLink, errorLink, httpLink]),
    cache: new InMemoryCache(),
  });

Is this behavior intentional or is it a bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Querying graphiql leads Apollo error forward is not a function
When executing the above mentioned query without the link variable that handles the error, I receive a 400 Bad Request from the server...
Read more >
Error Link - Apollo GraphQL Docs
A function that calls the next link down the chain. Calling return forward(operation) in your onError callback retries the operation, returning a new...
Read more >
apollo-link.forward JavaScript and Node.js code examples
Best JavaScript code snippets using apollo-link.forward(Showing top 13 results out ... function createClient(headers, token, initialState) { let accessToken ...
Read more >
TypeError: forward is not a function @apollo/client@3.0.0-beta ...
Expected Behavior When using onError() from @apollo/link-error we do not get an error upon GraphQL request. Actual Behavior.
Read more >
How to use the apollo-link.ApolloLink function in apollo-link
{ graphqlErrors, networkError }); }); const authLink = new ApolloLink((operation, forward) => { const token = localStorage.getItem('AUTH_TOKEN'); operation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found