flutter_universal_sync_graphql 0.1.0 copy "flutter_universal_sync_graphql: ^0.1.0" to clipboard
flutter_universal_sync_graphql: ^0.1.0 copied to clipboard

GraphQL RemoteSyncAdapter for the flutter_universal_sync family. Pulls via queries and pushes via mutations over a single GraphQL endpoint.

flutter_universal_sync_graphql #

A GraphQL RemoteSyncAdapter for the flutter_universal_sync family. GraphQL schemas differ per backend, so you supply the query/mutation builders.

Install #

dependencies:
  flutter_universal_sync_core: ^0.2.0
  flutter_universal_sync_graphql: ^0.1.0
  http: ^1.2.2

Use #

final remote = GraphQLSyncAdapter(
  endpoint: Uri.parse('https://api.example.com/graphql'),
  pullQuery: (table, since) => '''
    { $table(where: { updated_at: { _gt: "${since?.toIso8601String() ?? ''}" } }) { id name updated_at } }
  ''',
  pushMutation: (e) => switch (e.operation) {
    SyncOperation.insert => 'mutation { insert_${e.table}_one(object: ${_json(e.payload)}) { id } }',
    SyncOperation.update => 'mutation { update_${e.table}(...) { affected_rows } }',
    SyncOperation.delete => 'mutation { delete_${e.table}(...) { affected_rows } }',
  },
  headers: () => {'authorization': 'Bearer $token'},
);

Omit pushMutation for a read-only endpoint — push then raises SyncPushException. The pull result is read from data[rootKey(table)] (defaults to the table name; override rootKey when they differ).

Testing #

Unit tests use MockClient. A live pull test runs against the read-only SpaceX GraphQL API:

dart test                 # unit
dart test -t integration  # live SpaceX

License #

MIT.

0
likes
150
points
162
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

GraphQL RemoteSyncAdapter for the flutter_universal_sync family. Pulls via queries and pushes via mutations over a single GraphQL endpoint.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter_universal_sync_core, http

More

Packages that depend on flutter_universal_sync_graphql