实现 GraphQL &扑 [英] Implement GraphQL & Flutter

查看:27
本文介绍了实现 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' 不是类型转换中类型 'String' 的子类型

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('
', ' ');

 await post(deleteMutation , variables: <String, dynamic>{'itemId': itemId});

这篇关于实现 GraphQL &amp;扑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆