简体   繁体   English

graphql_flutter 突变查询需要返回语句 - 不确定如何添加它

[英]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 控制台中检查了您的突变查询,因为突变查询需要返回字段或受影响的行,如图所示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.

相关问题 如何在 graphql_flutter 中重试对 GraphQLError 的请求 - How to retry a request on GraphQLError in graphql_flutter 如何在每次构建Query()时禁用graphql_flutter查询后端 - How to disable graphql_flutter query backend every time build Query() graphql_flutter 返回 LazyCacheMap,built_value deserializeWith JSON String,如何让它们协同工作 - graphql_flutter return LazyCacheMap, built_value deserializeWith JSON String, how to make them work together 在操场上运行的 Graphql_flutter 突变在运行设备/模拟器上不起作用 - Graphql_flutter mutation running on playground doesn't work on running device/emulator Websocket 重连循环,graphql_flutter - Websocket reconnection loop, graphql_flutter 使用 graphql_flutter 连接到 Graphql API 时出错 - Error when connecting to Graphql API using graphql_flutter 如何在 Flutter 中使用 graphql 在 Mutation 中传递枚举? - How to pass enum in Mutation using graphql in Flutter? 突变不起作用 - Flutter 和 GraphQL - Mutation is not working - Flutter & GraphQL Flutter with Firebase JWT 将 GraphQL (graphql_flutter) 请求发送到具有“格式错误的授权标头”的 Heroku Hasura - Flutter with Firebase JWT sends GraphQL (graphql_flutter) request to Heroku Hasura that has a “Malformed Authorization header” Flutter (graphql_flutter + gql):找到这个候选,但参数不匹配 - Flutter (graphql_flutter + gql): Found this candidate, but the arguments don't match
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM