gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
602 stars 116 forks source link

Subscription Dependencies Missing #485

Closed krejko closed 1 year ago

krejko commented 1 year ago

I am trying to follow the examples linked to in this issue: https://github.com/gql-dart/ferry/issues/387

However, this appears to require the GraphQL flutter package in order to have access to the WebSocketLink class.

Whenever I run flutter pub add graphql to get this package, I get the following error:

Because graphql >=4.0.3-alpha.1 <5.0.1-beta.1 depends on rxdart ^0.26.0 and graphql <1.0.0 requires SDK version >=1.19.0 <2.0.0, graphql <1.0.0-∞ or >=4.0.3-alpha.1 <5.0.1-beta.1 requires rxdart ^0.26.0.
And because graphql >=1.0.0 <4.0.0-alpha.0 depends on mime ^0.9.6+2 and graphql >=4.0.0-alpha.0 <4.0.3-alpha.1 depends on http ^0.12.1, graphql <5.0.1-beta.1 requires rxdart ^0.26.0 or mime ^0.9.6+2 or http ^0.12.1.
And because graphql >=5.0.0-nullsafety.5 <5.1.2-beta.5 depends on gql ^0.13.0 and graphql >=5.1.2-beta.5 depends on normalize ^0.7.1, every version of graphql requires normalize ^0.7.1 or rxdart ^0.26.0 or mime ^0.9.6+2 or http ^0.12.1 or gql ^0.13.0.
And because ferry >=0.13.0 <0.14.0-dev.4 depends on normalize ^0.8.0 and ferry >=0.11.0-dev.0 depends on gql ^0.14.0, if ferry >=0.13.0 <0.14.0-dev.4 and graphql any then rxdart ^0.26.0 or mime ^0.9.6+2 or http ^0.12.1.
And because build_runner >=2.0.0 <2.4.0 depends on mime ^1.0.0 and build_runner >=2.4.0 requires SDK version >=3.0.0-134.0.dev <4.0.0, if ferry >=0.13.0 <0.14.0-dev.4 and graphql any and build_runner >=2.0.0 then rxdart ^0.26.0 or http ^0.12.1.
And because ferry_hive_store >=0.4.3 depends on rxdart ^0.27.1 and frontend depends on http ^0.13.5, one of ferry >=0.13.0 <0.14.0-dev.4 or graphql any or build_runner >=2.0.0 or ferry_hive_store >=0.4.3 must be false.
And because frontend depends on both ferry ^0.13.0 and ferry_hive_store ^0.5.0, graphql is incompatible with build_runner >=2.0.0.
So, because frontend depends on both graphql any and build_runner ^2.3.3, version solving failed.
pub finished with exit code 65

It would seem as though Ferry has updated past the point where it can still be used with the GraphQL flutter library. Is there anything that can be done on my end to get past this issue, or based on this are subscriptions now unavailable when using Ferry?

Any help would be appreciated. Thanks!

knaeckeKami commented 1 year ago

You don't need a dependency on graphql, gql_websocket_link provides the link you need

knaeckeKami commented 1 year ago

But if you want to use a link from the graphql package, you can add a dependency override on normalize

krejko commented 1 year ago

Thank you, trying the gql_websocket_link package now instead of graphql 🙏

krejko commented 1 year ago

gql_wbsocket_link package does solve the error around the missing WebSocketLink class. However, I am unsure how to use this link with my client. In the linked graphql documentation they do something like

/// subscriptions must be split otherwise `HttpLink` will. swallow them
if (websocketEndpoint != null){
  final _wsLink = WebSocketLink(websockeEndpoint);
  _link = Link.split((request) => request.isSubscription, _wsLink, _link);
}

However, the request object doesn't have a isSubscription property or method. Is the idea that I'd have two different clients with Ferry; one for HTTP and another for WS? Or is there some other way run the above check?

krejko commented 1 year ago

There very well may be a better way to do this, but possibly something like this would work in the short-term:

    final link = Link.split((request) {
      return request.operation
          .toString()
          .toLowerCase()
          .contains("subscription");
    }, wsLink, httpLink);
knaeckeKami commented 1 year ago

yes, there are better ways which are not documented at the moment. see:

https://github.com/gql-dart/gql/issues/360

krejko commented 1 year ago

Thank you. This has been extremely helpful.