1

尝试禁用有关输入验证错误的显式消息。当我请求一个不存在的字段(即年龄)时,我得到:

{
"data": null,
"errors": [{
        "path": null,
        "locations": [
            {
                "line": 1,
                "column": 129,
                "sourceName": null
            }
        ],
        "message": "Validation error of type FieldUndefined: Field 'age' in type 'Patient' is undefined @ 'path/age'"
    }]}

我想覆盖错误以显示自定义错误消息:

    {
"data": null,
"errors": [
    {
        "message": "invalid fields"
    }
]}

我的带有自定义 SystemError 的架构示例(不起作用):

type Patient {
  id: Int!
  firstName: String
  lastName: String
}

type Query {
  patient(id: Int!): Patient
  errors: [SystemError]
}

type SystemError {
  id: Int!
  message: String
}

schema {
  query: Query
}
4

1 回答 1

0

您可以尝试使用中间件 fe middy(一些 googled appsync 中间件),https://github.com/bboure/middy-appsync#error-handling

要限制错误信息,您可以尝试(未经测试)使用以下内容:

const doStuff = (event, context, callback) => {
  if( context.result && context.result.errorMessage ) {
    callback(new GraphQlError('Error'));
  } else {
    callback(null, context.result.data);
  }
};
于 2020-05-21T13:07:42.127 回答