apollographql / apollo-link

:link: Interface for fetching and modifying control flow of GraphQL requests
https://www.apollographql.com/docs/link/
MIT License
1.44k stars 344 forks source link

graphQLErrors returns an empty array for mutations onError #1285

Open cmnstmntmn opened 4 years ago

cmnstmntmn commented 4 years ago

i'm having this link

const errorLink = onError(
  ({ graphQLErrors, networkError, operation, forward }) => {
    if (graphQLErrors) {
      for (let err of graphQLErrors) {
        let { message, locations, path } = err;

        console.log(
          `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
        );

        switch (message) {
          case "Not Authorized":
            notAuthHandler();
            break;
          default:
            console.info(message);
        }
      }
    }
    if (networkError) {
      console.log(`[Network error]: ${networkError}`);
    }

    return forward(operation);
  }
);

in here, i can both graphQLErrors and networkError, but when trying to get these errors after a mutation, at the component level, only networkError is returned while graphQLErrors is an empty array.