我是 Flutter 的新手,GraphQl
我想使用我实现的这个查询Laravel
:
type Query {
loginAccount(mobile_number:String
@rules(apply:["required","min:11","max:11"])
):ResponseResultWithMessage
}
type ResponseResultWithMessage{
result:Int,
title:String
description:String
}
当我测试它时,这个查询对我来说很好,但是当我尝试实现它时,Flutter
我得到了这个错误:
I/flutter(20938):OperationException(linkException:null,graphqlErrors:[GraphQLError(消息:字段“loginAccount”参数“mobile_number”需要类型字符串,找到字符串。,位置:[ErrorLocation(行:3,列:31)] ,路径:空,扩展:{类别:graphql})])
我的代码:
class _Login extends State<Login> {
final _formKey = GlobalKey<FormState>();
final sample = r'''
query {
loginAccount(mobile_number:String) {
result
title
description
}
}
''';
@override
Widget build(BuildContext context) {
return Scaffold(
//...
body: Query(
options: QueryOptions(document: gql(sample), variables:<String,dynamic> {
'mobile_number': '0123456789',
}),
builder: (QueryResult result, { VoidCallback refetch, FetchMore fetchMore }) {
if (result.hasException) {
debugPrint(result.exception.toString());
return Text(result.exception.toString());
}
if (result.isLoading) {
return const Text('Loading');
}
debugPrint('$result');
return Container();
}
));
}
}