此代码无效。因为发生错误时错误属性始终为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>
);