Search code examples
reactjsreact-apolloapollo-clientexpress-graphql

Why graphQLErrors are always empty in react components?


I want to show some errors that comes from graphql server to user.

Have some component with callback that use some mutation

onSave() => {
    this.props.mutate({
        mutation: CHANGE_ORDER_MUTATION,
        variables: {
            ids,
        },
    }).catch((e) => {
        console.log(e.graphQLErrors) <--- e.graphQLErrors is always empty array = []
    })
}

While I'm able to see the graphQLErrors error with apollo-link-error link.

const errorLink = onError(({ graphQLErrors, networkError }) => { console.log(graphQLErrors) <--- errors from server });


Solution

  • Migration to apollo-server instead of express-graphql solve the problem.

    Or you can access errors by e.networkError.result.errors