预期结果:将graphQLError 消息记录到控制台
从失败的查询返回的错误消息似乎永远不会成为onError()
因为graphQLErrors
总是未定义的,但我总是得到一个 networkError。 我可以在 chrome 的网络选项卡中找到带有响应错误消息的失败请求。 我错过了什么吗?
// Log errors
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.map(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.log(`[Network error]: ${networkError}`);
});
// Combine all links
const link = split(
// split based on operation type: subscription or query/mutation
({ query }) => {
const { kind, operation } = getMainDefinition(query);
return kind === 'OperationDefinition' && operation === 'subscription';
},
// Subscriptions Link
from([
// Log Apollo operations in development
...(__DEV__ ? [apolloLogger] : []),
// Handle subscriptions, log errors in dev
...(__DEV__ ? [errorLink.concat(subscriptionsLink)] : [subscriptionsLink]),
]),
// Uploads/http Link
from([
// Log Apollo operations in development
...(__DEV__ ? [apolloLogger] : []),
// Handle http/file uploads, log errors in dev
...(__DEV__ ? [errorLink.concat(uploadLink)] : [uploadLink]),
]),
);
同样的问题在这里。 我们想要一个全局的onError
函数。
目前我们将 onError 函数传递给每个subscribeToMore
函数:
this.unsubscribe = data.subscribeToMore({
document: ...,
variables: {...}
updateQuery: (previous, { subscriptionData }) => {
...
},
onError: err => {
console.log({ err })
},
})
@goldo确切地说,当您真的只想记录所有内容时,该模式不能很好地扩展,因此出现错误链接!
我对文档感到困惑
const withDataAndErrors = graphql(MY_MIXED_QUERY, {
options: {
errorPolicy: 'all'
}
});
基于每个查询的错误策略是否会以某种方式影响onError()
获取消息的方式? 或者也许 GraphQL-Tools/Apollo Server 有一些新参数来启用错误日志?
@tim-soft 您使用的fetch
库是否可能将 HTTP 400 状态视为网络错误? 我遇到过一些这样的 fetch 模块。
这方面有什么进展吗?
最有用的评论
这方面有什么进展吗?