【发布时间】:2021-04-10 02:50:45
【问题描述】:
viewModelScope.launch {
val req = RequestCodeMutation(phoneNumber)
val response = try {
ApolloClientManager
.apolloClient
.suspendMutate(req)
}
catch (e: ApolloException) {
println(e.message)
isError.value = true
null
}
finally {
loading.value = false
}
val requestCode = response?.data?.requestCode
println(response?.errors)
}
suspend fun <D : Operation.Data, T, V : Operation.Variables> ApolloClient.suspendMutate(mutation: Mutation<D, T, V>): Response<T> =
mutate(mutation).toDeferred().await()
这是我在服务器端的验证器。它在 Graphiql 上正确显示,但是,我无法在客户端收到此消息。
requestCode = async (resolve, source, args, context, info) => {
let { phoneNumber } = args;
phoneNumber = validator.trim(phoneNumber);
Object.assign(args, { phoneNumber });
if (!validator.isMobilePhone(phoneNumber)) {
throw new UserInputError('Invalid phone number provided!');
}
return resolve(source, args, context, info);
}
ApolloException.message 显示内部服务器错误,response?.errors 是 null。
response?.errors 不应该是 null 并显示 GraphiQL 上显示的正确错误消息。
【问题讨论】:
-
您在 catch 块中返回
null。所以响应为空,response?.errors -
@ChristianB 如果我返回任何其他内容,它不允许我访问响应的数据属性。该块应该返回什么?
标签: android kotlin graphql apollo