简体   繁体   English

Flutter OperationException(linkException: ResponseFormatException(originalException: FormatException: 输入意外结束(在字符 1 处)

[英]Flutter OperationException(linkException: ResponseFormatException(originalException: FormatException: Unexpected end of input (at character 1)

Previously I was using graphql version 3.1.0 and it was working fine, able to receive request as expected, but recently I had to update my flutter version to 2.10.3 and all other packages, including graphql.以前我使用的是graphql版本 3.1.0,它工作正常,能够按预期接收请求,但最近我不得不将我的 flutter 版本更新到 2.10.3 和所有其他包,包括 graphql。

Now I am using v.5.1.0 and I suddenly get this error.现在我正在使用 v.5.1.0,但突然出现此错误。

Only changed the documentNode to document in Query.仅将 documentNode 更改为 Query 中的 document。 I built the request as per the documentation.我根据文档构建了请求。

main.dart主要.dart

 @override
  void initState() {
    _appSettingsManager.loadSettings();
    GraphQLRepository.instance.initializeClient();
    super.initState();
  }

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

Graphql Repository Graphql 资料库

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;
  }
}

Client客户

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;
  }
}

Response回复

{
  "data": {
    "balanceList": {
      "data": [
        {
          "currency": "GBP",
          "amount": 1000,
          "pendingAmount": 199,
          "holdAmount": 0,
          "availableBalance": 801
        },
        {
          "currency": "EUR",
          "amount": 1000000,
          "pendingAmount": 647,
          "holdAmount": 0,
          "availableBalance": 999353
        }
      ]
    }
  }
}

Previously I was using graphql version 3.1.0 and it was working fine, able to receive request as expected, but recently I had to update my flutter version to 2.10.3 and all other packages, including graphql.以前我使用的是graphql版本 3.1.0,它工作正常,能够按预期接收请求,但最近我不得不将我的 flutter 版本更新到 2.10.3 和所有其他包,包括 graphql。

Welcome to the present.欢迎来到现在。

Try to look in the migrate guide https://github.com/zino-hofmann/graphql-flutter/blob/main/changelog-v3-v4.md this will solve your problem!尝试查看迁移指南https://github.com/zino-hofmann/graphql-flutter/blob/main/changelog-v3-v4.md这将解决您的问题!

In addition, your query needs to contain __typename as described in the example https://github.com/zino-hofmann/graphql-flutter/blob/main/packages/graphql/README.md#query此外,您的查询需要包含__typename ,如示例https://github.com/zino-hofmann/graphql-flutter/blob/main/packages/graphql/README.md#query中所述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter GraphQL - OperationException(linkException:ResponseFormatException(originalException:FormatException:意外字符(在字符1) - Flutter GraphQL - OperationException(linkException: ResponseFormatException(originalException: FormatException: Unexpected character (at character 1) I/flutter:FormatException:输入意外结束(在字符 1 处) - I/flutter : FormatException: Unexpected end of input (at character 1) FormatException:输入意外结束(在字符 2 处)^ 在 flutter - FormatException: Unexpected end of input (at character 2) ^ in flutter FormatException:输入意外结束(在字符 1 处)^ - FormatException: Unexpected end of input (at character 1) ^ FormatException: 意外的输入结束(在字符 1 处) - FormatException: Unexpected end of input (at character 1) 未处理的异常:FormatException:意外的输入结束(在字符 1) - Unhandled Exception: FormatException: Unexpected end of input (at character 1) 未处理的异常:FormatException:输入意外结束(在字符 2 处) - Unhandled Exception: FormatException: Unexpected end of input (at character 2) FormatException:OSM map 的输入意外结束(在字符 1 处) - FormatException: Unexpected end of input (at character 1) with OSM map ObjectBox 失败:“FormatException:输入意外结束(在字符 1 处)” - ObjectBox Failure: "FormatException: Unexpected end of input (at character 1)" 未处理的异常:FormatException:flutter(在 shared_preferences 中)的输入意外结束(在字符 1) - Unhandled Exception: FormatException: Unexpected end of input (at character 1) in flutter (in shared_preferences)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM