better naming on test and avoid type error
MODIFY
lib/src/cache/in_memory.dart
lib/src/cache/in_memory.dart
@@ -26,6 +26,7 @@ class InMemoryCache implements Cache {
void write(String key, dynamic value) {
if (_inMemoryCache.containsKey(key) &&
_inMemoryCache[key] is Map &&
+ value != null &&
value is Map) {
// Avoid overriding a superset with a subset of a field (#155)
_inMemoryCache[key].addAll(value);
@@ -72,7 +73,7 @@ class InMemoryCache implements Cache {
// Catching errors to avoid locking forever.
// Maybe the device couldn't write in the past
- // but in the future it may.
+ // but it may in the future.
try {
final File file = await _localStorageFile;
final IOSink sink = file.openWrite();

MODIFY
test/normalized_in_memory_test.dart
test/normalized_in_memory_test.dart
@@ -66,7 +66,7 @@ final Map<String, Object> updatedCOperationData = <String, Object>{
'aField': <String, Object>{'field': false}
};
-final Map<String, Object> smallerAValue = <String, Object>{
+final Map<String, Object> subsetAValue = <String, Object>{
'a': <String, Object>{
'__typename': 'A',
'id': 1,
@@ -83,7 +83,7 @@ final Map<String, Object> smallerAValue = <String, Object>{
},
};
-final Map<String, Object> updatedAOperationData = <String, Object>{
+final Map<String, Object> updatedSubsetOperationData = <String, Object>{
'a': <String, Object>{
'__typename': 'A',
'id': 1,
@@ -121,9 +121,9 @@ void main() {
expect(cache.read(rawOperationKey), equals(updatedCOperationData));
});
- test('updating smaller query does not override bigger query', () {
- cache.write('anotherKey', smallerAValue);
- expect(cache.read(rawOperationKey), equals(updatedAOperationData));
+ test('updating subset query does not override superset query', () {
+ cache.write('anotherUnrelatedKey', subsetAValue);
+ expect(cache.read(rawOperationKey), equals(updatedSubsetOperationData));
});
});
}

better naming on test and avoid type error