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.
Breaking on exception, I get this in my bundle:
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
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
});
Most helpful comment
I am getting this error when a
networkError
happens withapollo-link-context
,apollo-link-error
, andapollo-link-http
: