From 75a18e10908a8188f8c8a93b7d4a6a8340d4ed08 Mon Sep 17 00:00:00 2001 From: Rex Momoh Date: Mon, 11 Feb 2019 22:16:49 +0100 Subject: [PATCH 1/3] updated readme --- .all-contributorsrc | 18 ++++++++++++++++-- README.md | 37 +++++++++++++++++++------------------ pubspec.yaml | 2 +- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 9c15168c9..5f93c0198 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1,6 +1,6 @@ { - "projectName": "graphql-flutter", - "projectOwner": "zino-app", + "projectName": "flutter-graphql", + "projectOwner": "juicycleff", "repoType": "github", "repoHost": "https://github.com", "files": [ @@ -9,6 +9,20 @@ "imageSize": 100, "commit": true, "contributors": [ + { + "login": "juicycleff", + "name": "Rex Raphael", + "avatar_url": "https://avatars2.githubusercontent.com/u/4757453?v=4", + "profile": "http://rexraphael.com", + "contributions": [ + "bug", + "code", + "doc", + "example", + "ideas", + "review" + ] + }, { "login": "eusdima", "name": "Eustatiu Dima", diff --git a/README.md b/README.md index 163d0e684..474ab1ed6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# GraphQL Flutter +# Flutter GraphQL [![version][version-badge]][package] [![MIT License][license-badge]][license] @@ -10,7 +10,7 @@ ## Table of Contents -- [GraphQL Flutter](#graphql-flutter) +- [Flutter GraphQL](#flutter-graphql) - [Table of Contents](#table-of-contents) - [About this project](#about-this-project) - [Installation](#installation) @@ -25,7 +25,7 @@ - [Roadmap](#roadmap) - [Contributing](#contributing) - [New Contributors](#new-contributors) - - [Base Contributors](#base-contributors) + - [Founding Contributors](#founding-contributors) ## About this project @@ -35,6 +35,10 @@ This project combines the benefits of GraphQL with the benefits of `Streams` in The project took inspriation from the [Apollo GraphQL client](https://github.com/apollographql/apollo-client), great work guys! +**Note: Still in alpha** + +**Docs is coming soon** + ## Installation First depend on the library by adding this to your packages `pubspec.yaml`: @@ -333,22 +337,19 @@ This is currently our roadmap, please feel free to request additions/changes. | Optimistic results | πŸ”œ | | Client state management | πŸ”œ | | Modularity | πŸ”œ | +| Documentation | πŸ”œ | ## Contributing -Feel free to open a PR with any suggestions! We'll be actively working on the library ourselves. +Feel free to open a PR with any suggestions! We'll be actively working on the library ourselves. If you need control to the repo, please contact me Rex Raphael ## New Contributors -This package was originally created and published by the engineers at [Zino App BV](https://zinoapp.com). Since then the community has helped to make it even more useful for even more developers. - -Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): - -Coming soon +This package was originally created and published by the engineers at [Zino App BV](https://zinoapp.com) and with contributions from the community. However the original project has been un-maintained for months and I choose to maintain and keep this project running with other developers. -## Base Contributors +| [
Eustatiu Dima](http://rexraphael.com)
[πŸ›](https://github.com/juicycleff/graphql-flutter/issues?q=author%3Ajuicycleff "Bug reports") [πŸ’»](https://github.com/juicycleff/graphql-flutter/commits?author=eusdima "Code") [πŸ“–](https://github.com/juicycleff/graphql-flutter/commits?author=eusdima "Documentation") [πŸ’‘](#example-eusdima "Examples") [πŸ€”](#ideas-juicycleff "Ideas, Planning, & Feedback") [πŸ‘€](#review-eusdima "Reviewed Pull Requests") | -This package was originally created and published by the engineers at [Zino App BV](https://zinoapp.com). Since then the community has helped to make it even more useful for even more developers. +## Founding Contributors Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): @@ -363,12 +364,12 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! [version-badge]: https://img.shields.io/pub/v/flutter_graphql.svg?style=flat-square -[package]: https://pub.dartlang.org/packages/flutter_graphql/versions/1.0.0-alpha.3 -[license-badge]: https://img.shields.io/github/license/zino-app/graphql-flutter.svg?style=flat-square -[license]: https://github.com/zino-app/graphql-flutter/blob/master/LICENSE +[package]: https://pub.dartlang.org/packages/flutter_graphql/versions/1.0.0-alpha.12 +[license-badge]: https://img.shields.io/github/license/juicycleff/graphql-flutter.svg?style=flat-square +[license]: https://github.com/juicycleff/graphql-flutter/blob/master/LICENSE [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square [prs]: http://makeapullrequest.com -[github-watch-badge]: https://img.shields.io/github/watchers/zino-app/graphql-flutter.svg?style=social -[github-watch]: https://github.com/zino-app/graphql-flutter/watchers -[github-star-badge]: https://img.shields.io/github/stars/zino-app/graphql-flutter.svg?style=social -[github-star]: https://github.com/zino-app/graphql-flutter/stargazers +[github-watch-badge]: https://img.shields.io/github/watchers/juicycleff/graphql-flutter.svg?style=social +[github-watch]: https://github.com/juicycleff/graphql-flutter/watchers +[github-star-badge]: https://img.shields.io/github/stars/juicycleff/graphql-flutter.svg?style=social +[github-star]: https://github.com/juicycleff/graphql-flutter/stargazers diff --git a/pubspec.yaml b/pubspec.yaml index b791d8334..1a990a649 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Rex Raphael - Eus Dima - Zino Hofmann -homepage: https://github.com/juicycleff/graphql-flutter/tree/master +homepage: https://github.com/juicycleff/graphql-flutter dependencies: flutter: From 2a3e6a5665621db02becba777c66a9db2287a52f Mon Sep 17 00:00:00 2001 From: Rex Momoh Date: Mon, 11 Feb 2019 22:24:20 +0100 Subject: [PATCH 2/3] updated readme --- README.md | 24 ++++++++++++------------ pubspec.yaml | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 474ab1ed6..d7a0fba6e 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ String typenameDataIdFromObject(Object object) { return null; } ``` -However note that **`graphql-flutter` does not inject __typename into operations** the way apollo does, so if you aren't careful to request them in your query, this normalization scheme is not possible. +However note that **`flutter-graphql` does not inject __typename into operations** the way apollo does, so if you aren't careful to request them in your query, this normalization scheme is not possible. ### Queries @@ -341,13 +341,13 @@ This is currently our roadmap, please feel free to request additions/changes. ## Contributing -Feel free to open a PR with any suggestions! We'll be actively working on the library ourselves. If you need control to the repo, please contact me Rex Raphael +Feel free to open a PR with any suggestions! We'll be actively working on the library ourselves. If you need control to the repo, please contact me Rex Raphael. Please fork and send your PRs to the v.1.0.0 branch. ## New Contributors This package was originally created and published by the engineers at [Zino App BV](https://zinoapp.com) and with contributions from the community. However the original project has been un-maintained for months and I choose to maintain and keep this project running with other developers. -| [
Eustatiu Dima](http://rexraphael.com)
[πŸ›](https://github.com/juicycleff/graphql-flutter/issues?q=author%3Ajuicycleff "Bug reports") [πŸ’»](https://github.com/juicycleff/graphql-flutter/commits?author=eusdima "Code") [πŸ“–](https://github.com/juicycleff/graphql-flutter/commits?author=eusdima "Documentation") [πŸ’‘](#example-eusdima "Examples") [πŸ€”](#ideas-juicycleff "Ideas, Planning, & Feedback") [πŸ‘€](#review-eusdima "Reviewed Pull Requests") | +| [
Eustatiu Dima](http://rexraphael.com)
[πŸ›](https://github.com/juicycleff/flutter-graphql/issues?q=author%3Ajuicycleff "Bug reports") [πŸ’»](https://github.com/juicycleff/flutter-graphql/commits?author=eusdima "Code") [πŸ“–](https://github.com/juicycleff/flutter-graphql/commits?author=eusdima "Documentation") [πŸ’‘](#example-eusdima "Examples") [πŸ€”](#ideas-juicycleff "Ideas, Planning, & Feedback") [πŸ‘€](#review-eusdima "Reviewed Pull Requests") | ## Founding Contributors @@ -355,21 +355,21 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds -| [
Eustatiu Dima](http://eusdima.com)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Aeusdima "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=eusdima "Code") [πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=eusdima "Documentation") [πŸ’‘](#example-eusdima "Examples") [πŸ€”](#ideas-eusdima "Ideas, Planning, & Feedback") [πŸ‘€](#review-eusdima "Reviewed Pull Requests") | [
Zino Hofmann](https://github.com/HofmannZ)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3AHofmannZ "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=HofmannZ "Code") [πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=HofmannZ "Documentation") [πŸ’‘](#example-HofmannZ "Examples") [πŸ€”](#ideas-HofmannZ "Ideas, Planning, & Feedback") [πŸš‡](#infra-HofmannZ "Infrastructure (Hosting, Build-Tools, etc)") [πŸ‘€](#review-HofmannZ "Reviewed Pull Requests") | [
Harkirat Saluja](https://github.com/jinxac)
[πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=jinxac "Documentation") [πŸ€”](#ideas-jinxac "Ideas, Planning, & Feedback") | [
Chris Muthig](https://github.com/camuthig)
[πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=camuthig "Code") [πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=camuthig "Documentation") [πŸ’‘](#example-camuthig "Examples") [πŸ€”](#ideas-camuthig "Ideas, Planning, & Feedback") | [
Cal Pratt](http://stackoverflow.com/users/3280538/flkes)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Acal-pratt "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=cal-pratt "Code") [πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=cal-pratt "Documentation") [πŸ’‘](#example-cal-pratt "Examples") [πŸ€”](#ideas-cal-pratt "Ideas, Planning, & Feedback") | [
Miroslav Valkovic-Madjer](http://madjer.info)
[πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=mmadjer "Code") | [
Aleksandar Faraj](https://github.com/AleksandarFaraj)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3AAleksandarFaraj "Bug reports") | +| [
Eustatiu Dima](http://eusdima.com)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Aeusdima "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=eusdima "Code") [πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=eusdima "Documentation") [πŸ’‘](#example-eusdima "Examples") [πŸ€”](#ideas-eusdima "Ideas, Planning, & Feedback") [πŸ‘€](#review-eusdima "Reviewed Pull Requests") | [
Zino Hofmann](https://github.com/HofmannZ)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3AHofmannZ "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=HofmannZ "Code") [πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=HofmannZ "Documentation") [πŸ’‘](#example-HofmannZ "Examples") [πŸ€”](#ideas-HofmannZ "Ideas, Planning, & Feedback") [πŸš‡](#infra-HofmannZ "Infrastructure (Hosting, Build-Tools, etc)") [πŸ‘€](#review-HofmannZ "Reviewed Pull Requests") | [
Harkirat Saluja](https://github.com/jinxac)
[πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=jinxac "Documentation") [πŸ€”](#ideas-jinxac "Ideas, Planning, & Feedback") | [
Chris Muthig](https://github.com/camuthig)
[πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=camuthig "Code") [πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=camuthig "Documentation") [πŸ’‘](#example-camuthig "Examples") [πŸ€”](#ideas-camuthig "Ideas, Planning, & Feedback") | [
Cal Pratt](http://stackoverflow.com/users/3280538/flkes)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Acal-pratt "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=cal-pratt "Code") [πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=cal-pratt "Documentation") [πŸ’‘](#example-cal-pratt "Examples") [πŸ€”](#ideas-cal-pratt "Ideas, Planning, & Feedback") | [
Miroslav Valkovic-Madjer](http://madjer.info)
[πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=mmadjer "Code") | [
Aleksandar Faraj](https://github.com/AleksandarFaraj)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3AAleksandarFaraj "Bug reports") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | -| [
Arnaud Delcasse](https://www.scity.coop)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Aadelcasse "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=adelcasse "Code") | [
Dustin Graham](https://github.com/dustin-graham)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Adustin-graham "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=dustin-graham "Code") | [
FΓ‘bio Carneiro](https://github.com/fabiocarneiro)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Afabiocarneiro "Bug reports") | [
Gregor](https://github.com/lordgreg)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Alordgreg "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=lordgreg "Code") [πŸ€”](#ideas-lordgreg "Ideas, Planning, & Feedback") | [
Kolja Esders](https://github.com/kolja-esders)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Akolja-esders "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=kolja-esders "Code") [πŸ€”](#ideas-kolja-esders "Ideas, Planning, & Feedback") | [
Michael Joseph Rosenthal](https://github.com/micimize)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Amicimize "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=micimize "Code") [πŸ“–](https://github.com/zino-app/graphql-flutter/commits?author=micimize "Documentation") [πŸ’‘](#example-micimize "Examples") [πŸ€”](#ideas-micimize "Ideas, Planning, & Feedback") [⚠️](https://github.com/zino-app/graphql-flutter/commits?author=micimize "Tests") | [
Igor Borges](http://borges.me/)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3AIgor1201 "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=Igor1201 "Code") | -| [
Rafael Ring](https://github.com/rafaelring)
[πŸ›](https://github.com/zino-app/graphql-flutter/issues?q=author%3Arafaelring "Bug reports") [πŸ’»](https://github.com/zino-app/graphql-flutter/commits?author=rafaelring "Code") | +| [
Arnaud Delcasse](https://www.scity.coop)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Aadelcasse "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=adelcasse "Code") | [
Dustin Graham](https://github.com/dustin-graham)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Adustin-graham "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=dustin-graham "Code") | [
FΓ‘bio Carneiro](https://github.com/fabiocarneiro)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Afabiocarneiro "Bug reports") | [
Gregor](https://github.com/lordgreg)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Alordgreg "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=lordgreg "Code") [πŸ€”](#ideas-lordgreg "Ideas, Planning, & Feedback") | [
Kolja Esders](https://github.com/kolja-esders)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Akolja-esders "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=kolja-esders "Code") [πŸ€”](#ideas-kolja-esders "Ideas, Planning, & Feedback") | [
Michael Joseph Rosenthal](https://github.com/micimize)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Amicimize "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=micimize "Code") [πŸ“–](https://github.com/zino-app/flutter-graphql/commits?author=micimize "Documentation") [πŸ’‘](#example-micimize "Examples") [πŸ€”](#ideas-micimize "Ideas, Planning, & Feedback") [⚠️](https://github.com/zino-app/flutter-graphql/commits?author=micimize "Tests") | [
Igor Borges](http://borges.me/)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3AIgor1201 "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=Igor1201 "Code") | +| [
Rafael Ring](https://github.com/rafaelring)
[πŸ›](https://github.com/zino-app/flutter-graphql/issues?q=author%3Arafaelring "Bug reports") [πŸ’»](https://github.com/zino-app/flutter-graphql/commits?author=rafaelring "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind are welcome! [version-badge]: https://img.shields.io/pub/v/flutter_graphql.svg?style=flat-square [package]: https://pub.dartlang.org/packages/flutter_graphql/versions/1.0.0-alpha.12 -[license-badge]: https://img.shields.io/github/license/juicycleff/graphql-flutter.svg?style=flat-square -[license]: https://github.com/juicycleff/graphql-flutter/blob/master/LICENSE +[license-badge]: https://img.shields.io/github/license/juicycleff/flutter-graphql.svg?style=flat-square +[license]: https://github.com/juicycleff/flutter-graphql/blob/master/LICENSE [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square [prs]: http://makeapullrequest.com -[github-watch-badge]: https://img.shields.io/github/watchers/juicycleff/graphql-flutter.svg?style=social -[github-watch]: https://github.com/juicycleff/graphql-flutter/watchers -[github-star-badge]: https://img.shields.io/github/stars/juicycleff/graphql-flutter.svg?style=social -[github-star]: https://github.com/juicycleff/graphql-flutter/stargazers +[github-watch-badge]: https://img.shields.io/github/watchers/juicycleff/flutter-graphql.svg?style=social +[github-watch]: https://github.com/juicycleff/flutter-graphql/watchers +[github-star-badge]: https://img.shields.io/github/stars/juicycleff/flutter-graphql.svg?style=social +[github-star]: https://github.com/juicycleff/flutter-graphql/stargazers diff --git a/pubspec.yaml b/pubspec.yaml index 1a990a649..19e70f5ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ authors: - Rex Raphael - Eus Dima - Zino Hofmann -homepage: https://github.com/juicycleff/graphql-flutter +homepage: https://github.com/juicycleff/flutter-graphql dependencies: flutter: From a51909db6ece92c800405e71ee08c65ce24a696a Mon Sep 17 00:00:00 2001 From: Rex Momoh Date: Mon, 4 Mar 2019 13:11:05 +0100 Subject: [PATCH 3/3] wip: sql normalized disk cache --- lib/src/cache/cache.dart | 1 + lib/src/cache/in_memory.dart | 6 ++ .../normalized/record_field_json_adapter.dart | 77 +++++++++++++++++++ .../normalized/sql/sql-normalized-cache.dart | 61 +++++++++++++++ lib/src/cache/normalized/sql/sql_helper.dart | 33 ++++++++ pubspec.yaml | 1 + 6 files changed, 179 insertions(+) create mode 100644 lib/src/cache/normalized/record_field_json_adapter.dart create mode 100644 lib/src/cache/normalized/sql/sql-normalized-cache.dart create mode 100644 lib/src/cache/normalized/sql/sql_helper.dart diff --git a/lib/src/cache/cache.dart b/lib/src/cache/cache.dart index a63cadc46..f209598cc 100644 --- a/lib/src/cache/cache.dart +++ b/lib/src/cache/cache.dart @@ -1,5 +1,6 @@ abstract class Cache { dynamic read(String key) {} + Future remove(String key, bool cascade) async {} void write( String key, dynamic value, diff --git a/lib/src/cache/in_memory.dart b/lib/src/cache/in_memory.dart index 6b4126364..4be115de7 100644 --- a/lib/src/cache/in_memory.dart +++ b/lib/src/cache/in_memory.dart @@ -102,4 +102,10 @@ class InMemoryCache implements Cache { return HashMap(); } } + + @override + Future remove(String key, bool cascade) { + // TODO: implement remove + return null; + } } diff --git a/lib/src/cache/normalized/record_field_json_adapter.dart b/lib/src/cache/normalized/record_field_json_adapter.dart new file mode 100644 index 000000000..797a26db6 --- /dev/null +++ b/lib/src/cache/normalized/record_field_json_adapter.dart @@ -0,0 +1,77 @@ +import 'dart:core'; + +class RecordFieldJsonAdapter { + + static RecordFieldJsonAdapter create() { + return new RecordFieldJsonAdapter(); + } + + RecordFieldJsonAdapter() { + } + + /* String toJson(Map fields) { + checkNotNull(fields, "fields == null"); + Buffer buffer = new Buffer(); + JsonWriter jsonWriter = JsonWriter.of(buffer); + jsonWriter.setSerializeNulls(true); + + try { + jsonWriter.beginObject(); + for (Map.Entry fieldEntry : fields.entrySet()) { + String key = fieldEntry.getKey(); + Object value = fieldEntry.getValue(); + jsonWriter.name(key); + writeJsonValue(value, jsonWriter); + } + jsonWriter.endObject(); + jsonWriter.close(); + return buffer.readUtf8(); + } catch (IOException e) { + // should never happen as we are working with mem buffer + throw new RuntimeException(e); + } + } + + private Map fromBufferSource(BufferedSource bufferedFieldSource) throws IOException { + final CacheJsonStreamReader cacheJsonStreamReader = + cacheJsonStreamReader(bufferedSourceJsonReader(bufferedFieldSource)); + return cacheJsonStreamReader.toMap(); + } + + public Map from(String jsonFieldSource) throws IOException { + final BufferedSource bufferSource + = Okio.buffer(Okio.source(new ByteArrayInputStream(jsonFieldSource.getBytes(Charset.defaultCharset())))); + return fromBufferSource(bufferSource); + } + + private static void writeJsonValue(Object value, JsonWriter jsonWriter) throws IOException { + if (value == null) { + jsonWriter.nullValue(); + } else if (value instanceof String) { + jsonWriter.value((String) value); + } else if (value instanceof Boolean) { + jsonWriter.value((boolean) value); + } else if (value instanceof Number) { + jsonWriter.value((Number) value); + } else if (value instanceof CacheReference) { + jsonWriter.value(((CacheReference) value).serialize()); + } else if (value instanceof List) { + jsonWriter.beginArray(); + for (Object item : (List) value) { + writeJsonValue(item, jsonWriter); + } + jsonWriter.endArray(); + } else if (value instanceof Map) { + //noinspection unchecked + Map fields = (Map) value; + jsonWriter.beginObject(); + for (Map.Entry fieldEntry : fields.entrySet()) { + jsonWriter.name(fieldEntry.getKey()); + writeJsonValue(fieldEntry.getValue(), jsonWriter); + } + jsonWriter.endObject(); + } else { + throw new RuntimeException("Unsupported record value type: " + value.getClass()); + } + } */ +} \ No newline at end of file diff --git a/lib/src/cache/normalized/sql/sql-normalized-cache.dart b/lib/src/cache/normalized/sql/sql-normalized-cache.dart new file mode 100644 index 000000000..f58dd155c --- /dev/null +++ b/lib/src/cache/normalized/sql/sql-normalized-cache.dart @@ -0,0 +1,61 @@ +import 'package:flutter_graphql/src/cache/cache.dart'; +import 'package:flutter_graphql/src/cache/normalized/sql/sql_helper.dart'; +import 'package:sqflite/sqflite.dart'; + +class SqlNormalizedCache implements Cache { + + static const String INSERT_STATEMENT = '''INSERT INTO ${SqlHelper.TABLE_RECORDS} (${SqlHelper.COLUMN_KEY},${SqlHelper.COLUMN_RECORD}) VALUES (?,?)'''; + static const String UPDATE_STATEMENT = '''UPDATE ${SqlHelper.TABLE_RECORDS} SET ${SqlHelper.COLUMN_KEY}=?, ${SqlHelper.COLUMN_RECORD}=? WHERE ${SqlHelper.COLUMN_KEY}=?'''; + + static const String DELETE_STATEMENT = '''DELETE FROM ${SqlHelper.TABLE_RECORDS} WHERE ${SqlHelper.COLUMN_KEY}=?'''; + static const String DELETE_ALL_RECORD_STATEMENT = '''DELETE FROM ${SqlHelper.TABLE_RECORDS}'''; + + Database database; + final SqlHelper dbHelper; + final allColumns = [ + SqlHelper.COLUMN_ID, + SqlHelper.COLUMN_KEY, + SqlHelper.COLUMN_RECORD]; + + SqlNormalizedCache(this.dbHelper); + + /* + private final SQLiteStatement insertStatement; + private final SQLiteStatement updateStatement; + private final SQLiteStatement deleteStatement; + private final SQLiteStatement deleteAllRecordsStatement; + private final RecordFieldJsonAdapter recordFieldAdapter;*/ + + @override + Object read(String key) { + // TODO: implement read + return null; + } + + @override + void reset() { + // TODO: implement reset + } + + @override + void restore() { + // TODO: implement restore + } + + @override + void save() { + // TODO: implement save + } + + @override + void write(String key, value) { + // TODO: implement write + } + + @override + Future remove(String key, bool cascade) { + // TODO: implement remove + return null; + } + +} \ No newline at end of file diff --git a/lib/src/cache/normalized/sql/sql_helper.dart b/lib/src/cache/normalized/sql/sql_helper.dart new file mode 100644 index 000000000..86820f87a --- /dev/null +++ b/lib/src/cache/normalized/sql/sql_helper.dart @@ -0,0 +1,33 @@ +import 'package:path/path.dart'; +import 'package:sqflite/sqflite.dart'; + +class SqlHelper { + + static const String TABLE_RECORDS = 'records'; + static const String COLUMN_ID = '_id'; + static const String COLUMN_RECORD = 'record'; + static const String COLUMN_KEY = 'key'; + + static const String DATABASE_NAME = 'graphql-flutter.db'; + static const int DATABASE_VERSION = 1; + + static const String DATABASE_CREATE = '''CREATE TABLE $TABLE_RECORDS ($COLUMN_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COLUMN_KEY TEXT NOT NULL, $COLUMN_RECORD TEXT NOT NULL'''; + static const String IDX_RECORDS_KEY = 'idx_records_key'; + static const String CREATE_KEY_INDEX = '''CREATE INDEX $IDX_RECORDS_KEY ON $TABLE_RECORDS ($COLUMN_KEY)'''; + + Database db; + + Future open() async { + final databasesPath = await getDatabasesPath(); + String path = join(databasesPath, DATABASE_NAME); + db = await openDatabase(path, version: DATABASE_VERSION, onCreate: (Database db, int version) async { + await db.execute(DATABASE_CREATE); + await db.execute(CREATE_KEY_INDEX); + }); + } + + Future close() async { + await db.close(); + } + +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 19e70f5ab..2650831bc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: path_provider: ^0.4.1 uuid: ^1.0.3 graphql_parser: ^1.1.1 + sqflite: ^1.1.0 dev_dependencies: flutter_test: