Skip to content

Cannot initiate connection to backend #1222

Closed
@MagedAlNaamani

Description

@MagedAlNaamani

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()),
        ),
      ),
    );
  }

Metadata

Metadata

Labels

⌛ reproduction neededIssue is subtle and requires a true accessible reproduction to debug⚡ websocketWeb Socket RelatedPriority: Waiting to be assignedTo be inside the next release process, it need to be marked with some level of priorityneeds more infoMore information is required

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions