标签: graphql-flutter

graphql_flutter 错误:非抽象类“GraphQLWebSocketChannel”缺少实现

我正在尝试将 graphql_flutter ( https://pub.dev/packages/graphql_flutter ) 用于我的 MVVM 架构。(https://stacked.filledstacks.com/docs/getting-started/overview)当我尝试运行我的代码时,我从包 graphql_flutter 中收到以下错误

`../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/graphql-5.1.2/lib/src/links/websocket_link/websocket_client.dart:577:7:错误:非- 抽象类“GraphQLWebSocketChannel”缺少这些成员的实现:

  • WebSocketChannel.ready 尝试任一
  • 提供一个实现,
  • 从超类或 mixin 继承实现,
  • 将类标记为抽象类,或者
  • 提供“noSuchMethod”实现。

GraphQLWebSocketChannel 类扩展了 StreamChannelMixin<dynamic> ^^^^^^^^^^^^^^^^^^^^^^^^ ../../Developer/flutter/.pub-cache/hosted/pub.dartlang .org/web_socket_channel-2.3.0/lib/src/channel.dart:56:22:上下文:“WebSocketChannel.ready”在这里定义。最终 Future<void> 准备好 = Future.value();`

这是我在 main.dart 文件中的代码。只要我导入了包,我就会收到错误。

    import 'package:flutter/material.dart';
    import 'package:testing/app/app.locator.dart';
    import 'package:testing/ui/common/app_colors.dart';
    import 'package:testing/ui/setup/setup_bottom_sheet_ui.dart';
    import 'package:testing/ui/setup/setup_dialog_ui.dart';
    import 'package:stacked_services/stacked_services.dart';

    import 'package:graphql_flutter/graphql_flutter.dart';

    import 'app/app.router.dart';

    void main() {
      setupLocator();
      setupDialogUi();
      setupBottomSheetUi();

      runApp(const MyApp());
    }

    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);

      @override
      Widget build(BuildContext context) {
        HttpLink httpLink = HttpLink("https://api.github.com/graphql"); …
Run Code Online (Sandbox Code Playgroud)

stacked flutter graphql-flutter flutter-stacked

10
推荐指数
1
解决办法
3090
查看次数

Flutter GraphQL - OperationException(linkException: ResponseFormatException(originalException: FormatException: 意外字符(在字符 1 处)

我在使用 graphql_flutter 包的 mutate 方法时收到此错误。

尝试使用以下版本的qraphql_flutter包:

错误:

I/flutter (13946): //// EXCEPTION: OperationException(linkException: ResponseFormatException(originalException: FormatException: Unexpected character (at character 1)
I/flutter (13946): <!DOCTYPE html>
I/flutter (13946): ^
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://xxx.xxx.dev/login'" />

        <title>Redirecting to https://xxx.xxx.dev/login</title>
    </head>
    <body>
        Redirecting to <a href="https://xxx.xxx.dev/login">https://xxx.xxx.dev/login</a>.
    </body>
</html>
I/flutter (13946): ), graphqlErrors: [])
Run Code Online (Sandbox Code Playgroud)

我尝试使用相同的代码运行查询。此代码与查询完美配合,仅在使用突变时引发异常。我创建了一个 graphql 帮助器类,它可以帮助使用此帮助器类执行项目中的每个 graphql 操作。

GraphQL 助手类:

import 'package:flutter/foundation.dart';
import 'package:graphql_demo/app_exception.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

class AppGraphQlClient {
  late GraphQLClient _client;

  AppGraphQlClient(String graphqlUrl) {
    final httpLink …
Run Code Online (Sandbox Code Playgroud)

graphql flutter flutter-graphql graphql-flutter

5
推荐指数
1
解决办法
2340
查看次数

Flutter graphql 显示实际请求

我正在使用flutter_graphql并不断收到异常OperationException(linkException: ResponseFormatException(originalException: FormatException: Unexpected end of input (at character 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); …
Run Code Online (Sandbox Code Playgroud)

graphql flutter flutter-graphql graphql-flutter

4
推荐指数
1
解决办法
1068
查看次数

graphql_flutter 突变小部件显示错误 -

我不确定我是否完全理解这个错误。任何有使用 graphql_flutter 包经验的人请帮忙。对 Flutter 和 graphql 来说是全新的。但到目前为止我已经弄清楚了后端。

我的突变在 graphiql 中工作,试图使其在 flutter 中工作。当我将鼠标悬停在这些红线上时,会出现此错误。

错误 - 参数类型“列函数(MultiSourceResult Function(Map <String,dynamic>,{Object?optimisticResult}),QueryResult)”无法分配给参数类型“Widget Function(MultiSourceResult Function(Map <String,dynamic)” >,{Object?optimisticResult}),QueryResult?)'。(文档)

这是片段 - 在此输入图像描述

class GraphQlMutations {

  String createUser() { return"""
    mutation createUser(\$id: String!, \$name: String!, \$email: String!) {
      createUser(objects: [{ id: $id, name: $name, code: $code }]) {
        returning {
          id
          name
          email
        }
      }
    }
  """;
  } 
}
Run Code Online (Sandbox Code Playgroud)

dart flutter graphql-flutter

0
推荐指数
1
解决办法
750
查看次数