Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql): transform nested object from box #1421

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/graphql/lib/src/cache/hive_store.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';
import 'package:meta/meta.dart';

import 'package:hive/hive.dart';
import 'package:meta/meta.dart';

import './store.dart';

Expand Down Expand Up @@ -92,7 +92,15 @@ class HiveStore extends Store {
}

@override
Map<String, Map<String, dynamic>?> toMap() => Map.unmodifiable(box.toMap());
Map<String, Map<String, dynamic>?> toMap() {
final map = <String, Map<String, dynamic>?>{};
for (final key in box.keys) {
if (key is String) {
map[key] = get(key);
}
}
return Map.unmodifiable(map);
}

Future<void> reset() => box.clear();
}
22 changes: 22 additions & 0 deletions packages/graphql/test/cache/store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,28 @@ void main() {
expect(readData2?['bob'], isA<List<dynamic>>());
expect(readData2?['bob'][0], isA<Map<String, dynamic>>());
});
test("Can re-open and reference nested data", () async {
final box1 = await HiveStore.openBox(
're-open-store',
path: path,
);
final store = HiveStore(box1);
final data = {
'foo': 'bar',
'bob': [
{'nested': true}
]
};
store.put("id", data);
expect(store.toMap(), equals({'id': data}));
await box1.close();
final box2 = await HiveStore.openBox(
're-open-store',
path: path,
);
final store2 = HiveStore(box2);
expect(store2.toMap(), equals({'id': data}));
});
test("Can put null", () async {
final box1 = await HiveStore.openBox(
'put-null',
Expand Down
Loading