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

354 views Asked by At

I am trying to make a request to GraphQl. I can do it in the playground. Request in the playground

When I try to make a request using flutter, I cannot make a wrapper LogIn in Query variables. This is my code from 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);
}
}
1

There are 1 answers

0
Igor Lopatchin On BEST ANSWER

Here is what worked for me: 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;
  }