无法使用 QueryVariables 中的包装器向 GraphQL 发出请求

Cannot make a request to the GraphQL with the wrapper in QueryVariables

我正在尝试向 GraphQl 发出请求。我可以在操场上做。 Request in the playground

当我尝试使用 flutter 发出请求时,我无法在查询变量中创建包装器登录。 这是我在 Flutter 中的代码:

InviteCodeRepository.dart

import 'package:fauna/data/api/graphql_api_client.dart';
import 'package:get/get.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

abstract class InviteCodeRepository {
Future<void> inviteCode(String inviteCode, String phone);
}

class InviteRepositoryImplementation extends GetxController
  implements InviteCodeRepository {
String login = r'''
 mutation login($Login: Login){
login(login: $Login) {
  token
}
}

final _gqlClient = Get.put(GraphQLApiClient(), permanent: true);

@override
Future<void> inviteCode(String inviteCode, String phone) async {
  final variables = {'phone': phone, 'accessCode': inviteCode};
  final QueryResult result = await _gqlClient.mutation(
    login,
    variables: variables,
  );
  print(result.data);
}
}

以下是对我有用的方法: InviteCodeRepository.dart

import 'package:fauna/data/api/graphql_api_client.dart';
import 'package:fauna/data/api/graphql_configuration.dart';
import 'package:get/get.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

class InviteRepositoryImplementation extends GetxController
    implements InviteCodeRepository {
  String _loginError = "";
  String login = r'''
  mutation login($Login: Login){
  login(login: $Login) {
    token
  }
}
  ''';

final _gqlClient = Get.put(GraphQLApiClient(), permanent: true);

Future<QueryResult> _logIn(String accessCode, String phone) async {
    final loginData = {'phone': phone, 'accessCode': accessCode};
    final variables = {'Login': loginData};
    final QueryResult result = await _gqlClient.mutation(
      login,
      variables: variables,
    );
    return result;
  }