突变不起作用-Flutter和GraphQL

问题描述

我将我的应用程序与graphql连接起来,查询工作正常,并且能够从API获取数据,但是某种程度上,这些突变根本无法正常工作。我的想法是一个简单的登录功能,您可以在其中输入现有用户的登录名和密码。每次运行它时,onCompleted都会返回空值,而不是带有令牌的JSON。稍后,我检查了该突变是否将任何内容传递给数据库,但没有。有办法解决吗?

我的代码:

final String loginQuery = """
mutation loginUser(\$email: String!,\$password: String!){
 login(email: \$email,password: \$password){}
}
""";

登录窗口小部件:按下按钮后,文本窗口小部件应显示突变的结果。

Widget mutation() {
    return Mutation(
        options: MutationOptions(
          update: (Cache cache,QueryResult result) {
            return cache;
          },onCompleted: (resultData) {
            print('on completed $resultData');
          },documentNode: gql(loginQuery),),builder: (RunMutation runMutation,QueryResult result) {
          return Column(
            children: <Widget>[
              RaisedButton(
                  child: Text('login'),onPressed: () {
                    runMutation(
                        {"email": "mockuser@gmail.com","password": "123456"});
                    print(result.data);
                  }),Container(
                  color: Colors.white,child: Text('Result  \n ${result?.data?.toString()}'))
            ],);
        });
  }

解决方法

尝试使用,

onError: (err) {
          print(err.graphqlErrors);
         },

完成后。 这将向您显示错误(如果有)。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...