[英]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.