错误属性在react-apollo中始终未定义

时间:2018-12-11 20:15:19

标签: react-apollo

此代码无效。因为发生错误时错误属性始终为undefined。我正在使用服务器端渲染。

const MY_QUERY = gql`
  query WillFail {
    badField
    goodField
  }
`;
const ShowingSomeErrors = () => (
  <Query query={MY_QUERY} errorPolicy="all">
    {({ error, data, loading }) => {
      if (loading) return <span>loading...</span>
      return (
        <div>
          <h2>Good: {data.goodField}</h2>
          <pre>Bad: {error.graphQLErrors.map(({ message }, i) => (
            <span key={i}>{message}</span>
          ))}
          </pre>
        </div>
      )
    }}
  </Query>
);

0 个答案:

没有答案