【发布时间】:2021-10-03 12:03:35
【问题描述】:
我正在使用带字段的 InputType:
@InputType('RegisterInput')
export default class RegisterInput {
@Field({nullable: true})
username: string
@Field({nullable: true})
password: string
@Field({nullable: true})
age?: number
}
当年龄不是数字时,我会收到如下错误:
UserInputError {
message: 'Variable "$registerInput" got invalid value "text" at "registerInput.age"; Int cannot represent non-integer value: "text"',
locations: [ { line: 1, column: 19 } ],
path: undefined,
extensions: { code: 'BAD_USER_INPUT' }
}
如何将消息更改为更加用户友好?我尝试的所有类型的中间件和类验证仍然首先产生此错误,然后产生任何其他错误。
如果我可以禁用它并在我的中间件中进行验证,那就更好了。
我尝试使用 graphql-middleware,但仍然只有在此验证之后才调用中间件。
【问题讨论】:
标签: node.js graphql apollo-server typegraphql