实现GraphQL&扑 [英] Implement GraphQL & Flutter
本文介绍了实现GraphQL&扑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在Flutter中实现GraphQL?我试图用JSON对象中的查询和变量对象进行API调用.
Is there a way to implement GraphQL in flutter? I was trying making the API call with the query and variables objects in a JSON object.
类型'_InternalLinkedHashMap'不是强制类型转换中'字符串'类型的子类型
type '_InternalLinkedHashMap' is not a subtype of type 'String' in type cast
推荐答案
我一直在使用 graphql_flutter 包已经有几个星期了,它似乎已经足够好了.这是一个示例:
I have been using graphql_flutter package for a few weeks now and it seems to work well enough. Here is an example:
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和任何变量.即删除突变可能看起来像
To use just give it the graphql and any variables. i.e. a delete mutation may look like
String deleteMutation =
'''mutation deleteItem(\$itemId: ID!) {
deleteItem(input: { itemId: \$itemId}) {
itemId
}
}'''.replaceAll('\n', ' ');
await post(deleteMutation , variables: <String, dynamic>{'itemId': itemId});
这篇关于实现GraphQL&扑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文