Closed
Description
I face an issue that my request not reach to backend... Can you help in this?
also the same subscription work in Apollo graphql website.
import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
class TrackingScreen extends StatefulWidget {
const TrackingScreen({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() {
return _TrackingScreenState();
}
}
class _TrackingScreenState extends State<TrackingScreen> {
@override
Widget build(BuildContext context) {
final httpLink = HttpLink(
'https://......',
);
final authLink = AuthLink(
getToken: () async => 'Bearer token',
);
var link = authLink.concat(httpLink);
final websocketLink = WebSocketLink(
'wss://......',
config: const SocketClientConfig(
inactivityTimeout: Duration(seconds: 30),
delayBetweenReconnectionAttempts: Duration(seconds: 10),
),
);
link = Link.split(
(request) => request.isSubscription,
websocketLink,
link,
);
final client = ValueNotifier<GraphQLClient>(
GraphQLClient(
cache: GraphQLCache(),
link: link,
),
);
return GraphQLProvider(
client: client,
child: CacheProvider(
child: Subscription(
options: SubscriptionOptions(
document: gql(
r"""subscription Tracking($frequencyInSeconds: Int!, $packageNumber: Int!) {
tracking(frequencyInSeconds: $frequencyInSeconds, packageNumber: $packageNumber) {
timestamp
}
}"""),
variables: {
"frequencyInSeconds": 3,
"packageNumber": 10,
},
operationName: 'Tracking',
),
builder: (result) => result.isLoading
? const Text('Loading...')
: Text(result.data.toString()),
),
),
);
}