Skip to content

graphql-client throws Error instance instead of ApolloError instance. #1194

@lucasconstantino

Description

@lucasconstantino

I'm experiencing a slight breaking change from 0.5.10 to 0.5.26. Basically, errors thrown from graphql-client are instances of ApolloError at the first, but not at the later.

Here goes a code to reproduce this issue:

import React, { Component } from 'react'
import { ApolloError } from 'apollo-client/errors/ApolloError'
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'

class MyContainer extends Component {
  save () {
    this.props.mutate()
      .catch(error => {
        if (error instanceof ApolloError) {
          // This works in 0.5.10
          // This does not work in 0.5.26
          alert('Error is an instance of ApolloError')
        }
      })
  }
  
  render () {
    return (
      <button onClick={ this.save }>Save</button>
    )
  }
}

const query = gql`
  mutation MutationName
    mutate {
      resultingField
    }
  }
`

export default graphql(query)(MyContainer)

I found this problem doing error normalization using the previous version, but once I've update the module, the code stopped working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions