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

apollo-link-error: graphQLErrors param is always undefined #422

Open
tim-soft opened this issue Jan 19, 2018 · 4 comments
Open

apollo-link-error: graphQLErrors param is always undefined #422

tim-soft opened this issue Jan 19, 2018 · 4 comments
Labels

Comments

@tim-soft
Copy link

tim-soft commented Jan 19, 2018

Intended outcome: Logging graphQLError messages to the console

[edit] It seems that on specifically [Network error]: Error: 400 (Bad Request) I don't receive the graphQLErrors but in other cases I do get the expected errors.

Error messages returned from failed queries never seem to make it to onError() as graphQLErrors is always undefined, but I'm always given a networkError. I can find the failed request with the response error messages in chrome's network tab. Am I missing something?

// Log errors
const errorLink = 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}`);
});

// Combine all links
const link = split(
  // split based on operation type: subscription or query/mutation
  ({ query }) => {
    const { kind, operation } = getMainDefinition(query);
    return kind === 'OperationDefinition' && operation === 'subscription';
  },

  // Subscriptions Link
  from([
    // Log Apollo operations in development
    ...(__DEV__ ? [apolloLogger] : []),

    // Handle subscriptions, log errors in dev
    ...(__DEV__ ? [errorLink.concat(subscriptionsLink)] : [subscriptionsLink]),
  ]),


  // Uploads/http Link
  from([
    // Log Apollo operations in development
    ...(__DEV__ ? [apolloLogger] : []),

    // Handle http/file uploads, log errors in dev
    ...(__DEV__ ? [errorLink.concat(uploadLink)] : [uploadLink]),
  ]),
);
@goldo
Copy link

goldo commented Jan 19, 2018

same probleme here. We would like to have a global onError function.
Currently we are passing onError function to every subscribeToMore function:

this.unsubscribe = data.subscribeToMore({
        document: ...,
        variables: {...}       
        updateQuery: (previous, { subscriptionData }) => {
          ...
        },
        onError: err => {
          console.log({ err })
        },
      })

@tim-soft
Copy link
Author

tim-soft commented Jan 19, 2018

@goldo exactly, that pattern doesn't scale well when you really just want to log everything, hence the error link!

What I find confusing about the docs is this code:

const withDataAndErrors = graphql(MY_MIXED_QUERY, {
  options: {
    errorPolicy: 'all'
  }
});

Does the error policy on a per-query basis somehow impact how onError() gets it's messages? Or maybe there are some new params to GraphQL-Tools/Apollo Server to enable error logging?

@evans evans added the bug label Feb 14, 2018
@dejayc
Copy link

dejayc commented Feb 23, 2018

@tim-soft is it possible the fetch library that you're using is treating HTTP 400 status as a network error? I've come across a few fetch modules like that.

@pragyandas
Copy link

Any progress on this ?

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

No branches or pull requests

5 participants