Unable to retrieve errors occured in Graphql mutation in flutter project

Issue

I am using the package graphql_flutter for GraphQL operations in my flutter app. The queries and mutations are going well but I cannot retrieve the errors by following the ways mentioned in their doc. Every time I receive a generic error message which is,

ClientException: Failed to connect to http://127.0.0.1:3006/graphql: 

That I get by doing,

print(result.exception.toString());

My mutation looks like,

final MutationOptions mutationOptions = MutationOptions(
  documentNode: gql(mutationString),
  variables: vars
);

final QueryResult result = await _instance._client.mutate(mutationOptions);

if (result.hasException) {
  // none of the following prints the expected error.
  print(result.exception.clientException.message);
  print(result.exception.graphqlErrors);
  print(result.exception.toString());
}

print(result.data);

return result.data;

Whereas in the apollo client, My error is :

{
  "errors": [
    {
      "message": "Invalid Phone number provided",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "otp"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
         ....

But I get none of that.

Note: The success response is coming as expected. I would like to know how can I get the graphql errors.

Solution

I found the problem. It is because android cannot connect to 127.0.0.1 or localhost from the emulator. I replaced the host with my local IP address and it is working fine now.

Answered By – Anik

Answer Checked By – Pedro (FlutterFixes Volunteer)

Leave a Reply

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