You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Where `code` and `reason` are values returned from the server on connection close. There is no such code like 401 in WebSockets so you can use your custom and server code could look similar:
`onConnectionLost` function returns `Duration` which is basically `delayBetweenReconnectionAttempts` for current reconnect attempt. If duration is `null` then default `delayBetweenReconnectionAttempts` will be used. Otherwise returned value. For example upon expired auth token there is not much sense to wait after token is refreshed.
387
+
388
+
#### Handling connection manually
389
+
390
+
`toggleConnection` stream was introduced to allow connect or disconnect manually.
391
+
392
+
```dart
393
+
var toggleConnection = PublishSubject<ToggleConnectionState>;
When `disconnect` event is called `autoReconnect` stops. When `connect` is called `autoReconnect` resumes.
409
+
this is useful when for some reason you want to stop reconnection. For example when user logouts from the system and reconnection would cause auth error from server causing infinite loop.
410
+
330
411
#### Customizing WebSocket Connections
331
412
332
413
`WebSocketLink` now has an experimental `connect` parameter that can be
@@ -427,15 +508,15 @@ class _Connection {
427
508
428
509
```
429
510
430
-
2- if you need to update your socket just cancel your subscription and resubscribe again using usual way
511
+
2- if you need to update your socket just cancel your subscription and resubscribe again using usual way
431
512
and if the token changed it will be reconnect with the new token otherwise it will use the same client
if you're not providing the possible type map and introspecting the typename, the cache can't be updated.
673
+
if you're not providing the possible type map and introspecting the typename, the cache can't be updated.
593
674
594
675
## Direct Cache Access API
595
676
596
677
The [`GraphQLCache`](https://pub.dev/documentation/graphql/latest/graphql/GraphQLCache-class.html)
597
678
leverages [`normalize`] to give us a fairly apollo-ish [direct cache access] API, which is also available on `GraphQLClient`.
598
679
This means we can do [local state management] in a similar fashion as well.
599
680
600
-
The cache access methods are available on any cache proxy, which includes the `GraphQLCache` the `OptimisticProxy` passed to `update` in the `graphql_flutter``Mutation` widget, and the `client` itself.
681
+
The cache access methods are available on any cache proxy, which includes the `GraphQLCache` the `OptimisticProxy` passed to `update` in the `graphql_flutter``Mutation` widget, and the `client` itself.
601
682
> **NB** counter-intuitively, you likely never want to use use direct cache access methods directly on the `cache`,
602
-
> as they will not be rebroadcast automatically.
683
+
> as they will not be rebroadcast automatically.
603
684
> **Prefer `client.writeQuery` and `client.writeFragment` to those on the `client.cache` for automatic rebroadcasting**
604
685
605
686
In addition to this overview, a complete and well-commented rundown of can be found in the
@@ -641,10 +722,10 @@ final data = client.readQuery(queryRequest);
641
722
client.writeQuery(queryRequest, data);
642
723
```
643
724
644
-
The cache access methods are available on any cache proxy, which includes the `GraphQLCache` the `OptimisticProxy` passed to `update` in the `graphql_flutter``Mutation` widget, and the `client` itself.
645
-
> **NB** counter-intuitively, you likely never want to use use direct cache access methods on the cache
725
+
The cache access methods are available on any cache proxy, which includes the `GraphQLCache` the `OptimisticProxy` passed to `update` in the `graphql_flutter``Mutation` widget, and the `client` itself.
726
+
> **NB** counter-intuitively, you likely never want to use use direct cache access methods on the cache
646
727
cache.readQuery(queryRequest);
647
-
client.readQuery(queryRequest); //
728
+
client.readQuery(queryRequest); //
648
729
649
730
### `FragmentRequest`, `readFragment`, and `writeFragment`
650
731
`FragmentRequest` has almost the same api as `Request`, but is provided directly from `graphql` for consistency.
@@ -710,7 +791,7 @@ client.query(QueryOptions(
710
791
errorPolicy: ErrorPolicy.ignore,
711
792
// ignore cache data.
712
793
cacheRereadPolicy: CacheRereadPolicy.ignore,
713
-
// ...
794
+
// ...
714
795
));
715
796
```
716
797
Defaults can also be overridden via `defaultPolices` on the client itself:
@@ -724,11 +805,11 @@ GraphQLClient(
724
805
CacheRereadPolicy.mergeOptimistic,
725
806
),
726
807
),
727
-
// ...
808
+
// ...
728
809
)
729
810
```
730
811
731
-
**[`FetchPolicy`](https://pub.dev/documentation/graphql/latest/graphql/FetchPolicy-class.html):** determines where the client may return a result from, and whether that result will be saved to the cache.
812
+
**[`FetchPolicy`](https://pub.dev/documentation/graphql/latest/graphql/FetchPolicy-class.html):** determines where the client may return a result from, and whether that result will be saved to the cache.
732
813
Possible options:
733
814
734
815
- cacheFirst: return result from cache. Only fetch from network if cached result is not available.
@@ -737,7 +818,7 @@ Possible options:
737
818
- noCache: return result from network, fail if network call doesn't succeed, don't save to cache.
738
819
- networkOnly: return result from network, fail if network call doesn't succeed, save to cache.
739
820
740
-
**[`ErrorPolicy`](https://pub.dev/documentation/graphql/latest/graphql/ErrorPolicy-class.html):** determines the level of events for errors in the execution result.
821
+
**[`ErrorPolicy`](https://pub.dev/documentation/graphql/latest/graphql/ErrorPolicy-class.html):** determines the level of events for errors in the execution result.
741
822
Possible options:
742
823
743
824
- none (default): Any GraphQL Errors are treated the same as network errors and any data is ignored from the response.
@@ -869,7 +950,7 @@ API key, IAM, and Federated provider authorization could be accomplished through
869
950
870
951
This package does not support code-generation out of the box, but [graphql_codegen](https://pub.dev/packages/graphql_codegen) does!
871
952
872
-
This package extensions on the client which takes away the struggle of serialization and gives you confidence through type-safety.
953
+
This package extensions on the client which takes away the struggle of serialization and gives you confidence through type-safety.
873
954
It is also more performant than parsing GraphQL queries at runtime.
0 commit comments