Ошибки захвата Graphql-Shield

В резольвере throw new createError.BadRequest("bad input") ошибка захвачена Graphql-shield и показано как

      {
    "errors": [
        {
            "message": "Not Authorised!",
            "locations": [
                {
                    "line": 2,
                    "column": 3
                }
            ],
            "path": [
                "myMutation"
            ],
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "exception": {
                    "stacktrace": [
                        "Error: Not Authorised!",

Это установка Apollo Server

          const schema = buildSubgraphSchema([
      { typeDefs: await typeDefs(), resolvers },
    ]);
    const apolloServer = new ApolloServer({
      schema: applyMiddleware(schema, permissions),
      context: async ({ req, res }) => new AuthenticatedContext(req, res)
    });

Как мне вернуть фактическую ошибку?

1 ответ

Я нашел решение в документации по щиту :

      const permissions = shield({
    Query: {
        ...
    },
    Mutation: {
        ...
    },
}, {allowExternalErrors: true});

Согласно документации , параметр allowExternalErrors по умолчанию имеет значение false.

Другие вопросы по тегам