技術浮浪貢

NestJS 的 GraphQL Error

筆記一下 NestJS (搭配 Apollo) 是怎麼把內部丟出的 exception 轉換成 GraphQL 的 error response。

標準步驟

階段 1. Apollo server

階段 2. NestJS Apollo driver

(透過 Apollo server 的 formatError 選項改寫 error response)

客製化方法

  1. 想要改寫 HTTP status / header: 丟出 GraphQLError,在 extensions 裡面新增 http 欄位

  2. 只有要改寫 error response 的內容: 透過 GraphQLModule 的 formatError 選項

#GraphQL #NestJS

« 上一篇

沒有下一篇