HttpLinkParserException using GraphQL in Flutter

HttpLinkParserException using GraphQL in Flutter


0

So im trying to implement graphql in flutter, using bloc too. I think i already did all the necessary part, but when i try to hit the graphql, it return response like this

HttpLinkParserException (ResponseFormatException(originalException: FormatException: Unexpected character (at character 1)

here is my graphql function –

void _onLoginButtonPressed(
      LoginButtonPressed event, Emitter<LoginState> emit) async {
    emit(LoginLoading());
    try {
      // Define your login mutation
      final String loginMutation = '''
        mutation Login($uname: String!, $pass: String!, $idNum: String!, $deviceId: String!) {
          login(uname: $uname, pass: $pass, idNum: $idNum, deviceId: $deviceId) {
            accessToken
            refreshToken
          }
        }
      ''';

      // Define variables for your mutation
      final Map<String, dynamic> variables = {
        'uname': event.username,
        'pass': event.password,
        'idNum': event.idNum,
        'deviceId': event.deviceId,
      };

      // Execute the login mutation and get the response
      final QueryResult result = await graphQLClient.mutate(
        MutationOptions(
          document: gql(loginMutation),
          variables: variables,
        ),
      );

      if (result.hasException) {
        print(result.exception!);
      } else {
        // Extract access token and refresh token from the response
        final accessToken = result.data?['login']['accessToken'];
        final refreshToken = result.data?['login']['refreshToken'];
        emit(
            LoginSuccess(accessToken: accessToken, refreshToken: refreshToken));
      }
    } catch (e) {
      emit(LoginFailure(error: e.toString()));
    }
  }

this is the response when I try using postman

{
"data": {
"login": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVbmFtZSI6ImRlbyIsIlJlZ2lzdGVyZWRDbGFpbXMiOnsiaXNzIjoiYnJtb2JpbGUiLCJleHAiOjE2OTY5MDkwNTZ9fQ.XT57BIVfR6Ct8IIf5zHicqhwIqF_J9Ckj9FWflzQdwc",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVbmFtZSI6ImRlbyIsIlJlZ2lzdGVyZWRDbGFpbXMiOnsiaXNzIjoiYnJtb2JpbGUiLCJleHAiOjE2OTY5MjM0NTZ9fQ.MTBtgeKe9cgrPE4CnCPG7Z4vagi9_7qm4PDT4aJ6Nbo"
}
}
}


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *