Skip to content

fixes function_typed_parameter_var #16

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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ ios/.generated/
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.*
.flutter-plugins
example/.flutter-plugins-dependencies
example/ios/Flutter/flutter_export_environment.sh
3 changes: 0 additions & 3 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linter:
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as
# - avoid_bool_literals_in_conditional_expressions # not yet tested
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
Expand Down Expand Up @@ -78,7 +77,6 @@ linter:
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_bool_in_asserts
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
Expand All @@ -105,7 +103,6 @@ linter:
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
# - type_annotate_public_apis # subset of always_specify_types
Expand Down
3 changes: 0 additions & 3 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linter:
- always_specify_types
- annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as
# - avoid_bool_literals_in_conditional_expressions # not yet tested
# - avoid_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly
Expand Down Expand Up @@ -78,7 +77,6 @@ linter:
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
- prefer_asserts_in_initializer_lists
- prefer_bool_in_asserts
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_const_constructors
Expand All @@ -105,7 +103,6 @@ linter:
- slash_for_doc_comments
- sort_constructors_first
- sort_unnamed_constructors_first
- super_goes_last
- test_types_in_equals
- throw_in_finally
# - type_annotate_public_apis # subset of always_specify_types
Expand Down
3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ dev_dependencies:

flutter:
uses-material-design: true

environment:
sdk: ">=2.10.0 <3.0.0"
25 changes: 10 additions & 15 deletions lib/flutter_graphql.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
library flutter_graphql;

export 'package:flutter_graphql/src/graphql_client.dart';
export 'package:flutter_graphql/src/socket_client.dart';

export 'package:flutter_graphql/src/cache/in_memory.dart';
export 'package:flutter_graphql/src/cache/normalized_in_memory.dart';
export 'package:flutter_graphql/src/core/graphql_error.dart';
export 'package:flutter_graphql/src/core/query_options.dart';
export 'package:flutter_graphql/src/core/query_result.dart';
export 'package:flutter_graphql/src/core/graphql_error.dart';

export 'package:flutter_graphql/src/link/link.dart';
export 'package:flutter_graphql/src/graphql_client.dart';
export 'package:flutter_graphql/src/link/fetch_result.dart';
export 'package:flutter_graphql/src/link/http/link_http.dart';
export 'package:flutter_graphql/src/link/link.dart';
export 'package:flutter_graphql/src/link/operation.dart';
export 'package:flutter_graphql/src/link/fetch_result.dart';

export 'package:flutter_graphql/src/cache/in_memory.dart';
export 'package:flutter_graphql/src/cache/normalized_in_memory.dart';

export 'package:flutter_graphql/src/socket_client.dart';
export 'package:flutter_graphql/src/websocket/messages.dart';
export 'package:flutter_graphql/src/websocket/socket.dart';

export 'package:flutter_graphql/src/widgets/graphql_provider.dart';
export 'package:flutter_graphql/src/widgets/graphql_consumer.dart';
export 'package:flutter_graphql/src/widgets/cache_provider.dart';
export 'package:flutter_graphql/src/widgets/query.dart';
export 'package:flutter_graphql/src/widgets/graphql_consumer.dart';
export 'package:flutter_graphql/src/widgets/graphql_provider.dart';
export 'package:flutter_graphql/src/widgets/mutation.dart';
export 'package:flutter_graphql/src/widgets/query.dart';
export 'package:flutter_graphql/src/widgets/subscription.dart';
3 changes: 1 addition & 2 deletions lib/src/cache/cache.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
abstract class Cache {
Future<bool> remove(String key, bool cascade) async {}
Future<bool>? remove(String key, bool cascade);

dynamic read(String key) {}

Expand All @@ -13,5 +13,4 @@ abstract class Cache {
void restore() {}

void reset() {}

}
6 changes: 3 additions & 3 deletions lib/src/cache/in_memory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class InMemoryCache implements Cache {
/// A directory to be used for storage.
/// This is used for testing, on regular usage
/// 'path_provider' will provide the storage directory.
final Directory customStorageDirectory;
final Directory? customStorageDirectory;

HashMap<String, dynamic> _inMemoryCache = HashMap<String, dynamic>();
bool _writingToStorage = false;
Expand Down Expand Up @@ -64,7 +64,7 @@ class InMemoryCache implements Cache {
Future<String> get _localStoragePath async {
if (customStorageDirectory != null) {
// Used for testing
return customStorageDirectory.path;
return customStorageDirectory!.path;
}

final Directory directory = await getApplicationDocumentsDirectory();
Expand Down Expand Up @@ -139,7 +139,7 @@ class InMemoryCache implements Cache {
}

@override
Future<bool> remove(String key, bool cascade) {
Future<bool>? remove(String key, bool cascade) {
// TODO: implement remove
return null;
}
Expand Down
11 changes: 3 additions & 8 deletions lib/src/cache/normalized/record_field_json_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@ import 'dart:convert';
import 'dart:core';

class RecordFieldJsonAdapter {

static RecordFieldJsonAdapter create() {
return new RecordFieldJsonAdapter();
}

RecordFieldJsonAdapter() {
return RecordFieldJsonAdapter();
}

dynamic toJson(Map<String, dynamic> fields) {
assert(fields != null);
return json.encode(fields);
}

Map<String, Object> from(dynamic jsonObj) {
Map<String, Object>? from(dynamic jsonObj) {
assert(jsonObj != null);
return json.decode(jsonObj);
}
Expand All @@ -27,4 +22,4 @@ class RecordFieldJsonAdapter {
return cacheJsonStreamReader.toMap();
}
*/
}
}
28 changes: 16 additions & 12 deletions lib/src/cache/normalized/sql/sql-normalized-cache.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:collection';

import 'package:flutter_graphql/src/cache/normalized/record_field_json_adapter.dart';
Expand All @@ -7,33 +8,33 @@ import 'package:sqflite/sqflite.dart';
import '../../cache.dart';

class SqlNormalizedCache implements Cache {

SqlNormalizedCache(this.dbHelper, this.recordFieldAdapter) {
dbHelper.open();
database = dbHelper.db;
}

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;
Database? database;
final SqlHelper dbHelper;
final allColumns = [
SqlHelper.COLUMN_ID,
SqlHelper.COLUMN_KEY,
SqlHelper.COLUMN_RECORD];
SqlHelper.COLUMN_ID,
SqlHelper.COLUMN_KEY,
SqlHelper.COLUMN_RECORD
];
final RecordFieldJsonAdapter recordFieldAdapter;
HashMap<String, dynamic> _inMemoryCache = HashMap<String, dynamic>();

@override
Object read(String key) {
Object? read(String key) {
// TODO: implement read
return null;
}

Future<List<HashMap<String, dynamic>>> _readFromStorage() async {
List<HashMap<String, dynamic>> records = await database.query(SqlHelper.TABLE_RECORDS);
List<HashMap<String, dynamic>> records = await (database!.query(SqlHelper.TABLE_RECORDS) as FutureOr<List<HashMap<String, dynamic>>>);
return records;
}

Expand All @@ -54,14 +55,17 @@ class SqlNormalizedCache implements Cache {

@override
void write(String key, dynamic values) {
database.insert(SqlHelper.TABLE_RECORDS, values);
database!.insert(SqlHelper.TABLE_RECORDS, values);
}

@override
Future<bool> remove(String key, bool cascade) async {
assert(key != null);
final deletedObj = await database.delete(SqlHelper.TABLE_RECORDS, where: '${SqlHelper.COLUMN_KEY}=?', whereArgs: [key].toList());
final deletedObj = await database!.delete(SqlHelper.TABLE_RECORDS,
where: '${SqlHelper.COLUMN_KEY}=?',
whereArgs: [
key
].toList());
return true;
}

}
}
4 changes: 2 additions & 2 deletions lib/src/cache/normalized/sql/sql_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SqlHelper {
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;
Database? db;

Future open() async {
final databasesPath = await getDatabasesPath();
Expand All @@ -27,7 +27,7 @@ class SqlHelper {
}

Future close() async {
await db.close();
await db!.close();
}

}
35 changes: 18 additions & 17 deletions lib/src/cache/normalized_in_memory.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import 'package:meta/meta.dart';
import 'package:flutter_graphql/src/utilities/traverse.dart';
import 'package:flutter_graphql/src/cache/in_memory.dart';
typedef String DataIdFromObject(Object node);
import 'package:flutter_graphql/src/utilities/traverse.dart';

typedef String? DataIdFromObject(Object? node);

class NormalizationException implements Exception {
NormalizationException(this.cause, this.overflowError, this.value);

StackOverflowError overflowError;
String cause;
Object value;
Object? value;

String get message => cause;
}

class NormalizedInMemoryCache extends InMemoryCache {
NormalizedInMemoryCache({
@required this.dataIdFromObject,
required this.dataIdFromObject,
String prefix = '@cache/reference',
}) : _prefix = prefix;

DataIdFromObject dataIdFromObject;
String _prefix;

Object _dereference(Object node) {
Object? _dereference(Object? node) {
if (node is List && node.length == 2 && node[0] == _prefix) {
return read(node[1]);
}
Expand All @@ -36,7 +36,7 @@ class NormalizedInMemoryCache extends InMemoryCache {
*/
@override
dynamic read(String key) {
final Object value = super.read(key);
final Object? value = super.read(key);

try {
return traverse(value, _dereference);
Expand All @@ -54,12 +54,15 @@ class NormalizedInMemoryCache extends InMemoryCache {
}
}

List<String> _normalize(Object node) {
final String dataId = dataIdFromObject(node);
List<String>? _normalize(Object? node) {
final String? dataId = dataIdFromObject(node);

if (dataId != null) {
write(dataId, node);
return <String>[_prefix, dataId];
return <String>[
_prefix,
dataId
];
}

return null;
Expand All @@ -70,17 +73,15 @@ class NormalizedInMemoryCache extends InMemoryCache {
replacing them with references
*/
@override
void write(String key, Object value) {
final Object normalized = traverseValues(value, _normalize);
void write(String key, Object? value) {
final Object normalized = traverseValues(Map.castFrom<String, dynamic, String, Object>(value as Map<String, dynamic>), _normalize);
super.write(key, normalized);
}
}

String typenameDataIdFromObject(Object object) {
if (object is Map<String, Object> &&
object.containsKey('__typename') &&
object.containsKey('id')) {
return "${object['__typename']}/${object['id']}";
String? typenameDataIdFromObject(Object? object) {
if (object is Map<String, Object> && object.containsKey('__typename') && object.containsKey('id')) {
return '${object['__typename']}/${object['id']}';
}

return null;
Expand Down
14 changes: 7 additions & 7 deletions lib/src/core/graphql_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class Location {
column = data['column'];

/// The line of the error in the query.
final int line;
final int? line;

/// The column of the error in the query.
final int column;
final int? column;

@override
String toString() => '{ line: $line, column: $column }';
Expand Down Expand Up @@ -42,18 +42,18 @@ class GraphQLError {
final dynamic data;

/// The message of the error.
final String message;
final String? message;

/// Locations where the error appear.
final List<Location> locations;
final List<Location>? locations;

/// The path of the field in error.
final List<dynamic> path;
final List<dynamic>? path;

/// Custom error data returned by your GraphQL API server
final Map<String, dynamic> extensions;
final Map<String, dynamic>? extensions;

@override
String toString() =>
'$message: ${locations is List ? locations.map((Location l) => '[${l.toString()}]').join('') : "Undefined location"}';
'$message: ${locations is List ? locations!.map((Location l) => '[${l.toString()}]').join('') : "Undefined location"}';
}
Loading