Skip to content

Commit

Permalink
added new version
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Moura authored and Jacob Moura committed Nov 27, 2019
1 parent 2bc71ce commit 7487f1f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 4 additions & 0 deletions 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.
Expand Down
42 changes: 18 additions & 24 deletions README.md
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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";
Expand All @@ -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;
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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 <jacobaraujo7@gmail.com>

Expand Down

0 comments on commit 7487f1f

Please sign in to comment.