[英]graphql_flutter mutation query expects return statement - not sure how to add it
The mutation query on the builder method is expecting a return statement, which I am not sure where and how to add to the below code. builder 方法上的变异查询需要返回语句,我不确定在何处以及如何将其添加到以下代码中。 I believe the mutation query should return a pass or fail for the operation.
我相信变异查询应该返回操作的通过或失败。
I have been trying to figure this out for the past few days.在过去的几天里,我一直在努力解决这个问题。 I still haven't got a clue on what is wrong.
我仍然不知道出了什么问题。
I have this method which is called on the onCompleted callback when the user fills in the one time code.我有这个方法,当用户填写一次性代码时,它会在 onCompleted 回调上调用。
createUser Mutation Query - createUser 突变查询 -
class GraphQlMutations {
final String createUser = r'''
mutation createUser($uid: ID!, $fullname: String!, $phone: String!, $photourl: String, $createdtime: String){
createUser(uid: $uid, fullname: $fullname, phone: $phone, photourl: $photourl, createdtime: $createdtime){
uid
fullname
phone
photourl
createdtime
}
}
''';
}
void signInWithPhoneAuthCredential(
PhoneAuthCredential phoneAuthCredential) async {
setState(() {
showLoading = true;
});
try {
setState(() {
showLoading = false;
});
final authCredential =
await _auth.signInWithCredential(phoneAuthCredential);
User? user = authCredential.user;
print(user);
if (authCredential.user != null) {
Mutation(
options: MutationOptions(
document: gql(GraphQlMutations().createUser),
onCompleted: (dynamic resultData) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('New user added')));
}),
builder: (RunMutation createUser, QueryResult? result) {
if (user != null) {
final DateTime? createdTime = user.metadata.creationTime;
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String userCreatedTime = formatter.format(createdTime!);
try {
createUser({
'uid': user.uid,
'fullname': _fullname.text,
'phone': user.phoneNumber,
'photourl': 'https://www.bol.com',
'createdtime': userCreatedTime,
});
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => Conversations()));
} catch (e) {}
}
},
);
}
}
}
Vscode points out an error on the builder method which exactly says - Vscode 指出了 builder 方法的一个错误,它确切地说 -
The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type.正文可能会正常完成,从而导致返回 'null',但返回类型可能是不可为 null 的类型。 Try adding either a return or a throw statement at the
尝试在
Somebody with expertise in graphq_flutter please chime in to help.请在 graphq_flutter 方面具有专业知识的人提供帮助。
Thanks.谢谢。
did you check your mutation query in graphql console because mutation query require field returning or affected_rows as show in image您是否在 graphql 控制台中检查了您的突变查询,因为突变查询需要返回字段或受影响的行,如图所示
and if you are running sound null safety then you should also consider that any of your fields(uid, fullname, phone,...) aren't retuning null.并且如果您运行声音空安全,那么您还应该考虑您的任何字段(uid、全名、电话,...)都没有重新调整空值。
and can you provide more detail on createUser
if problem not resolve如果问题未解决,您能否提供有关
createUser
更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.