我使用的是OperationException(linkException: ResponseFormatException(originalException: FormatException:输入的意外结束(字符1) )、^ graphqlErrors:[]、
有没有办法显示实际发送的请求?想要在控制台中看到传递的实际请求
客户端
class GraphqlClient {
static String _token;
static final String serverUrl =
GlobalConfiguration().getString(Config.GRAPHQL_URL);
static final HttpLink httpLink = HttpLink(
serverUrl,
);
static final AuthLink authLink = AuthLink(getToken: () async {
final SharedPrefsRepository _sharedPrefsRepository =
SharedPrefsRepository();
String accountKey = await _sharedPrefsRepository.getAccountKey();
String sessionKey= await _sharedPrefsRepository.getSessionKey();
_token = 'Bearer $accountKey, Bearer $sessionKey';
debugPrint('token '+_token);
return _token ?? '';
});
static final Link link = authLink.concat(httpLink);
static ValueNotifier<GraphQLClient> initializeClient() {
debugPrint('link '+link.toString());
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;
}
}请求
Query(
options: QueryOptions(
document: gql(DashboardGraphQL.accountDetailsQuery),
operationName: 'AccountDetails',
),查询
static const String accountDetailsQuery = """
query AccountDetails {
accountDetails {
... on AccountDetails {
ibanList {
accountId
bicCode
iban
}
accountType
accountNumber
accountNumberShort
accountId
ruid
companyId
accountDataOpened
email
mobile
baseCurrency
balanceInBaseCurrency
lastTransactionDate
}
... on ResponseErrors {
errors {
message
code
displayMessage
... on InternalError {
message
code
displayMessage
context
}
}
}
}
}
"""发布于 2022-10-22 11:17:42
您可以创建一个链接,它记录您发送的每一个请求,然后将它与您的链接连接起来。
class LoggerLink extends Link {
@override
Stream<Response> request(
Request request, [
NextLink? forward,
]) {
Stream<Response> response = forward!(request).map((Response fetchResult) {
final ioStreamedResponse =
fetchResult.context.entry<HttpLinkResponseContext>();
if (kDebugMode) {
print("Request: " + request.toString());
print("Response:" + (ioStreamedResponse?.toString() ?? "null"));
}
return fetchResult;
}).handleError((error) {
// throw error;
});
return response;
}
LoggerLink();
} 您可以创建此链接的实例。
final _loggerLink = LoggerLink() ;然后你就会在你的客户中加入它。
client = ValueNotifier<GraphQLClient>(GraphQLClient(
link: _loggerLink.concat(httpLink),
cache: GraphQLCache(),
defaultPolicies: DefaultPolicies(
watchQuery: Policies(fetch: FetchPolicy.networkOnly),
query: Policies(fetch: FetchPolicy.networkOnly),
mutate: Policies(fetch: FetchPolicy.networkOnly),
),
));请注意,
httpLink是你的实际链接
https://stackoverflow.com/questions/72128141
复制相似问题