Skip to content

Instantly share code, notes, and snippets.

@bessey
Last active November 29, 2016 23:12
Show Gist options
  • Select an option

  • Save bessey/926cdb3e383b406e7f546c6f4dd55a8a to your computer and use it in GitHub Desktop.

Select an option

Save bessey/926cdb3e383b406e7f546c6f4dd55a8a to your computer and use it in GitHub Desktop.
Apollo error workaround
import React, { Component, PropTypes } from "react"
// Fixes a silly bug in Apollo where certain errors are not propagated to the console
const throwApolloError = function(WrappedComponent) {
return class ApolloErrorThrower extends Component {
static propTypes = {
data: PropTypes.shape({
error: PropTypes.object
})
}
render () {
let error = null
if (this.props.data) {
error = this.props.data.error
}
if (error) {
throw error
} else {
return <WrappedComponent {...this.props}/>
}
}
}
}
export default throwApolloError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment