From 7487f1f0ed6a642fb372b0a0671a00b1c2dd8369 Mon Sep 17 00:00:00 2001 From: Jacob Moura Date: Wed, 27 Nov 2019 00:00:23 -0300 Subject: [PATCH] added new version --- CHANGELOG.md | 4 ++++ README.md | 42 ++++++++++++++++++------------------------ pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4ced33..c797e85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.0-dev.1 + +- Added Mutation Cache in Snapshot. + ## 0.2.1+2 - Added Mutation Cache in Snapshot. diff --git a/README.md b/README.md index 00fb02e..076e032 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,11 @@ String docQuery = """ Now just add the document to the "query" method of the HasuraConnect instance. ```dart +//get query var r = await hasuraConnect.query(docQuery); -print(r); + +//get query with cache +var r = await hasuraConnect.cachedQuery(docQuery); //OR USE MUTATION var r = await hasuraConnect.mutation(docQuery); @@ -77,19 +80,6 @@ Snapshot snapshot = hasuraConnect.subscription(docSubscription); ``` -### Mutation + Subscriptions - -You can to use mutation directly from the subscription snapshot. This will allow you to update your local list even before it has been notified by Hasura. - -```dart -Snapshot snapshot = hasuraConnect.subscription(docSubscription); -... -snapshot.mutation(docMutation, onNotify: (data) { - return data..insert(a, {"name": "next offline item" }); -} - -``` - ### Mapped Subscription Use the Map operator to convert json data to a Dart object; @@ -137,7 +127,7 @@ snapshot.changeVariable({"limit": 20}); ```dart - String url = 'http://localhost:8080/v1/graphql'; +String url = 'http://localhost:8080/v1/graphql'; HasuraConnect hasuraConnect = HasuraConnect(url, token: (isError) async { //sharedPreferences or other storage logic return "Bearer YOUR-JWT-TOKEN"; @@ -147,23 +137,27 @@ HasuraConnect hasuraConnect = HasuraConnect(url, token: (isError) async { ## CACHE OFFLINE -Offline caching works with subscriptions automatically. -To use Mutation caching, use the Snapshot object property. +- Offline caching works with subscriptions automatically. +- A good strategy for mutation caching is to add the offline object to the snapshot with the add parameter with what will be the change, then perform the mutation. +- When a mutation internet error occurs, HasuraConnect will attempt to mutate again when the device reconnects to the internet. +- Use this information to promote your offline persistence rules. + ``` dart Snapshot snapshot = connect.subscription(...); -//Mutation cache works! -snapshot.mutation(...); - -//Mutation cache not works -connect.mutation(...); +//Add object to cache of snapshot +var list = snapshot.value; +list.add(newItem); +snapshot.add(newItem); +//exec asinc mutation +conn.mutation(...); ``` ## Dispose -HasuraConnect provides a dispose () method for use in Provider or BlocProvider. +HasuraConnect provides a dispose() method for use in Provider or BlocProvider. Subscription will start only when someone is listening, and when all listeners are closed HasuraConnect automatically disconnects. Therefore, we only connect to Hasura when we are actually using it; @@ -185,7 +179,7 @@ This is currently our roadmap, please feel free to request additions/changes. | Variables | ✅ | | Cache Subscription | ✅ | | Cache Mutation | ✅ | -| Cache Query | 🔜 | +| Cache Query | ✅ | ## Features and bugs diff --git a/pubspec.yaml b/pubspec.yaml index 87368be..c0f2c31 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: hasura_connect description: Connect your Flutter/Dart apps to Hasura simply. All the power of GraphQL and Postgres in Flutter -version: 0.2.1+2 +version: 1.0.0-dev.1 homepage: https://github.com/Flutterando/hasura_connect author: Team Flutterando