チェック:自分のReadMeからhttps://github.com/thebigredgeek/apollo-errors
:
いくつかのエラーを作成します。
import { createError } from 'apollo-errors';
export const FooError = createError('FooError', {
message: 'A foo error has occurred'
});
は、書式設定フックアップ:
import express from 'express';
import bodyParser from 'body-parser';
import { formatError } from 'apollo-errors';
import { graphqlExpress } from 'apollo-server-express';
import schema from './schema';
const app = express();
app.use('/graphql',
bodyParser.json(),
graphqlExpress({
formatError,
schema
})
);
app.listen(8080)
は、いくつかのエラーを投げる:
を
import { FooError } from './errors';
const resolverThatThrowsError = (root, params, context) => {
throw new FooError({
data: {
something: 'important'
}
});
}
あなたの答えに感謝します。 1)私は投げたり、エラーの配列を返したり、前に文字列の配列を返したりしましたが、運はありません。あなたはそれをする方法を知っていますか? 2)通常のルーチンでは、サーバーの応答からのエラー配列がフォーム検証のようなエラーには適していないように、データオブジェクトに捕捉されたエラーを代わりに置きます – James