Hi, are there examples on how to setup and subscribe to graphql subscription using https://pub.dev/packages/graphql? Thanks!
Just found out myself how to do this. Use WebSocketLink instead of HttpLink:
GraphQLClient _client = GraphQLClient(
cache: InMemoryCache(),
link: WebSocketLink(url: "ws://foo.bar"),
);
final QueryOptions options = QueryOptions(
documentNode: gql(<insert subcription query here>),
variables: <insert optional variables here>,
);
final Operation operation = Operation.fromOptions(options);
final Stream<FetchResult> result = _client.subscribe(operation);
Hope this helps you in the right direction.
@phijma thanks!
Also note that on v4 it is important to split links by type: link = Link.split((request) => request.isSubscription, websocketLink, link);
see: https://github.com/zino-app/graphql-flutter/tree/beta/packages/graphql#composing-links
Most helpful comment
Just found out myself how to do this. Use
WebSocketLinkinstead ofHttpLink:Hope this helps you in the right direction.