0

我正在尝试向 GraphQl 提出请求。我可以在操场上做。 在操场上请求

当我尝试使用颤振发出请求时,我无法在查询变量中创建包装器登录。这是我来自 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);
}
}
4

1 回答 1

0

这对我有用: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;
  }

于 2021-11-07T15:51:26.800 回答