dart - 实现 GraphQL 和 Flutter
问题描述
有没有办法在 Flutter 中实现 GraphQL?我正在尝试使用 JSON 对象中的查询和变量对象进行 API 调用。
类型“_InternalLinkedHashMap”不是类型转换中“String”类型的子类型
解决方案
我已经使用graphql_flutter包几个星期了,它似乎工作得很好。这是一个例子:
import 'package:graphql_flutter/graphql_flutter.dart' show Client, InMemoryCache;
...
Future<dynamic> post(
String body, {
Map<String, dynamic> variables,
}) async {
final Client client = Client(
endPoint: endpoint,
cache: new InMemoryCache(),
);
final Future<Map<String, dynamic>> result =
client.query(query: body, variables: variables);
return result;
}
要使用它,只需给它 graphql 和任何变量。即删除突变可能看起来像
String deleteMutation =
'''mutation deleteItem(\$itemId: ID!) {
deleteItem(input: { itemId: \$itemId}) {
itemId
}
}'''.replaceAll('\n', ' ');
await post(deleteMutation , variables: <String, dynamic>{'itemId': itemId});
推荐阅读
- .net - 具有众多身份角色的 .NET 5 400 错误
- visual-studio-code - pickProcess 命令的源代码 VS Code
- r - 删除数据框中所有列名的字符
- reactjs - 从 Material UI 下拉选择中显示模态
- javascript - 只有当我在 Spotify API 上发出第一次获取请求(单击搜索方法)时,我才会得到 401,之后就可以正常工作了。请帮我解决它
- python - Python .loc 返回一个 TypeError
- julia - 如何在 Colab 上打开 .ipynb 笔记本
- javascript - 使用useState在React中更新数组时如何保留以前的值
- coq - 如何在 Coq 中表达归纳关系的一个元素不能从另一个元素推导出来?
- python - 如何在 Python 中标准化颜色条?