hasura_connect 1.0.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 93

Hasura Connect Package #

Connect your Flutter/Dart apps to Hasura simply.

What can he do #

The hasura_connect is designed to facilitate Hasura's integration with Flutter applications, leveraging the full power of Graphql.

  • Use Query, Mutation and Subscriptions the easy way.
  • Offline cache for Subscription and Mutation made from a Snapshot.
  • Easy integration with leading dart providers (Provider, bloc_pattern).
  • Pass your JWT Token easily if you are informed when it is invalid.

Install #

Add dependency in your pubspec.yaml file:


or use Slidy:

slidy install hasura_connect

Usage #

A simple usage example:

import 'package:hasura_connect/hasura_connect.dart';

String url = 'http://localhost:8080/v1/graphql';
HasuraConnect hasuraConnect = HasuraConnect(url);

You can encapsulate this instance into a BLoC class or directly into a Provider.

Create a document with Query:

String docQuery = """
  query {
    authors {

Now just add the document to the "query" method of the HasuraConnect instance.

//get query
var r = await hasuraConnect.query(docQuery);

//get query with cache
var r = await hasuraConnect.cachedQuery(docQuery);

var r = await hasuraConnect.mutation(docQuery);

Subscriptions #

Subscriptions will notify you each time you have a change to the searched items. Use the "hasuraConnect.subscription" method to receive a stream.

Snapshot snapshot = hasuraConnect.subscription(docSubscription);
  snapshot.stream.listen((data) {
  }).onError((err) {

Subscription Converter #

Use the Map operator to convert json data to a Dart object;

Snapshot<PostModel> snapshot = hasuraConnect
                                  .convert((data) => PostModel.fromJson(data),
                                        cachePersist: (PostModel post) => post.toJson(),

snapshot.stream.listen((PostModel data) {
 }).onError((err) {

Using variables #

Variables maintain the integrity of Querys, see an example:

String docSubscription = """
  subscription algumaCoisa($limit:Int!){
    users(limit: $limit, order_by: {user_id: desc}) {

Snapshot snapshot = hasuraConnect.subscription(docSubscription, variables: {"limit": 10});

//change values of variables for PAGINATIONS
snapshot.changeVariable({"limit": 20});

Authorization (JWT Token) #

View Hasura's official Authorization documentation.

String url = 'http://localhost:8080/v1/graphql';
HasuraConnect hasuraConnect = HasuraConnect(url, token: (isError) async {
  //sharedPreferences or other storage logic
  return "Bearer YOUR-JWT-TOKEN";


  • 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.
Snapshot snapshot = connect.subscription(...);

//Add object to cache of snapshot
var list = snapshot.value;

//exec asinc mutation

Dispose #

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;

Roadmap #

This is currently our roadmap, please feel free to request additions/changes.

Change Variable in Subscriptions
Dynamic JWT Token
bloc_pattern Integration
Provider Integration
Cache Subscription
Cache Mutation
Cache Query

Features and bugs #

Please send feature requests and bugs at the issue tracker.

Created from templates made available by Stagehand under a BSD-style license.

1.0.5 #

  • Change cache engine (hive to Sharepreferences)
  • Fix id snapshot errors (uuid)

1.0.4 #

  • Update RXDART to v0.23.x

1.0.3 #

  • Fix not close snapshot error
  • improve cache.

1.0.2 #

  • Added Flutter Web Cache offline for PWA.
  • added request with variable cache.

1.0.0+2 #

  • Cache offline for Subscription and Query (CachedQuery).
  • When mutation fails due to no connection, HasuraConnect will retry when you have internet.
  • Refactored Snapshot.
  • Error Handling.

0.2.0 #

  • Added Subscription Cache.
  • fix error #9
  • fix Duplicate error
  • close streams subscriptions
  • Added isError in token Function

0.1.2 #

  • fix start stream with value

0.1.0 #

  • Mapped Subscriptions
  • Mutation in Snapshot

0.0.8 #

  • Flutter web Support.

0.0.7+1 #

  • Apply Health suggestions.

0.0.7 #

  • Add and Remove Headers

0.0.6 #

  • Added variables.
  • Change Variables in subscriptions (for Reactive Pagination)
  • Mutations links

0.0.3 #

  • Add variable;
  • Add mutation;

0.0.2 #

  • Query return param data;

0.0.1 #

  • Initial version, created by Stagehand


example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  hasura_connect: ^1.0.5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:hasura_connect/hasura_connect.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Fix lib/src/core/hasura_connect_base.dart. (-1 points)

Analysis of lib/src/core/hasura_connect_base.dart reported 2 hints:

line 343 col 33: 'close' is deprecated and shouldn't be used.

line 344 col 30: 'close' is deprecated and shouldn't be used.

Format lib/src/snapshot/snapshot_info.dart.

Run flutter format to format lib/src/snapshot/snapshot_info.dart.

Format lib/src/utils/hydrated.dart.

Run flutter format to format lib/src/utils/hydrated.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
http ^0.12.0+2 0.12.0+4
path_provider ^1.4.4 1.5.1
rxdart >=0.23.0 <1.0.0 0.23.1
shared_preferences ^0.5.6 0.5.6
uuid ^2.0.4 2.0.4
websocket ^0.0.5 0.0.5
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.4
flutter_web_plugins 0.0.0
http_parser 3.1.3
meta 1.1.8
path 1.6.4
pedantic 1.9.0
platform 2.2.1
shared_preferences_macos 0.0.1+3
shared_preferences_platform_interface 1.0.1
shared_preferences_web 0.1.2+2
sky_engine 0.0.99
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies