0
的documentation告訴我們,一個解析器具有這種形式:如何在graphql apollo-server突變解析程序中發出錯誤信號?
fieldName: (obj, args, context, info) => result
而這結果是null
或undefined
如果「對象找不到」。
其他錯誤怎麼樣 - 例如,如果訪問未被授權?
您似乎無法直接「返回」錯誤,因爲結果必須與模式匹配。
我試過在解析器中拋出一個異常,這幾乎是正確的:客戶端得到一個ApolloError異常消息:很棒。但是apollo-server發出一個堆棧跟蹤,就好像這個異常沒有被處理。這看起來不正確。
因此,這個問題:應該怎麼做?
阿波羅服務器堆棧跟蹤,在情況下,它可以幫助:
Error: test exception message
at /Users/mgregory/NRN/src/agreeonit/apollo_server/resolvers/mutationResolvers.js:29:17
at tryCatcher (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/promise.js:510:31)
at Promise._settlePromise (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/promise.js:567:18)
at Promise._settlePromise0 (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/promise.js:612:10)
at Promise._settlePromises (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/promise.js:691:18)
at Async._drainQueue (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/async.js:138:16)
at Async._drainQueues (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/async.js:148:10)
at Immediate.Async.drainQueues (/Users/mgregory/NRN/src/agreeonit/apollo_server/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:574:20)
at tryOnImmediate (timers.js:554:5)
at processImmediate [as _immediateCallback] (timers.js:533:5)