從 Apollo Graphql 檔案中,這種方式可以定義擴展錯誤:
https://www.apollographql.com/docs/apollo-server/data/errors/
import { GraphQLError } from 'graphql';
throw new GraphQLError('the error message',
extensions: {
code: 'SOMETHING_BAD_HAPPENED',
http: {
status: 404,
headers: new Map([
['some-header', 'it was bad'],
['another-header', 'seriously'],
]),
},
},
);
但在我的情況下,它得到了這個錯誤:
Argument of type '{ extensions: { code: string; http: { status: number; headers: Map<string, string>; }; }; }' is not assignable to parameter of type 'Maybe<ASTNode | readonly ASTNode[]>'.
Object literal may only specify known properties, and 'extensions' does not exist in type 'ASTNode | readonly ASTNode[]'.
23 extensions: {
~~~~~~~~~~~~~
24 code: 'SOMETHING_BAD_HAPPENED',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
31 },
~~~~~~~~~~~~
32 },
~~~~~~~~~
Found 1 error(s).
我正在使用這些軟體包:
- “阿波羅服務器核心”:“^3.7.0”,
- "apollo-server-express": "^3.4.0",
- "apollo-server-plugin-base": "^0.13.0",
我也嘗試安裝apollo-server-testing但仍然無法使用擴展。
uj5u.com熱心網友回復:
這種方式有效:
throw new GraphQLError('the error message',
null,
null,
null,
null,
null,
{
code: 'SOMETHING_BAD_HAPPENED',
http: {
status: 404,
},
},
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/517464.html
上一篇:javarmi-如何處理RemoteException
下一篇:用戶輸入的型別檢查并排除負數例外
