簡體   English   中英

發送錯誤到阿波羅graphql

[英]Sending errors to apollo graphql

我有一個這樣的查詢解析器:

page: (root, args) =>
      DB.page
        .findById(args.id)
        .then((result) => {
          if (result == null) throw Error(`Page not found for ${args.id}`);
          return result;
        })
        .catch((error) => {
          log.error('Error in page query.', error.message);
        }),

當我執行查詢時,結果是:

{
  "data": {
    "page": null
  }
}

但是它沒有顯示查詢失敗時拋出的錯誤。 我的期望:

{
  "errors": [
    ...
  ]
}

引發錯誤后,您就可以捕獲錯誤。 您需要完全忽略catch ,或者在記錄日志后拋出catch錯誤:

.catch((error) => {
  log.error('Error in page query.', error.message)
  throw error
}),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM