首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振OperationException(linkException: ResponseFormatException(originalException: FormatException:意外输入结束)(字符1)

颤振OperationException(linkException: ResponseFormatException(originalException: FormatException:意外输入结束)(字符1)
EN

Stack Overflow用户
提问于 2022-05-02 11:50:13
回答 1查看 419关注 0票数 1

以前我使用的是图形版本3.1.0,它运行良好,能够按预期接收请求,但最近我不得不将自己的flutter版本更新为2.10.3和所有其他包,包括graphql。

现在我使用的是5.1.0版本,我突然得到了这个错误。

只将documentNode更改为查询中的文档。我根据文档构建了请求。

main.dart

代码语言:javascript
复制
 @override
  void initState() {
    _appSettingsManager.loadSettings();
    GraphQLRepository.instance.initializeClient();
    super.initState();
  }

GraphQLProvider(client: GraphQLRepository.instance.graphQLClientValueNotifier,child: MaterialApp....

图形库

代码语言:javascript
复制
class GraphQLRepository {
  factory GraphQLRepository() {
    return instance;
  }

  GraphQLRepository._();

  static final GraphQLRepository instance = GraphQLRepository._();
  GraphQLClient _graphQLClient;
  ValueNotifier<GraphQLClient> _graphQLClientValueNotifier;

  GraphQLClient get graphQlClient => _graphQLClient;
  ValueNotifier<GraphQLClient> get graphQLClientValueNotifier =>
      _graphQLClientValueNotifier;

  void initializeClient() {
    _graphQLClientValueNotifier = GraphqlClient.initializeClient();
    _graphQLClient = _graphQLClientValueNotifier.value;
    return;
  }
}

客户端

代码语言:javascript
复制
class GraphqlClient {
  static String _token;


  static final HttpLink httpLink = HttpLink(
     serverUrl,
  );

  static final AuthLink authLink = AuthLink(getToken: () async {
    _token = 'Bearer $accountKey, Bearer $sessionKey';
    return _token ?? '';
  });

  static final Link link = authLink.concat(httpLink);

  static ValueNotifier<GraphQLClient> initializeClient() {
    final policies = Policies(
      fetch: FetchPolicy.networkOnly,
    );
    
    final ValueNotifier<GraphQLClient> client = ValueNotifier<GraphQLClient>(
      GraphQLClient(
        cache: GraphQLCache(store: HiveStore()),
        link: link,
        defaultPolicies: DefaultPolicies(
          watchQuery: policies,
          query: policies,
          mutate: policies,
        ),
      ),
    );
    return client;
  }
}

响应

代码语言:javascript
复制
{
  "data": {
    "balanceList": {
      "data": [
        {
          "currency": "GBP",
          "amount": 1000,
          "pendingAmount": 199,
          "holdAmount": 0,
          "availableBalance": 801
        },
        {
          "currency": "EUR",
          "amount": 1000000,
          "pendingAmount": 647,
          "holdAmount": 0,
          "availableBalance": 999353
        }
      ]
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-05-03 08:10:34

以前我使用的是图形版本3.1.0,它运行良好,能够按预期接收请求,但最近我不得不将自己的flutter版本更新为2.10.3和所有其他包,包括graphql。

欢迎来到现在。

尝试查看迁移指南https://github.com/zino-hofmann/graphql-flutter/blob/main/changelog-v3-v4.md,这将解决您的问题!

此外,您的查询需要包含__typename,如示例https://github.com/zino-hofmann/graphql-flutter/blob/main/packages/graphql/README.md#query中所述。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72086256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档