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"
}
}
}
4
what does it print to the console when you do
print(result.data)
Since i know graph likes to nest it results pretty weirdly41 mins ago
it throws error after the result, the code stops there
36 mins ago
ah ok, so your graphqlclient setup could be the issue. Can you include how you setup the graphqlclient, you can remove any sensitive urls. Also are you using graphql or graphql-flutter package?
10 mins ago
Ok I will edit and Include it, I think so too. I tested it on the local server tho, so it's fine. Im using GraphQL-Flutter, is there any difference between the two of it?
27 secs ago