Graphql-flutter: ": Undefined location" when running a manual Mutation (next branch) + Random 127.0.0.1 connections

Created on 11 Mar 2019  路  13Comments  路  Source: zino-app/graphql-flutter

Describe the bug
When running a mutation manually, I get 2 errors at different code levels:

  • SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 33860 with random port (location is: flutter_graphql/src/link/link_http.dart:85) ... this is directly related to the mutation that I'm trying to run
  • : Undefined location after getting the awaited result of the mutation. Note that my backend is on localhost.

I was trying to get to the code that caused connections to random ports, but I couldn't use the IDE to pin-point the source of the problem. Makes me wonder, why is it doing this random connection and not connecting to where it's supposed to.

To Reproduce
Steps to reproduce the behavior:

  1. Start any project that would use flutter_graphql (same exact behavior when using graphql_flutter's next branch or 1.0.0 beta)
  2. Use an HttpLink that is pointing to a fixed http://localhost:8080/v1/graphql
  3. At this point, any manual mutations I tried to run would cause the same exact error
  4. Even absolutely invalid document will also return the same error
  5. Set a break-point deeper and deeper, and eventually, you'll meet SocketException

Expected behavior
A connection is made to my GraphQL backend. Unfortunately, my backend stays still, not receiving any connection at all.

Screenshots
Here are some screens:

image

image

Desktop (please complete the following information):

  • OS: Linux Mint (based on Ubuntu)
  • Version: 19.1

Smartphone (please complete the following information):

  • Device: Emulator
  • OS: Android
  • Version: any

Additional context
I was looking at the 0.9.5 version, but there was no way to run manual Mutations.

bug released

Most helpful comment

Same Error:
graphql_flutter: ^1.0.0-beta

   final HttpLink link = HttpLink(
      uri: 'http://127.0.0.1:8000/graphql',
    );

    GraphQLClient graphQl = GraphQLClient(
      cache: InMemoryCache(),
      link: link,
    );
    String getAllCustomers = """
          query getCustomers {
            allCustomers {
              id
              name
            }
          }
        """
        .replaceAll('\n', ' ');

    QueryOptions q = QueryOptions(document: getAllCustomers);
    var result = await graphQl.query(q);
    print(result.errors);

All 13 comments

Same Error:
graphql_flutter: ^1.0.0-beta

   final HttpLink link = HttpLink(
      uri: 'http://127.0.0.1:8000/graphql',
    );

    GraphQLClient graphQl = GraphQLClient(
      cache: InMemoryCache(),
      link: link,
    );
    String getAllCustomers = """
          query getCustomers {
            allCustomers {
              id
              name
            }
          }
        """
        .replaceAll('\n', ' ');

    QueryOptions q = QueryOptions(document: getAllCustomers);
    var result = await graphQl.query(q);
    print(result.errors);

I mean, is this project still alive? At least, a quick reply would be appreciated. Thanks.

Don't think it is....https://github.com/snowballdigital/flutter-graphql but still the same problem!

This only occurs when there is an error returned in the mutation, at least with snowballdigital's fork. This catch statement breaks, as the error object is a builtin dart error that has no message getter. If there's no error, the mutation succeeds and the data is returned correctly.

This only occurs when there is an error returned in the mutation

But that doesn't explain why no connection is made to my GraphQL server, at all.

If there's no error, the mutation succeeds and the data is returned correctly.

Logically, the framework will never know if there was error unless it connects to the GraphQL first.

The main problem here is that the Flutter app using the library never connects to the actual GraphQL server; instead, it tries to connect to random ports. The question of why it does that is still not answered.

@eliezedeck I was able to connect to my server fine on both Android and iOS emulators - I'm hosting it remotely, as I was unable to get localhost binding working (in this instance, unless you have a port forwarding setup working, localhost is referring to the actual emulator). I'm fairly sure that the issue you reported happens whenever any error occurs, and we were experiencing separate issues.

Can you connect to your endpoint using just the Dart HTTP client (you may need to try 10.0.2.2 if you're on Android)? If you're unable to, the connection issue is not related to this library.

@yunyu to be clear, you were unable to connect to localhost:port, even from simulators?
This is probably mostly some kind of firewall or networking issue

The "random ports" can happen as a result of network issues. I'm investigating similar connection issues with iOS. A temporary workaround might be to use ngrok

To keep track of this, here are the environs we're trying to resolve this for:

  • [ ] android simulator - setting host to 10.0.2.2is the main candidate solution
  • [ ] android device - adb reverse should work
  • [ ] iOS device
  • [ ] iOS simulator - works for me with localhost and 127.0.0.1 localhost local in my /etc/hosts, idk if there are other configurations I needed to make

@micimize It's more of a laziness factor 馃槩 We didn't bother looking up the 10.0.2.2 and localhost difference for Android and iOS, and somehow ended up using the same one for testing.

That said, I am running into this bug (or at least a variant of it) even when there are no networking issues - errors with a status code of 400 but returning a valid GraphQL response are "eaten" with 400 Bad Request (such as Apollo syntax/data format errors).

@yunyu exception swallowing is a different issue - at least I'm going to treat it that way, it's kind of a pervasive issue atm but we've got merged changes that should make it better.

Anyways, please provide more details in #177

Just kidding, I'm dumb. This is an issue with the current next branch of this library, but not with https://github.com/snowballdigital/flutter-graphql. I just did a quick conversion between the two, and flutter_graphql worked without a SocketError while rev 89fc23c45becd9a8fb90fbede734282941ec531c of graphql_flutter did not.

So, I think @yunyu's PR fixed one root cause, and I made #212 for tracking this generally. Closing this, if y'all encounter it again please comment on #212 or make a new issue with more specific details (operation string, port server is running on, environment you're trying to connect from.

:tada: This issue has been resolved in version 1.0.0-beta.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

:tada: This issue has been resolved in version 1.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

arsen picture arsen  路  17Comments

juicycleff picture juicycleff  路  13Comments

dali546 picture dali546  路  17Comments

serendipity1004 picture serendipity1004  路  14Comments

Kyle-Mendes picture Kyle-Mendes  路  15Comments