zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.23k stars 613 forks source link

Null check operator used on a null value in SocketClient.onConnectionLost #1379

Open vytautas-pranskunas- opened 10 months ago

vytautas-pranskunas- commented 10 months ago

my error logger reports follwoing error:

_TypeError

websocket_client.dart in SocketClient.onConnectionLost

Ongoing
Level: Error
Null check operator used on a null value
websocket_client.dart in SocketClient.onConnectionLost at line 371 within graphql
In App
websocket_client.dart in SocketClient._connect at line 365 within graphql
priyanshnama commented 6 months ago

can i work on this

WieFel commented 2 months ago

I have the same problem on Android (API 34). It crashes even the whole emulator at app start. On web and even iOS, my code works fine.

E/flutter ( 4262): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
E/flutter ( 4262): #0      SocketClient.onConnectionLost (package:graphql/src/links/websocket_link/websocket_client.dart:375:29)
E/flutter ( 4262): #1      SocketClient._connect (package:graphql/src/links/websocket_link/websocket_client.dart:369:7)
E/flutter ( 4262): <asynchronous suspension>

My client initialisation code looks like this:

final errorLink = ErrorLink(
  onException: (request, forward, exception) {
    logger.e(exception);
    return null;
  },
);

final WebSocketLink websocketLink = WebSocketLink(
  websocketBackendUrl,
  config: SocketClientConfig(
      autoReconnect: true,
      inactivityTimeout: const Duration(seconds: 30),
      initialPayload: () async {
        // ... some authentication logic
      }),
  subProtocol: GraphQLProtocol.graphqlTransportWs,
);

Link link = errorLink.concat(websocketLink);

return GraphQLClient(
  link: link,
  cache: GraphQLCache(store: InMemoryStore()),
  defaultPolicies: DefaultPolicies(
    query: Policies(fetch: FetchPolicy.noCache),
    mutate: Policies(fetch: FetchPolicy.noCache),
  ),
);

The error occurres even when using version 5.2.0-beta.7 of the package (#1410).