From bb7e93a9390e24b3db6097379790725e1cd7bdfb Mon Sep 17 00:00:00 2001 From: micimize Date: Wed, 10 Feb 2021 09:36:47 -0600 Subject: [PATCH 01/42] cats: null safety --- cats/lib/src/cat_builder.dart | 14 +++--- cats/lib/src/cat_model.dart | 82 +++++++++++++++++------------------ cats/lib/src/cats_base.dart | 64 +++++++++++++-------------- cats/pubspec.yaml | 14 +++--- 4 files changed, 87 insertions(+), 87 deletions(-) diff --git a/cats/lib/src/cat_builder.dart b/cats/lib/src/cat_builder.dart index 6ce10c0a..9497921e 100644 --- a/cats/lib/src/cat_builder.dart +++ b/cats/lib/src/cat_builder.dart @@ -31,7 +31,7 @@ class CatBuilder { Scenario buildScenario(File file, Directory folder) { var doc = loadYaml( file.readAsStringSync(), - sourceUrl: file.path, + sourceUrl: Uri.parse(file.path), ); var schema; @@ -67,7 +67,7 @@ class CatBuilder { ); } - Iterable buildTests(YamlNode node, Directory folder) { + Iterable? buildTests(YamlNode? node, Directory folder) { if (node is YamlList) { return node.map((n) => buildTest(n, folder)); } @@ -110,7 +110,7 @@ class CatBuilder { ); } - Action buildAction(YamlMap node) { + Action? buildAction(YamlMap node) { if (node.containsKey('parse')) { return ParsingAction(); } @@ -135,7 +135,7 @@ class CatBuilder { return null; } - Iterable buildAssertions(YamlNode node) { + Iterable? buildAssertions(YamlNode? node) { if (node is YamlList) { return node.map((n) => buildAssertion(n)); } @@ -147,17 +147,17 @@ class CatBuilder { return null; } - Assertion buildAssertion(YamlNode node) { + Assertion? buildAssertion(YamlNode? node) { if (node is YamlMap) { if (node.containsKey('passes')) { return PassesAssertion( - passes: node['passes'] as bool, + passes: node['passes'] as bool?, ); } if (node.containsKey('syntax-error')) { return SyntaxErrorAssertion( - syntaxError: node['syntax-error'] as bool, + syntaxError: node['syntax-error'] as bool?, ); } diff --git a/cats/lib/src/cat_model.dart b/cats/lib/src/cat_model.dart index 7331ac13..8914f051 100644 --- a/cats/lib/src/cat_model.dart +++ b/cats/lib/src/cat_model.dart @@ -1,7 +1,7 @@ class Suite { - Iterable scenarios; + Iterable? scenarios; - Map errorMapping; + Map? errorMapping; Suite({ this.scenarios, @@ -10,15 +10,15 @@ class Suite { } class Scenario { - String folder; - String file; + String? folder; + String? file; - String name; + String? name; - String schema; - Map testData; + String? schema; + Map? testData; - Iterable tests; + Iterable? tests; Scenario({ this.folder, @@ -31,15 +31,15 @@ class Scenario { } class TestCase { - String name; + String? name; - String query; - String schema; - Map testData; + String? query; + String? schema; + Map? testData; - Action action; + Action? action; - Iterable assertions; + Iterable? assertions; TestCase({ this.name, @@ -56,16 +56,16 @@ abstract class Action {} class ParsingAction extends Action {} class ValidationAction extends Action { - Iterable validationRules; + Iterable validationRules; ValidationAction(this.validationRules); } class ExecutionAction extends Action { - String operationName; - Map variables; - bool validateQuery; - String testValue; + String? operationName; + Map? variables; + bool? validateQuery; + String? testValue; ExecutionAction({ this.operationName, @@ -78,7 +78,7 @@ class ExecutionAction extends Action { abstract class Assertion {} class PassesAssertion extends Assertion { - bool passes; + bool? passes; PassesAssertion({ this.passes, @@ -86,7 +86,7 @@ class PassesAssertion extends Assertion { } class SyntaxErrorAssertion extends Assertion { - bool syntaxError; + bool? syntaxError; SyntaxErrorAssertion({ this.syntaxError, @@ -94,11 +94,11 @@ class SyntaxErrorAssertion extends Assertion { } class DataAssertion extends Assertion { - Map data; + Map? data; } class ErrorCountAssertion extends Assertion { - int count; + int? count; ErrorCountAssertion({ this.count, @@ -106,9 +106,9 @@ class ErrorCountAssertion extends Assertion { } class ErrorCodeAssertion extends Assertion { - String errorCode; - Map args; - Iterable locations; + String? errorCode; + Map? args; + Iterable? locations; ErrorCodeAssertion({ this.errorCode, @@ -118,38 +118,38 @@ class ErrorCodeAssertion extends Assertion { } class ErrorContainsAssertion extends Assertion { - String error; - Iterable locations; + String? error; + Iterable? locations; } class ErrorRegexAssertion extends Assertion { - String errorRegex; - Iterable locations; + String? errorRegex; + Iterable? locations; } class ExecutionExceptionContainsAssertion extends Assertion { - String exception; + String? exception; } class ExecutionExceptionRegexAssertion extends Assertion { - String errorRegex; + String? errorRegex; } class Location { - int line; - int column; + int? line; + int? column; } class ErrorDefinition { - String message; - String specReference; - String implementationReference; + String? message; + String? specReference; + String? implementationReference; } class DriverError { - String code; - String message; - Location location; + String? code; + String? message; + Location? location; DriverError({ this.code, @@ -159,5 +159,5 @@ class DriverError { } class DriverException { - String message; + String? message; } diff --git a/cats/lib/src/cats_base.dart b/cats/lib/src/cats_base.dart index 3ff2c74e..4bb26388 100644 --- a/cats/lib/src/cats_base.dart +++ b/cats/lib/src/cats_base.dart @@ -4,28 +4,28 @@ import './cat_model.dart'; abstract class CatDriver { Doc parse({ - String source, + String? source, }); Iterable validate({ - Doc schema, - Doc query, - Iterable validationRules, + Doc? schema, + Doc? query, + Iterable? validationRules, }); execute({ - Doc schema, + Doc? schema, dynamic testData, - Doc query, - String operation, - Map variables, + Doc? query, + String? operation, + Map? variables, }); } class CatRunner { CatBuilder _builder = CatBuilder(); - CatDriver driver; - List whitelist; + CatDriver? driver; + List? whitelist; CatRunner({ this.driver, @@ -35,41 +35,41 @@ class CatRunner { void runSuite(String suitePath) { var suite = _builder.buildSuite(suitePath); - suite.scenarios.forEach(_runScenario); + suite.scenarios!.forEach(_runScenario); } void _runScenario(Scenario scenario) { - if (whitelist != null && !whitelist.contains(scenario.file)) return; + if (whitelist != null && !whitelist!.contains(scenario.file)) return; group(scenario.name, () { - scenario.tests.forEach( + scenario.tests!.forEach( (test) => _runTest(test, scenario), ); }); } void _runTest(TestCase testCase, Scenario scenario) { - var passesAssertion = testCase.assertions.firstWhere( + var passesAssertion = testCase.assertions!.firstWhere( (a) => a is PassesAssertion, orElse: () => null, - ) as PassesAssertion; - var syntaxAssertion = testCase.assertions.firstWhere( + ) as PassesAssertion?; + var syntaxAssertion = testCase.assertions!.firstWhere( (a) => a is SyntaxErrorAssertion, orElse: () => null, - ) as SyntaxErrorAssertion; - var errorCountAssertion = testCase.assertions.firstWhere( + ) as SyntaxErrorAssertion?; + var errorCountAssertion = testCase.assertions!.firstWhere( (a) => a is ErrorCountAssertion, orElse: () => null, - ) as ErrorCountAssertion; + ) as ErrorCountAssertion?; var errorCodeAssertions = - testCase.assertions.whereType(); - var errorContainsAssertion = testCase.assertions.firstWhere( + testCase.assertions!.whereType(); + var errorContainsAssertion = testCase.assertions!.firstWhere( (a) => a is ErrorContainsAssertion, orElse: () => null, - ) as ErrorContainsAssertion; - var errorRegexAssertion = testCase.assertions.firstWhere( + ) as ErrorContainsAssertion?; + var errorRegexAssertion = testCase.assertions!.firstWhere( (a) => a is ErrorRegexAssertion, orElse: () => null, - ) as ErrorRegexAssertion; + ) as ErrorRegexAssertion?; group(testCase.name, () { var queryDoc; @@ -85,7 +85,7 @@ class CatRunner { setUp(() { try { - queryDoc = driver.parse( + queryDoc = driver!.parse( source: testCase.query, ); } catch (e) { @@ -97,7 +97,7 @@ class CatRunner { if (schema != null) { try { - schemaDoc = driver.parse( + schemaDoc = driver!.parse( source: schema, ); } catch (e) { @@ -109,7 +109,7 @@ class CatRunner { ? (testCase.action as ValidationAction).validationRules : null; - validationErrors = driver.validate( + validationErrors = driver!.validate( schema: schemaDoc, query: queryDoc, validationRules: validationRules, @@ -121,12 +121,12 @@ class CatRunner { var testData = (testCase.testData ?? scenario.testData); try { - executionResult = driver.execute( + executionResult = driver!.execute( query: queryDoc, schema: schemaDoc, testData: testData != null && testData.containsKey(action.testValue) - ? testData[action.testValue] + ? testData[action.testValue!] : testData, operation: action.operationName, variables: action.variables, @@ -144,14 +144,14 @@ class CatRunner { expect(queryParsingError, isNull); }); } else { - if ((passesAssertion == null || passesAssertion.passes) && - !(syntaxAssertion != null && syntaxAssertion.syntaxError)) { + if ((passesAssertion == null || passesAssertion.passes!) && + !(syntaxAssertion != null && syntaxAssertion.syntaxError!)) { test('parses successfuly', () { expect(queryDoc, isNotNull); expect(queryParsingError, isNull); }); } - if (syntaxAssertion != null && syntaxAssertion.syntaxError) { + if (syntaxAssertion != null && syntaxAssertion.syntaxError!) { test('throws syntax error', () { expect(queryDoc, isNull); expect(queryParsingError, isNotNull); diff --git a/cats/pubspec.yaml b/cats/pubspec.yaml index 4fab83ee..979c87b7 100644 --- a/cats/pubspec.yaml +++ b/cats/pubspec.yaml @@ -1,10 +1,10 @@ name: cats description: A starting point for Dart libraries or applications. repository: https://github.com/gql-dart/gql -environment: - sdk: '>=2.7.2 <3.0.0' -dependencies: - test: ^1.6.0 -dev_dependencies: - pedantic: ^1.7.0 - yaml: ^2.1.16 +environment: + sdk: '>=2.12.0-259.9.beta <3.0.0' +dependencies: + test: ^1.16.0 +dev_dependencies: + pedantic: ^1.10.0 + yaml: ^3.0.0 From cbcf939d56546b18ba7e465cf16bb9a7847f44e8 Mon Sep 17 00:00:00 2001 From: micimize Date: Wed, 10 Feb 2021 09:39:38 -0600 Subject: [PATCH 02/42] gql: null safety --- gql/example/add_typenames.dart | 2 +- gql/example/inspect.dart | 4 +- gql/example/parse.dart | 2 +- gql/example/visit_types.dart | 2 +- gql/lib/src/ast/ast.dart | 306 +++++++++--------- gql/lib/src/ast/transformer.dart | 32 +- gql/lib/src/ast/visitor.dart | 180 +++++------ gql/lib/src/language/lexer.dart | 48 +-- gql/lib/src/language/parser.dart | 100 +++--- gql/lib/src/language/printer.dart | 68 ++-- .../src/operation/definitions/base_types.dart | 4 +- .../operation/definitions/definitions.dart | 24 +- .../src/operation/definitions/selections.dart | 40 +-- .../operation/definitions/type_resolver.dart | 6 +- gql/lib/src/operation/executable.dart | 6 +- gql/lib/src/schema/defaults.dart | 28 +- .../src/schema/definitions/base_types.dart | 26 +- .../src/schema/definitions/definitions.dart | 70 ++-- .../src/schema/definitions/type_resolver.dart | 6 +- .../src/schema/definitions/value_types.dart | 12 +- gql/lib/src/schema/schema.dart | 50 +-- .../rules/lone_schema_definition.dart | 2 +- .../rules/unique_argument_names.dart | 2 +- .../rules/unique_directive_names.dart | 6 +- .../rules/unique_enum_value_names.dart | 8 +- .../rules/unique_field_definition_names.dart | 4 +- .../rules/unique_input_field_names.dart | 2 +- .../rules/unique_operation_types.dart | 2 +- .../validation/rules/unique_type_names.dart | 6 +- gql/lib/src/validation/validator.dart | 12 +- gql/pubspec.yaml | 20 +- gql/test/lexer_test.dart | 22 +- gql/test/operation_test.dart | 6 +- gql/test/parser_test.dart | 14 +- gql/test/scenarios_test.dart | 4 +- gql/test/schema_test.dart | 42 +-- 36 files changed, 584 insertions(+), 584 deletions(-) diff --git a/gql/example/add_typenames.dart b/gql/example/add_typenames.dart index 61236769..baf67804 100644 --- a/gql/example/add_typenames.dart +++ b/gql/example/add_typenames.dart @@ -18,7 +18,7 @@ class AddTypenames extends ast.TransformingVisitor { ast.FieldNode( name: ast.NameNode(value: "__typename"), ), - ...node.selectionSet.selections + ...node.selectionSet!.selections ], ), ); diff --git a/gql/example/inspect.dart b/gql/example/inspect.dart index 85cf0d2c..12a4d1d3 100644 --- a/gql/example/inspect.dart +++ b/gql/example/inspect.dart @@ -33,7 +33,7 @@ void inspectSchema() { print(character.isImplementedBy(droid)); // prints "true" - print(schema.query.getField("droids").type.toString()); + print(schema.query!.getField("droids").type.toString()); // prints "[Droid!]" } @@ -70,7 +70,7 @@ void inspectQuery() { final query = document.operations.first; final droids = query.selectionSet.fields.first; - final spreadDroidName = droids.selectionSet.fragmentSpreads.first; + final spreadDroidName = droids.selectionSet!.fragmentSpreads.first; print( // dereference fragment spread into fragment definition diff --git a/gql/example/parse.dart b/gql/example/parse.dart index a21ad035..7990155f 100644 --- a/gql/example/parse.dart +++ b/gql/example/parse.dart @@ -14,6 +14,6 @@ void main() { ); print( - (doc.definitions.first as ast.OperationDefinitionNode).name.value, + (doc.definitions.first as ast.OperationDefinitionNode).name!.value, ); } diff --git a/gql/example/visit_types.dart b/gql/example/visit_types.dart index 7b33ed07..3540d941 100644 --- a/gql/example/visit_types.dart +++ b/gql/example/visit_types.dart @@ -31,7 +31,7 @@ void main() { print( v.types .map( - (t) => t.name.value, + (t) => t.name!.value, ) .join("\n"), ); diff --git a/gql/lib/src/ast/ast.dart b/gql/lib/src/ast/ast.dart index 58dfa342..7b2bdf73 100644 --- a/gql/lib/src/ast/ast.dart +++ b/gql/lib/src/ast/ast.dart @@ -21,11 +21,11 @@ void _visitAll( @immutable abstract class Node { /// [FileSpan] representing the location of the node in the [SourceFile] - final FileSpan span; + final FileSpan? span; const Node(this.span); - List get _children; + List get _children; /// Lets [Visitor] [v] visit children nodes of this node. void visitChildren(Visitor v) => _children.forEach( @@ -43,7 +43,7 @@ abstract class Node { if (identical(this, o)) return true; if (o.runtimeType != runtimeType) return false; - return const ListEquality( + return const ListEquality( DeepCollectionEquality(), ).equals( (o as Node)._children, @@ -52,7 +52,7 @@ abstract class Node { } @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _children, @@ -67,7 +67,7 @@ class DocumentNode extends Node { const DocumentNode({ this.definitions = const [], - FileSpan span, + FileSpan? span, }) : assert(definitions != null), super(span); @@ -81,18 +81,18 @@ class DocumentNode extends Node { } abstract class DefinitionNode extends Node { - final NameNode name; + final NameNode? name; const DefinitionNode({ - @required this.name, - FileSpan span, + required this.name, + FileSpan? span, }) : super(span); } abstract class ExecutableDefinitionNode extends DefinitionNode { const ExecutableDefinitionNode({ - @required NameNode name, - FileSpan span, + required NameNode? name, + FileSpan? span, }) : super( name: name, span: span, @@ -138,12 +138,12 @@ class OperationDefinitionNode extends ExecutableDefinitionNode { final SelectionSetNode selectionSet; const OperationDefinitionNode({ - @required this.type, - NameNode name, + required this.type, + NameNode? name, this.variableDefinitions = const [], this.directives = const [], - @required this.selectionSet, - FileSpan span, + required this.selectionSet, + FileSpan? span, }) : assert(variableDefinitions != null), assert(directives != null), assert(selectionSet != null), @@ -156,7 +156,7 @@ class OperationDefinitionNode extends ExecutableDefinitionNode { R accept(Visitor v) => v.visitOperationDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, type, selectionSet, @@ -170,7 +170,7 @@ class SelectionSetNode extends Node { const SelectionSetNode({ this.selections = const [], - FileSpan span, + FileSpan? span, }) : super(span); @override @@ -183,11 +183,11 @@ class SelectionSetNode extends Node { } abstract class SelectionNode extends Node { - const SelectionNode(FileSpan span) : super(span); + const SelectionNode(FileSpan? span) : super(span); } class FieldNode extends SelectionNode { - final NameNode alias; + final NameNode? alias; final NameNode name; @@ -195,15 +195,15 @@ class FieldNode extends SelectionNode { final List directives; - final SelectionSetNode selectionSet; + final SelectionSetNode? selectionSet; const FieldNode({ this.alias, - @required this.name, + required this.name, this.arguments = const [], this.directives = const [], this.selectionSet, - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(arguments != null), assert(directives != null), @@ -213,7 +213,7 @@ class FieldNode extends SelectionNode { R accept(Visitor v) => v.visitFieldNode(this); @override - List get _children => [ + List get _children => [ alias, name, selectionSet, @@ -228,9 +228,9 @@ class ArgumentNode extends Node { final ValueNode value; const ArgumentNode({ - @required this.name, - @required this.value, - FileSpan span, + required this.name, + required this.value, + FileSpan? span, }) : assert(name != null), assert(value != null), super(span); @@ -251,9 +251,9 @@ class FragmentSpreadNode extends SelectionNode { final List directives; const FragmentSpreadNode({ - @required this.name, + required this.name, this.directives = const [], - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(directives != null), super(span); @@ -269,7 +269,7 @@ class FragmentSpreadNode extends SelectionNode { } class InlineFragmentNode extends SelectionNode { - final TypeConditionNode typeCondition; + final TypeConditionNode? typeCondition; final List directives; @@ -278,8 +278,8 @@ class InlineFragmentNode extends SelectionNode { const InlineFragmentNode({ this.typeCondition, this.directives = const [], - @required this.selectionSet, - FileSpan span, + required this.selectionSet, + FileSpan? span, }) : assert(directives != null), assert(selectionSet != null), super(span); @@ -288,7 +288,7 @@ class InlineFragmentNode extends SelectionNode { R accept(Visitor v) => v.visitInlineFragmentNode(this); @override - List get _children => [ + List get _children => [ typeCondition, selectionSet, directives, @@ -303,11 +303,11 @@ class FragmentDefinitionNode extends ExecutableDefinitionNode { final SelectionSetNode selectionSet; const FragmentDefinitionNode({ - @required NameNode name, - @required this.typeCondition, + required NameNode name, + required this.typeCondition, this.directives = const [], - @required this.selectionSet, - FileSpan span, + required this.selectionSet, + FileSpan? span, }) : assert(name != null), assert(typeCondition != null), assert(directives != null), @@ -321,7 +321,7 @@ class FragmentDefinitionNode extends ExecutableDefinitionNode { R accept(Visitor v) => v.visitFragmentDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, typeCondition, selectionSet, @@ -333,8 +333,8 @@ class TypeConditionNode extends Node { final NamedTypeNode on; const TypeConditionNode({ - @required this.on, - FileSpan span, + required this.on, + FileSpan? span, }) : assert(on != null), super(span); @@ -348,15 +348,15 @@ class TypeConditionNode extends Node { } abstract class ValueNode extends Node { - const ValueNode(FileSpan span) : super(span); + const ValueNode(FileSpan? span) : super(span); } class VariableNode extends ValueNode { final NameNode name; const VariableNode({ - @required this.name, - FileSpan span, + required this.name, + FileSpan? span, }) : assert(name != null), super(span); @@ -373,8 +373,8 @@ class IntValueNode extends ValueNode { final String value; const IntValueNode({ - @required this.value, - FileSpan span, + required this.value, + FileSpan? span, }) : assert(value != null), super(span); @@ -391,8 +391,8 @@ class FloatValueNode extends ValueNode { final String value; const FloatValueNode({ - @required this.value, - FileSpan span, + required this.value, + FileSpan? span, }) : assert(value != null), super(span); @@ -411,9 +411,9 @@ class StringValueNode extends ValueNode { final bool isBlock; const StringValueNode({ - @required this.value, - @required this.isBlock, - FileSpan span, + required this.value, + required this.isBlock, + FileSpan? span, }) : assert(value != null), assert(isBlock != null), super(span); @@ -432,8 +432,8 @@ class BooleanValueNode extends ValueNode { final bool value; const BooleanValueNode({ - @required this.value, - FileSpan span, + required this.value, + FileSpan? span, }) : assert(value != null), super(span); @@ -448,7 +448,7 @@ class BooleanValueNode extends ValueNode { class NullValueNode extends ValueNode { const NullValueNode({ - FileSpan span, + FileSpan? span, }) : super(span); @override @@ -462,8 +462,8 @@ class EnumValueNode extends ValueNode { final NameNode name; const EnumValueNode({ - @required this.name, - FileSpan span, + required this.name, + FileSpan? span, }) : assert(name != null), super(span); @@ -481,7 +481,7 @@ class ListValueNode extends ValueNode { const ListValueNode({ this.values = const [], - FileSpan span, + FileSpan? span, }) : super(span); @override @@ -498,7 +498,7 @@ class ObjectValueNode extends ValueNode { const ObjectValueNode({ this.fields = const [], - FileSpan span, + FileSpan? span, }) : super(span); @override @@ -516,9 +516,9 @@ class ObjectFieldNode extends Node { final ValueNode value; const ObjectFieldNode({ - @required this.name, - @required this.value, - FileSpan span, + required this.name, + required this.value, + FileSpan? span, }) : assert(name != null), assert(value != null), super(span); @@ -538,16 +538,16 @@ class VariableDefinitionNode extends Node { final TypeNode type; - final DefaultValueNode defaultValue; + final DefaultValueNode? defaultValue; final List directives; const VariableDefinitionNode({ - @required this.variable, - @required this.type, + required this.variable, + required this.type, this.defaultValue, this.directives = const [], - FileSpan span, + FileSpan? span, }) : assert(variable != null), assert(type != null), assert(directives != null), @@ -557,7 +557,7 @@ class VariableDefinitionNode extends Node { R accept(Visitor v) => v.visitVariableDefinitionNode(this); @override - List get _children => [ + List get _children => [ variable, type, defaultValue, @@ -566,18 +566,18 @@ class VariableDefinitionNode extends Node { } class DefaultValueNode extends Node { - final ValueNode value; + final ValueNode? value; const DefaultValueNode({ - @required this.value, - FileSpan span, + required this.value, + FileSpan? span, }) : super(span); @override R accept(Visitor v) => v.visitDefaultValueNode(this); @override - List get _children => [ + List get _children => [ value, ]; } @@ -585,7 +585,7 @@ class DefaultValueNode extends Node { abstract class TypeNode extends Node { final bool isNonNull; - const TypeNode(this.isNonNull, FileSpan span) + const TypeNode(this.isNonNull, FileSpan? span) : assert(isNonNull != null), super(span); } @@ -594,9 +594,9 @@ class NamedTypeNode extends TypeNode { final NameNode name; const NamedTypeNode({ - @required this.name, + required this.name, bool isNonNull = false, - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(isNonNull != null), super(isNonNull, span); @@ -615,9 +615,9 @@ class ListTypeNode extends TypeNode { final TypeNode type; const ListTypeNode({ - @required this.type, - @required bool isNonNull, - FileSpan span, + required this.type, + required bool isNonNull, + FileSpan? span, }) : assert(type != null), assert(isNonNull != null), super(isNonNull, span); @@ -638,9 +638,9 @@ class DirectiveNode extends Node { final List arguments; const DirectiveNode({ - @required this.name, + required this.name, this.arguments = const [], - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(arguments != null), super(span); @@ -659,8 +659,8 @@ class NameNode extends Node { final String value; const NameNode({ - @required this.value, - FileSpan span, + required this.value, + FileSpan? span, }) : assert(value != null), super(span); @@ -675,8 +675,8 @@ class NameNode extends Node { abstract class TypeSystemDefinitionNode extends DefinitionNode { const TypeSystemDefinitionNode({ - @required NameNode name, - FileSpan span, + required NameNode? name, + FileSpan? span, }) : super( name: name, span: span, @@ -684,14 +684,14 @@ abstract class TypeSystemDefinitionNode extends DefinitionNode { } abstract class TypeDefinitionNode extends TypeSystemDefinitionNode { - final StringValueNode description; + final StringValueNode? description; final List directives; const TypeDefinitionNode({ this.description, - @required NameNode name, + required NameNode name, this.directives = const [], - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(directives != null), super( @@ -702,8 +702,8 @@ abstract class TypeDefinitionNode extends TypeSystemDefinitionNode { abstract class TypeSystemExtensionNode extends TypeSystemDefinitionNode { const TypeSystemExtensionNode({ - @required NameNode name, - FileSpan span, + required NameNode? name, + FileSpan? span, }) : super( name: name, span: span, @@ -714,8 +714,8 @@ abstract class TypeExtensionNode extends TypeSystemExtensionNode { final List directives; const TypeExtensionNode({ - FileSpan span, - @required NameNode name, + FileSpan? span, + required NameNode name, this.directives = const [], }) : assert(name != null), assert(directives != null), @@ -732,7 +732,7 @@ class SchemaDefinitionNode extends TypeSystemDefinitionNode { const SchemaDefinitionNode({ this.directives = const [], this.operationTypes = const [], - FileSpan span, + FileSpan? span, }) : assert(directives != null), assert(operationTypes != null), super( @@ -755,9 +755,9 @@ class OperationTypeDefinitionNode extends Node { final NamedTypeNode type; const OperationTypeDefinitionNode({ - @required this.operation, - @required this.type, - FileSpan span, + required this.operation, + required this.type, + FileSpan? span, }) : assert(operation != null), assert(type != null), super(span); @@ -774,10 +774,10 @@ class OperationTypeDefinitionNode extends Node { class ScalarTypeDefinitionNode extends TypeDefinitionNode { const ScalarTypeDefinitionNode({ - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(directives != null), super( @@ -791,7 +791,7 @@ class ScalarTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitScalarTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -805,10 +805,10 @@ class ObjectTypeDefinitionNode extends TypeDefinitionNode { const ObjectTypeDefinitionNode({ this.interfaces = const [], this.fields = const [], - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(interfaces != null), assert(fields != null), assert(name != null), @@ -824,7 +824,7 @@ class ObjectTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitObjectTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -834,7 +834,7 @@ class ObjectTypeDefinitionNode extends TypeDefinitionNode { } class FieldDefinitionNode extends Node { - final StringValueNode description; + final StringValueNode? description; final NameNode name; final TypeNode type; final List directives; @@ -842,11 +842,11 @@ class FieldDefinitionNode extends Node { const FieldDefinitionNode({ this.description, - @required this.name, - @required this.type, + required this.name, + required this.type, this.args = const [], this.directives = const [], - FileSpan span, + FileSpan? span, }) : assert(type != null), assert(args != null), assert(name != null), @@ -857,7 +857,7 @@ class FieldDefinitionNode extends Node { R accept(Visitor v) => v.visitFieldDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -867,19 +867,19 @@ class FieldDefinitionNode extends Node { } class InputValueDefinitionNode extends Node { - final StringValueNode description; + final StringValueNode? description; final NameNode name; final TypeNode type; - final ValueNode defaultValue; + final ValueNode? defaultValue; final List directives; const InputValueDefinitionNode({ this.description, - @required this.name, - @required this.type, + required this.name, + required this.type, this.defaultValue, this.directives = const [], - FileSpan span, + FileSpan? span, }) : assert(type != null), assert(name != null), assert(type != null), @@ -890,7 +890,7 @@ class InputValueDefinitionNode extends Node { R accept(Visitor v) => v.visitInputValueDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -904,10 +904,10 @@ class InterfaceTypeDefinitionNode extends TypeDefinitionNode { const InterfaceTypeDefinitionNode({ this.fields = const [], - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(fields != null), assert(name != null), assert(directives != null), @@ -922,7 +922,7 @@ class InterfaceTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitInterfaceTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -935,10 +935,10 @@ class UnionTypeDefinitionNode extends TypeDefinitionNode { const UnionTypeDefinitionNode({ this.types = const [], - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(types != null), assert(name != null), assert(directives != null), @@ -953,7 +953,7 @@ class UnionTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitUnionTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -966,10 +966,10 @@ class EnumTypeDefinitionNode extends TypeDefinitionNode { const EnumTypeDefinitionNode({ this.values = const [], - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(values != null), assert(name != null), assert(directives != null), @@ -984,7 +984,7 @@ class EnumTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitEnumTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -996,10 +996,10 @@ class EnumValueDefinitionNode extends TypeDefinitionNode { final bool fallback; const EnumValueDefinitionNode({ - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, this.fallback = false, }) : assert(name != null), assert(directives != null), @@ -1015,7 +1015,7 @@ class EnumValueDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitEnumValueDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -1027,10 +1027,10 @@ class InputObjectTypeDefinitionNode extends TypeDefinitionNode { const InputObjectTypeDefinitionNode({ this.fields = const [], - StringValueNode description, - @required NameNode name, + StringValueNode? description, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(fields != null), assert(name != null), assert(directives != null), @@ -1045,7 +1045,7 @@ class InputObjectTypeDefinitionNode extends TypeDefinitionNode { R accept(Visitor v) => v.visitInputObjectTypeDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, directives, @@ -1054,18 +1054,18 @@ class InputObjectTypeDefinitionNode extends TypeDefinitionNode { } class DirectiveDefinitionNode extends TypeSystemDefinitionNode { - final StringValueNode description; + final StringValueNode? description; final List args; final List locations; final bool repeatable; const DirectiveDefinitionNode({ this.description, - @required NameNode name, + required NameNode name, this.args = const [], this.locations = const [], this.repeatable = false, - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(args != null), assert(locations != null), @@ -1079,7 +1079,7 @@ class DirectiveDefinitionNode extends TypeSystemDefinitionNode { R accept(Visitor v) => v.visitDirectiveDefinitionNode(this); @override - List get _children => [ + List get _children => [ name, description, locations, @@ -1095,7 +1095,7 @@ class SchemaExtensionNode extends TypeSystemExtensionNode { const SchemaExtensionNode({ this.directives = const [], this.operationTypes = const [], - FileSpan span, + FileSpan? span, }) : assert(directives != null), assert(operationTypes != null), super( @@ -1107,7 +1107,7 @@ class SchemaExtensionNode extends TypeSystemExtensionNode { R accept(Visitor v) => v.visitSchemaExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, operationTypes, @@ -1116,8 +1116,8 @@ class SchemaExtensionNode extends TypeSystemExtensionNode { class ScalarTypeExtensionNode extends TypeExtensionNode { const ScalarTypeExtensionNode({ - FileSpan span, - @required NameNode name, + FileSpan? span, + required NameNode name, List directives = const [], }) : assert(name != null), assert(directives != null), @@ -1131,7 +1131,7 @@ class ScalarTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitScalarTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, ]; @@ -1142,10 +1142,10 @@ class ObjectTypeExtensionNode extends TypeExtensionNode { final List fields; const ObjectTypeExtensionNode({ - @required NameNode name, + required NameNode name, this.interfaces = const [], this.fields = const [], - FileSpan span, + FileSpan? span, List directives = const [], }) : assert(name != null), assert(interfaces != null), @@ -1161,7 +1161,7 @@ class ObjectTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitObjectTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, interfaces, @@ -1174,8 +1174,8 @@ class InterfaceTypeExtensionNode extends TypeExtensionNode { const InterfaceTypeExtensionNode({ this.fields = const [], - @required NameNode name, - FileSpan span, + required NameNode name, + FileSpan? span, List directives = const [], }) : assert(name != null), assert(fields != null), @@ -1190,7 +1190,7 @@ class InterfaceTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitInterfaceTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, fields, @@ -1202,9 +1202,9 @@ class UnionTypeExtensionNode extends TypeExtensionNode { const UnionTypeExtensionNode({ this.types = const [], - @required NameNode name, + required NameNode name, List directives = const [], - FileSpan span, + FileSpan? span, }) : assert(name != null), assert(types != null), assert(directives != null), @@ -1218,7 +1218,7 @@ class UnionTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitUnionTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, types, @@ -1230,8 +1230,8 @@ class EnumTypeExtensionNode extends TypeExtensionNode { const EnumTypeExtensionNode({ this.values = const [], - FileSpan span, - @required NameNode name, + FileSpan? span, + required NameNode name, List directives = const [], }) : assert(name != null), assert(values != null), @@ -1246,7 +1246,7 @@ class EnumTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitEnumTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, values, @@ -1258,8 +1258,8 @@ class InputObjectTypeExtensionNode extends TypeExtensionNode { const InputObjectTypeExtensionNode({ this.fields = const [], - FileSpan span, - @required NameNode name, + FileSpan? span, + required NameNode name, List directives = const [], }) : assert(name != null), assert(fields != null), @@ -1274,7 +1274,7 @@ class InputObjectTypeExtensionNode extends TypeExtensionNode { R accept(Visitor v) => v.visitInputObjectTypeExtensionNode(this); @override - List get _children => [ + List get _children => [ name, directives, fields, diff --git a/gql/lib/src/ast/transformer.dart b/gql/lib/src/ast/transformer.dart index 494a2c6d..84d9bc52 100644 --- a/gql/lib/src/ast/transformer.dart +++ b/gql/lib/src/ast/transformer.dart @@ -293,7 +293,7 @@ class _Transformer extends Visitor { this.visitors = const [], }); - N _visitOne( + N _visitOne( N node, ) { if (node == null) return node; @@ -379,7 +379,7 @@ class _Transformer extends Visitor { DirectiveDefinitionNode node, ) { final updatedNode = DirectiveDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), locations: node.locations, repeatable: node.repeatable, @@ -412,7 +412,7 @@ class _Transformer extends Visitor { EnumTypeDefinitionNode node, ) { final updatedNode = EnumTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), values: _visitAll(node.values), @@ -429,7 +429,7 @@ class _Transformer extends Visitor { EnumTypeExtensionNode node, ) { final updatedNode = EnumTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), values: _visitAll(node.values), ); @@ -445,7 +445,7 @@ class _Transformer extends Visitor { EnumValueDefinitionNode node, ) { final updatedNode = EnumValueDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), ); @@ -525,7 +525,7 @@ class _Transformer extends Visitor { FragmentDefinitionNode node, ) { final updatedNode = FragmentDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), selectionSet: _visitOne(node.selectionSet), typeCondition: _visitOne(node.typeCondition), @@ -573,7 +573,7 @@ class _Transformer extends Visitor { InputObjectTypeDefinitionNode node, ) { final updatedNode = InputObjectTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), fields: _visitAll(node.fields), @@ -590,7 +590,7 @@ class _Transformer extends Visitor { InputObjectTypeExtensionNode node, ) { final updatedNode = InputObjectTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), fields: _visitAll(node.fields), ); @@ -638,7 +638,7 @@ class _Transformer extends Visitor { InterfaceTypeDefinitionNode node, ) { final updatedNode = InterfaceTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), fields: _visitAll(node.fields), @@ -655,7 +655,7 @@ class _Transformer extends Visitor { InterfaceTypeExtensionNode node, ) { final updatedNode = InterfaceTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), fields: _visitAll(node.fields), ); @@ -754,7 +754,7 @@ class _Transformer extends Visitor { ObjectTypeDefinitionNode node, ) { final updatedNode = ObjectTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), fields: _visitAll(node.fields), @@ -772,7 +772,7 @@ class _Transformer extends Visitor { ObjectTypeExtensionNode node, ) { final updatedNode = ObjectTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), fields: _visitAll(node.fields), interfaces: _visitAll(node.interfaces), @@ -836,7 +836,7 @@ class _Transformer extends Visitor { ScalarTypeDefinitionNode node, ) { final updatedNode = ScalarTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), ); @@ -852,7 +852,7 @@ class _Transformer extends Visitor { ScalarTypeExtensionNode node, ) { final updatedNode = ScalarTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), ); @@ -940,7 +940,7 @@ class _Transformer extends Visitor { UnionTypeDefinitionNode node, ) { final updatedNode = UnionTypeDefinitionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), description: _visitOne(node.description), directives: _visitAll(node.directives), types: _visitAll(node.types), @@ -957,7 +957,7 @@ class _Transformer extends Visitor { UnionTypeExtensionNode node, ) { final updatedNode = UnionTypeExtensionNode( - name: _visitOne(node.name), + name: _visitOne(node.name!), directives: _visitAll(node.directives), types: _visitAll(node.types), ); diff --git a/gql/lib/src/ast/visitor.dart b/gql/lib/src/ast/visitor.dart index 17833461..b7301a1d 100644 --- a/gql/lib/src/ast/visitor.dart +++ b/gql/lib/src/ast/visitor.dart @@ -224,267 +224,267 @@ abstract class Visitor { } /// A simple implementation of [Visitor] returning `null` from each visit method. -class SimpleVisitor implements Visitor { +class SimpleVisitor implements Visitor { @override - R visitDocumentNode( + R? visitDocumentNode( DocumentNode node, ) => null; @override - R visitNameNode( + R? visitNameNode( NameNode node, ) => null; @override - R visitDirectiveNode( + R? visitDirectiveNode( DirectiveNode node, ) => null; @override - R visitListTypeNode( + R? visitListTypeNode( ListTypeNode node, ) => null; @override - R visitNamedTypeNode( + R? visitNamedTypeNode( NamedTypeNode node, ) => null; @override - R visitDefaultValueNode( + R? visitDefaultValueNode( DefaultValueNode node, ) => null; @override - R visitVariableDefinitionNode( + R? visitVariableDefinitionNode( VariableDefinitionNode node, ) => null; @override - R visitObjectFieldNode( + R? visitObjectFieldNode( ObjectFieldNode node, ) => null; @override - R visitObjectValueNode( + R? visitObjectValueNode( ObjectValueNode node, ) => null; @override - R visitListValueNode( + R? visitListValueNode( ListValueNode node, ) => null; @override - R visitEnumValueNode( + R? visitEnumValueNode( EnumValueNode node, ) => null; @override - R visitNullValueNode( + R? visitNullValueNode( NullValueNode node, ) => null; @override - R visitBooleanValueNode( + R? visitBooleanValueNode( BooleanValueNode node, ) => null; @override - R visitStringValueNode( + R? visitStringValueNode( StringValueNode node, ) => null; @override - R visitFloatValueNode( + R? visitFloatValueNode( FloatValueNode node, ) => null; @override - R visitIntValueNode( + R? visitIntValueNode( IntValueNode node, ) => null; @override - R visitVariableNode( + R? visitVariableNode( VariableNode node, ) => null; @override - R visitTypeConditionNode( + R? visitTypeConditionNode( TypeConditionNode node, ) => null; @override - R visitFragmentDefinitionNode( + R? visitFragmentDefinitionNode( FragmentDefinitionNode node, ) => null; @override - R visitInlineFragmentNode( + R? visitInlineFragmentNode( InlineFragmentNode node, ) => null; @override - R visitFragmentSpreadNode( + R? visitFragmentSpreadNode( FragmentSpreadNode node, ) => null; @override - R visitArgumentNode( + R? visitArgumentNode( ArgumentNode node, ) => null; @override - R visitFieldNode( + R? visitFieldNode( FieldNode node, ) => null; @override - R visitSelectionSetNode( + R? visitSelectionSetNode( SelectionSetNode node, ) => null; @override - R visitOperationDefinitionNode( + R? visitOperationDefinitionNode( OperationDefinitionNode node, ) => null; @override - R visitSchemaDefinitionNode( + R? visitSchemaDefinitionNode( SchemaDefinitionNode node, ) => null; @override - R visitOperationTypeDefinitionNode( + R? visitOperationTypeDefinitionNode( OperationTypeDefinitionNode node, ) => null; @override - R visitScalarTypeDefinitionNode( + R? visitScalarTypeDefinitionNode( ScalarTypeDefinitionNode node, ) => null; @override - R visitObjectTypeDefinitionNode( + R? visitObjectTypeDefinitionNode( ObjectTypeDefinitionNode node, ) => null; @override - R visitFieldDefinitionNode( + R? visitFieldDefinitionNode( FieldDefinitionNode node, ) => null; @override - R visitInputValueDefinitionNode( + R? visitInputValueDefinitionNode( InputValueDefinitionNode node, ) => null; @override - R visitInterfaceTypeDefinitionNode( + R? visitInterfaceTypeDefinitionNode( InterfaceTypeDefinitionNode node, ) => null; @override - R visitUnionTypeDefinitionNode( + R? visitUnionTypeDefinitionNode( UnionTypeDefinitionNode node, ) => null; @override - R visitEnumTypeDefinitionNode( + R? visitEnumTypeDefinitionNode( EnumTypeDefinitionNode node, ) => null; @override - R visitEnumValueDefinitionNode( + R? visitEnumValueDefinitionNode( EnumValueDefinitionNode node, ) => null; @override - R visitInputObjectTypeDefinitionNode( + R? visitInputObjectTypeDefinitionNode( InputObjectTypeDefinitionNode node, ) => null; @override - R visitDirectiveDefinitionNode( + R? visitDirectiveDefinitionNode( DirectiveDefinitionNode node, ) => null; @override - R visitSchemaExtensionNode( + R? visitSchemaExtensionNode( SchemaExtensionNode node, ) => null; @override - R visitScalarTypeExtensionNode( + R? visitScalarTypeExtensionNode( ScalarTypeExtensionNode node, ) => null; @override - R visitObjectTypeExtensionNode( + R? visitObjectTypeExtensionNode( ObjectTypeExtensionNode node, ) => null; @override - R visitInterfaceTypeExtensionNode( + R? visitInterfaceTypeExtensionNode( InterfaceTypeExtensionNode node, ) => null; @override - R visitUnionTypeExtensionNode( + R? visitUnionTypeExtensionNode( UnionTypeExtensionNode node, ) => null; @override - R visitEnumTypeExtensionNode( + R? visitEnumTypeExtensionNode( EnumTypeExtensionNode node, ) => null; @override - R visitInputObjectTypeExtensionNode( + R? visitInputObjectTypeExtensionNode( InputObjectTypeExtensionNode node, ) => null; @@ -766,7 +766,7 @@ abstract class RecursiveVisitor implements Visitor { /// traversing the AST only once and collecting the return /// values in the `accumulator`. class AccumulatingVisitor extends RecursiveVisitor { - List>> visitors; + List>?> visitors; List accumulator = []; AccumulatingVisitor({ @@ -780,7 +780,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitArgumentNode(node) ?? [], + (visitor) => visitor!.visitArgumentNode(node) ?? [], ) ]; @@ -794,7 +794,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitBooleanValueNode(node) ?? [], + (visitor) => visitor!.visitBooleanValueNode(node) ?? [], ) ]; @@ -808,7 +808,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitDefaultValueNode(node) ?? [], + (visitor) => visitor!.visitDefaultValueNode(node) ?? [], ) ]; @@ -822,7 +822,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitDirectiveDefinitionNode(node) ?? [], + (visitor) => visitor!.visitDirectiveDefinitionNode(node) ?? [], ) ]; @@ -836,7 +836,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitDirectiveNode(node) ?? [], + (visitor) => visitor!.visitDirectiveNode(node) ?? [], ) ]; @@ -850,7 +850,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitDocumentNode(node) ?? [], + (visitor) => visitor!.visitDocumentNode(node) ?? [], ) ]; @@ -864,7 +864,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitEnumTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitEnumTypeDefinitionNode(node) ?? [], ) ]; @@ -878,7 +878,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitEnumTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitEnumTypeExtensionNode(node) ?? [], ) ]; @@ -892,7 +892,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitEnumValueDefinitionNode(node) ?? [], + (visitor) => visitor!.visitEnumValueDefinitionNode(node) ?? [], ) ]; @@ -906,7 +906,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitEnumValueNode(node) ?? [], + (visitor) => visitor!.visitEnumValueNode(node) ?? [], ) ]; @@ -920,7 +920,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitFieldDefinitionNode(node) ?? [], + (visitor) => visitor!.visitFieldDefinitionNode(node) ?? [], ) ]; @@ -934,7 +934,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitFieldNode(node) ?? [], + (visitor) => visitor!.visitFieldNode(node) ?? [], ) ]; @@ -948,7 +948,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitFloatValueNode(node) ?? [], + (visitor) => visitor!.visitFloatValueNode(node) ?? [], ) ]; @@ -962,7 +962,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitFragmentDefinitionNode(node) ?? [], + (visitor) => visitor!.visitFragmentDefinitionNode(node) ?? [], ) ]; @@ -976,7 +976,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitFragmentSpreadNode(node) ?? [], + (visitor) => visitor!.visitFragmentSpreadNode(node) ?? [], ) ]; @@ -990,7 +990,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInlineFragmentNode(node) ?? [], + (visitor) => visitor!.visitInlineFragmentNode(node) ?? [], ) ]; @@ -1004,7 +1004,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInputObjectTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitInputObjectTypeDefinitionNode(node) ?? [], ) ]; @@ -1018,7 +1018,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInputObjectTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitInputObjectTypeExtensionNode(node) ?? [], ) ]; @@ -1032,7 +1032,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInputValueDefinitionNode(node) ?? [], + (visitor) => visitor!.visitInputValueDefinitionNode(node) ?? [], ) ]; @@ -1046,7 +1046,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitIntValueNode(node) ?? [], + (visitor) => visitor!.visitIntValueNode(node) ?? [], ) ]; @@ -1060,7 +1060,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInterfaceTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitInterfaceTypeDefinitionNode(node) ?? [], ) ]; @@ -1074,7 +1074,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitInterfaceTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitInterfaceTypeExtensionNode(node) ?? [], ) ]; @@ -1088,7 +1088,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitListTypeNode(node) ?? [], + (visitor) => visitor!.visitListTypeNode(node) ?? [], ) ]; @@ -1102,7 +1102,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitListValueNode(node) ?? [], + (visitor) => visitor!.visitListValueNode(node) ?? [], ) ]; @@ -1116,7 +1116,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitNameNode(node) ?? [], + (visitor) => visitor!.visitNameNode(node) ?? [], ) ]; @@ -1130,7 +1130,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitNamedTypeNode(node) ?? [], + (visitor) => visitor!.visitNamedTypeNode(node) ?? [], ) ]; @@ -1144,7 +1144,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitNullValueNode(node) ?? [], + (visitor) => visitor!.visitNullValueNode(node) ?? [], ) ]; @@ -1158,7 +1158,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitObjectFieldNode(node) ?? [], + (visitor) => visitor!.visitObjectFieldNode(node) ?? [], ) ]; @@ -1172,7 +1172,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitObjectTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitObjectTypeDefinitionNode(node) ?? [], ) ]; @@ -1186,7 +1186,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitObjectTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitObjectTypeExtensionNode(node) ?? [], ) ]; @@ -1200,7 +1200,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitObjectValueNode(node) ?? [], + (visitor) => visitor!.visitObjectValueNode(node) ?? [], ) ]; @@ -1214,7 +1214,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitOperationDefinitionNode(node) ?? [], + (visitor) => visitor!.visitOperationDefinitionNode(node) ?? [], ) ]; @@ -1228,7 +1228,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitOperationTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitOperationTypeDefinitionNode(node) ?? [], ) ]; @@ -1242,7 +1242,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitScalarTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitScalarTypeDefinitionNode(node) ?? [], ) ]; @@ -1256,7 +1256,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitScalarTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitScalarTypeExtensionNode(node) ?? [], ) ]; @@ -1270,7 +1270,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitSchemaDefinitionNode(node) ?? [], + (visitor) => visitor!.visitSchemaDefinitionNode(node) ?? [], ) ]; @@ -1284,7 +1284,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitSchemaExtensionNode(node) ?? [], + (visitor) => visitor!.visitSchemaExtensionNode(node) ?? [], ) ]; @@ -1298,7 +1298,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitSelectionSetNode(node) ?? [], + (visitor) => visitor!.visitSelectionSetNode(node) ?? [], ) ]; @@ -1312,7 +1312,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitStringValueNode(node) ?? [], + (visitor) => visitor!.visitStringValueNode(node) ?? [], ) ]; @@ -1326,7 +1326,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitTypeConditionNode(node) ?? [], + (visitor) => visitor!.visitTypeConditionNode(node) ?? [], ) ]; @@ -1340,7 +1340,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitUnionTypeDefinitionNode(node) ?? [], + (visitor) => visitor!.visitUnionTypeDefinitionNode(node) ?? [], ) ]; @@ -1354,7 +1354,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitUnionTypeExtensionNode(node) ?? [], + (visitor) => visitor!.visitUnionTypeExtensionNode(node) ?? [], ) ]; @@ -1368,7 +1368,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitVariableDefinitionNode(node) ?? [], + (visitor) => visitor!.visitVariableDefinitionNode(node) ?? [], ) ]; @@ -1382,7 +1382,7 @@ class AccumulatingVisitor extends RecursiveVisitor { accumulator = [ ...accumulator, ...visitors.expand( - (visitor) => visitor.visitVariableNode(node) ?? [], + (visitor) => visitor!.visitVariableNode(node) ?? [], ) ]; diff --git a/gql/lib/src/language/lexer.dart b/gql/lib/src/language/lexer.dart index e3699959..7d9f536f 100644 --- a/gql/lib/src/language/lexer.dart +++ b/gql/lib/src/language/lexer.dart @@ -26,9 +26,9 @@ enum TokenKind { } abstract class Token { - FileSpan get span; + FileSpan? get span; - TokenKind get kind; + TokenKind? get kind; String get value; @@ -39,16 +39,16 @@ abstract class Token { class _Token implements Token { @override - final TokenKind kind; + final TokenKind? kind; @override - final FileSpan span; + final FileSpan? span; const _Token({ this.kind, this.span, }); - String get _text => span.text; + String get _text => span!.text; String _getValue() { switch (kind) { @@ -56,11 +56,11 @@ class _Token implements Token { return _text.substring(1, _text.length - 1).replaceAllMapped( RegExp(r'\\[nrbtf\\/"]'), (match) { - switch (match.group(0).codeUnitAt(1)) { + switch (match.group(0)!.codeUnitAt(1)) { case 34: // " case 47: // / case 92: // \ - return match.group(0)[1]; + return match.group(0)![1]; case 98: // \b return "\b"; case 102: // \f @@ -72,17 +72,17 @@ class _Token implements Token { case 116: // \t return "\t"; default: - return match.group(0); + return match.group(0)!; } }, ).replaceAllMapped( RegExp(r"\\u[0-9A-Za-z]{4}"), (match) => String.fromCharCode( uniCharCode( - match.group(0).codeUnitAt(2), - match.group(0).codeUnitAt(3), - match.group(0).codeUnitAt(4), - match.group(0).codeUnitAt(5), + match.group(0)!.codeUnitAt(2), + match.group(0)!.codeUnitAt(3), + match.group(0)!.codeUnitAt(4), + match.group(0)!.codeUnitAt(5), ), ), ); @@ -91,7 +91,7 @@ class _Token implements Token { _text.substring(3, _text.length - 3).replaceAll('\\"""', '"""'), ); default: - return span.text; + return span!.text; } } @@ -127,7 +127,7 @@ class _Scanner { _Scanner(this.src); - int peek({ + int? peek({ int offset = 0, }) { if (position + offset >= src.length) { @@ -169,7 +169,7 @@ class _Scanner { ); } - final code = peek(); + final code = peek()!; if ((code >= 65 && code <= 90) || code == 95 || @@ -234,7 +234,7 @@ class _Scanner { Token scanComment() { var length = 0; - int code; + int? code; do { code = peek(offset: ++length); @@ -299,11 +299,11 @@ class _Scanner { int _scanDigits(int offset) { var digitOffset = offset; - var code = peek(offset: digitOffset); + var code = peek(offset: digitOffset)!; if (code >= 48 && code <= 57) { do { - code = peek(offset: ++digitOffset); + code = peek(offset: ++digitOffset)!; } while (code != null && code >= 48 && code <= 57); return digitOffset; @@ -378,10 +378,10 @@ class _Scanner { case 116: // \t break; case 117: // \u - final isUnicode = isHex(peek(offset: 1)) && - isHex(peek(offset: 2)) && - isHex(peek(offset: 3)) && - isHex(peek(offset: 4)); + final isUnicode = isHex(peek(offset: 1)!) && + isHex(peek(offset: 2)!) && + isHex(peek(offset: 3)!) && + isHex(peek(offset: 4)!); if (!isUnicode) { throw SourceSpanException( @@ -526,7 +526,7 @@ int char2Hex(int a) { String dedentBlockStringValue(String value) { var lines = value.split(RegExp(r"\r\n|[\n\r]")); - int commonIndent; + int? commonIndent; for (var i = 1; i < lines.length; i++) { final line = lines[i]; final indent = leadingWhitespace(line); @@ -542,7 +542,7 @@ String dedentBlockStringValue(String value) { if (commonIndent != null && commonIndent != 0) { lines = lines.map((line) { - if (line.length < commonIndent) { + if (line.length < commonIndent!) { return ""; } else { return line.substring(commonIndent); diff --git a/gql/lib/src/language/parser.dart b/gql/lib/src/language/parser.dart index 3d947b1c..eab484c1 100644 --- a/gql/lib/src/language/parser.dart +++ b/gql/lib/src/language/parser.dart @@ -51,8 +51,8 @@ class _Parser { ++_position; } - Token _expectToken(TokenKind kind, [String errorMessage]) { - final next = _next(); + Token _expectToken(TokenKind kind, [String? errorMessage]) { + final next = _next()!; if (next.kind == kind) { _advance(); return next; @@ -60,12 +60,12 @@ class _Parser { throw SourceSpanException( errorMessage ?? "Expected $kind", - _next().span, + _next()!.span, ); } - Token _expectOptionalToken(TokenKind kind) { - final next = _next(); + Token? _expectOptionalToken(TokenKind kind) { + final next = _next()!; if (next.kind == kind) { _advance(); return next; @@ -74,8 +74,8 @@ class _Parser { return null; } - Token _expectKeyword(String value, [String errorMessage]) { - final next = _next(); + Token _expectKeyword(String value, [String? errorMessage]) { + final next = _next()!; if (next.kind == TokenKind.name && next.value == value) { _advance(); return next; @@ -83,12 +83,12 @@ class _Parser { throw SourceSpanException( errorMessage ?? "Expected keyword '$value'", - _next().span, + _next()!.span, ); } - Token _expectOptionalKeyword(String value) { - final next = _next(); + Token? _expectOptionalKeyword(String value) { + final next = _next()!; if (next.kind == TokenKind.name && next.value == value) { _advance(); return next; @@ -97,7 +97,7 @@ class _Parser { return null; } - Token _next({int offset = 0}) { + Token? _next({int offset = 0}) { if (_position + offset >= _length) return null; return _tokens[_position + offset]; @@ -107,7 +107,7 @@ class _Parser { TokenKind open, _ParseFunction parse, TokenKind close, [ - String errorMessage, + String? errorMessage, ]) { _expectToken(open, errorMessage); @@ -124,7 +124,7 @@ class _Parser { TokenKind open, _ParseFunction parse, TokenKind close, [ - String errorMessage, + String? errorMessage, ]) { if (_peek(open)) { return _parseMany( @@ -148,7 +148,7 @@ class _Parser { DefinitionNode _parseDefinition() { if (_peek(TokenKind.name)) { - switch (_next().value) { + switch (_next()!.value) { case "query": case "mutation": case "subscription": @@ -173,14 +173,14 @@ class _Parser { } throw SourceSpanException( - "Unknown definition type '${_next().value}'", - _next().span, + "Unknown definition type '${_next()!.value}'", + _next()!.span, ); } ExecutableDefinitionNode _parseExecutableDefinition() { if (_peek(TokenKind.name)) { - switch (_next().value) { + switch (_next()!.value) { case "query": case "mutation": case "subscription": @@ -193,8 +193,8 @@ class _Parser { } throw SourceSpanException( - "Unknown executable definition '${_next().value}'", - _next().span, + "Unknown executable definition '${_next()!.value}'", + _next()!.span, ); } @@ -224,7 +224,7 @@ class _Parser { } final operationType = _parseOperationType(); - NameNode name; + NameNode? name; if (_peek(TokenKind.name)) name = _parseName(); return OperationDefinitionNode( @@ -249,7 +249,7 @@ class _Parser { final type = _parseType(); - ValueNode defaultValue; + ValueNode? defaultValue; if (_expectOptionalToken(TokenKind.equals) != null) { defaultValue = _parseValue(isConst: true); } @@ -303,7 +303,7 @@ class _Parser { ObjectFieldNode _parseNonConstObjectField() => _parseObjectField(isConst: false); - ObjectFieldNode _parseObjectField({bool isConst}) { + ObjectFieldNode _parseObjectField({bool? isConst}) { final name = _parseName("Expected an object field name"); _expectToken(TokenKind.colon, "Missing ':' before object field value"); @@ -315,13 +315,13 @@ class _Parser { ValueNode _parseNonConstValue() => _parseValue(isConst: false); - ValueNode _parseValue({bool isConst}) { - final token = _next(); + ValueNode _parseValue({bool? isConst}) { + final token = _next()!; switch (token.kind) { case TokenKind.bracketL: - return _parseList(isConst: isConst); + return _parseList(isConst: isConst!); case TokenKind.braceL: - return _parseObject(isConst: isConst); + return _parseObject(isConst: isConst!); case TokenKind.int: _advance(); @@ -354,7 +354,7 @@ class _Parser { name: _parseName(), ); case TokenKind.dollar: - if (!isConst) { + if (!isConst!) { return _parseVariable(); } @@ -371,7 +371,7 @@ class _Parser { } StringValueNode _parseStringValue() { - final valueToken = _next(); + final valueToken = _next()!; _advance(); return StringValueNode( @@ -380,7 +380,7 @@ class _Parser { ); } - ListValueNode _parseList({bool isConst}) => ListValueNode( + ListValueNode _parseList({required bool isConst}) => ListValueNode( values: _parseMany( TokenKind.bracketL, isConst ? _parseConstValue : _parseNonConstValue, @@ -388,7 +388,7 @@ class _Parser { ), ); - ObjectValueNode _parseObject({bool isConst}) => ObjectValueNode( + ObjectValueNode _parseObject({required bool isConst}) => ObjectValueNode( fields: _parseMany( TokenKind.braceL, isConst ? _parseConstObjectField : _parseNonConstObjectField, @@ -405,7 +405,7 @@ class _Parser { return directives; } - DirectiveNode _parseDirective({bool isConst}) { + DirectiveNode _parseDirective({required bool isConst}) { _expectToken(TokenKind.at, "Expected directive name starting with '@'"); return DirectiveNode( @@ -414,7 +414,7 @@ class _Parser { ); } - List _parseArguments({bool isConst}) => _maybeParseMany( + List _parseArguments({required bool isConst}) => _maybeParseMany( TokenKind.parenL, isConst ? _parseConstArgument : _parseNonConstArgument, TokenKind.parenR, @@ -424,7 +424,7 @@ class _Parser { ArgumentNode _parseNonConstArgument() => _parseArgument(isConst: false); - ArgumentNode _parseArgument({bool isConst}) { + ArgumentNode _parseArgument({bool? isConst}) { final name = _parseName("Expected an argument name"); _expectToken(TokenKind.colon, "Expected ':' followed by argument value"); @@ -491,7 +491,7 @@ class _Parser { } NameNode _parseFragmentName() { - final token = _next(); + final token = _next()!; if (token.value == "on") { throw SourceSpanException( "Invalid fragment name 'on'", @@ -506,7 +506,7 @@ class _Parser { final nameOrAlias = _parseName("Expected a field or field alias name"); NameNode name; - NameNode alias; + NameNode? alias; if (_expectOptionalToken(TokenKind.colon) != null) { alias = nameOrAlias; @@ -518,7 +518,7 @@ class _Parser { final arguments = _parseArguments(isConst: false); final directives = _parseDirectives(isConst: false); - SelectionSetNode selectionSet; + SelectionSetNode? selectionSet; if (_peek(TokenKind.braceL)) { selectionSet = _parseSelectionSet(); } @@ -532,7 +532,7 @@ class _Parser { ); } - NameNode _parseName([String errorMessage]) { + NameNode _parseName([String? errorMessage]) { final token = _expectToken( TokenKind.name, errorMessage ?? "Expected a name", @@ -551,7 +551,7 @@ class _Parser { final token = _next(offset: keywordOffset); if (_peek(TokenKind.name, offset: keywordOffset)) { - switch (token.value) { + switch (token!.value) { case "schema": return _parseSchemaDefinition(); case "scalar": @@ -572,7 +572,7 @@ class _Parser { } throw SourceSpanException( - "Unknown type system definition type '${token.value}'", + "Unknown type system definition type '${token!.value}'", token.span, ); } @@ -583,7 +583,7 @@ class _Parser { final token = _next(); if (_peek(TokenKind.name) != null) { - switch (token.value) { + switch (token!.value) { case "schema": return _parseSchemaExtension(); case "scalar": @@ -602,7 +602,7 @@ class _Parser { } throw SourceSpanException( - "Unknown type system extension type '${token.value}'", + "Unknown type system extension type '${token!.value}'", token.span, ); } @@ -647,7 +647,7 @@ class _Parser { ); } - StringValueNode _parseDescription() { + StringValueNode? _parseDescription() { if (_peek(TokenKind.string) || _peek(TokenKind.blockString)) { return _parseStringValue(); } @@ -720,7 +720,7 @@ class _Parser { final name = _parseName("Expected an input value name"); _expectToken(TokenKind.colon, "Expected ':' followed by input value type"); final type = _parseType(); - ValueNode defaultValue; + ValueNode? defaultValue; if (_expectOptionalToken(TokenKind.equals) != null) { defaultValue = _parseConstValue(); } @@ -925,7 +925,7 @@ class _Parser { if (directives.isEmpty && operationTypes.isEmpty) { throw SourceSpanException( "Schema extension must have either directives or operation types defined", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -946,7 +946,7 @@ class _Parser { if (directives.isEmpty) { throw SourceSpanException( "Scalar extension must have either directives defined", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -969,7 +969,7 @@ class _Parser { if (interfaces.isEmpty && directives.isEmpty && fields.isEmpty) { throw SourceSpanException( "Object type extension must define at least one directive or field, or implement at lease one interface", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -993,7 +993,7 @@ class _Parser { if (directives.isEmpty && fields.isEmpty) { throw SourceSpanException( "Interface type extension must define at least one directive or field", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -1016,7 +1016,7 @@ class _Parser { if (directives.isEmpty && types.isEmpty) { throw SourceSpanException( "Union type extension must define at least one directive or type", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -1039,7 +1039,7 @@ class _Parser { if (directives.isEmpty && values.isEmpty) { throw SourceSpanException( "Enum type extension must define at least one directive or value", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } @@ -1062,7 +1062,7 @@ class _Parser { if (directives.isEmpty && fields.isEmpty) { throw SourceSpanException( "Input type extension must define at least one directive or field, or implement at lease one interface", - errorToken.span.expand(_next().span), + errorToken!.span!.expand(_next()!.span!), ); } diff --git a/gql/lib/src/language/printer.dart b/gql/lib/src/language/printer.dart index 17a21c8b..9faf5710 100644 --- a/gql/lib/src/language/printer.dart +++ b/gql/lib/src/language/printer.dart @@ -68,14 +68,14 @@ class _PrintVisitor extends Visitor { def.variable.accept(this), ": ", def.type.accept(this), - def.defaultValue.accept(this) + def.defaultValue!.accept(this) ].join(); @override String visitDefaultValueNode(DefaultValueNode defaultValueNode) { if (defaultValueNode.value == null) return ""; - return " = ${defaultValueNode.value.accept(this)}"; + return " = ${defaultValueNode.value!.accept(this)}"; } @override @@ -87,7 +87,7 @@ class _PrintVisitor extends Visitor { _opType(op.type), if (op.name != null) ...[ " ", - op.name.accept(this), + op.name!.accept(this), ], if (op.variableDefinitions != null && op.variableDefinitions.isNotEmpty) visitVariableDefinitionSetNode(op.variableDefinitions), @@ -208,7 +208,7 @@ class _PrintVisitor extends Visitor { FragmentDefinitionNode fragmentDefinitionNode) => [ "fragment ", - fragmentDefinitionNode.name.accept(this), + fragmentDefinitionNode.name!.accept(this), if (fragmentDefinitionNode.typeCondition != null) ...[ " ", fragmentDefinitionNode.typeCondition.accept(this), @@ -229,7 +229,7 @@ class _PrintVisitor extends Visitor { "...", if (inlineFragmentNode.typeCondition != null) ...[ " ", - inlineFragmentNode.typeCondition.accept(this), + inlineFragmentNode.typeCondition!.accept(this), ], if (inlineFragmentNode.directives != null && inlineFragmentNode.directives.isNotEmpty) ...[ @@ -263,7 +263,7 @@ class _PrintVisitor extends Visitor { @override String visitFieldNode(FieldNode fieldNode) => [ if (fieldNode.alias != null) ...[ - fieldNode.alias.accept(this), + fieldNode.alias!.accept(this), ": ", ], fieldNode.name.accept(this), @@ -276,7 +276,7 @@ class _PrintVisitor extends Visitor { ], if (fieldNode.selectionSet != null) ...[ " ", - visitSelectionSetNode(fieldNode.selectionSet), + visitSelectionSetNode(fieldNode.selectionSet!), ], ].join(); @@ -317,12 +317,12 @@ class _PrintVisitor extends Visitor { @override String visitScalarTypeDefinitionNode(ScalarTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "scalar", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -332,12 +332,12 @@ class _PrintVisitor extends Visitor { @override String visitObjectTypeDefinitionNode(ObjectTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "type", " ", - node.name.accept(this), + node.name!.accept(this), " ", visitImplementsSetNode(node.interfaces), visitDirectiveSetNode(node.directives), @@ -386,7 +386,7 @@ class _PrintVisitor extends Visitor { @override String visitFieldDefinitionNode(FieldDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", _indent(_tabs), ], @@ -420,7 +420,7 @@ class _PrintVisitor extends Visitor { @override String visitInputValueDefinitionNode(InputValueDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", _indent(_tabs), ], @@ -432,7 +432,7 @@ class _PrintVisitor extends Visitor { " ", "=", " ", - node.defaultValue.accept(this), + node.defaultValue!.accept(this), ], if (node.directives != null && node.directives.isNotEmpty) " ", visitDirectiveSetNode(node.directives), @@ -441,12 +441,12 @@ class _PrintVisitor extends Visitor { @override String visitInterfaceTypeDefinitionNode(InterfaceTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "interface", " ", - node.name.accept(this), + node.name!.accept(this), " ", visitDirectiveSetNode(node.directives), visitFieldSetNode(node.fields), @@ -455,12 +455,12 @@ class _PrintVisitor extends Visitor { @override String visitUnionTypeDefinitionNode(UnionTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "union", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -494,12 +494,12 @@ class _PrintVisitor extends Visitor { @override String visitEnumTypeDefinitionNode(EnumTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "enum", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -533,11 +533,11 @@ class _PrintVisitor extends Visitor { @override String visitEnumValueDefinitionNode(EnumValueDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", _indent(_tabs), ], - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) " ", visitDirectiveSetNode(node.directives), ].join(); @@ -547,12 +547,12 @@ class _PrintVisitor extends Visitor { InputObjectTypeDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "input", " ", - node.name.accept(this), + node.name!.accept(this), " ", visitDirectiveSetNode(node.directives), visitInputValueDefinitionSetNode(node.fields), @@ -583,13 +583,13 @@ class _PrintVisitor extends Visitor { @override String visitDirectiveDefinitionNode(DirectiveDefinitionNode node) => [ if (node.description != null) ...[ - node.description.accept(this), + node.description!.accept(this), "\n", ], "directive", " ", "@", - node.name.accept(this), + node.name!.accept(this), visitArgumentDefinitionSetNode(node.args), if (node.repeatable) ...[ " ", @@ -643,7 +643,7 @@ class _PrintVisitor extends Visitor { " ", "scalar", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -656,7 +656,7 @@ class _PrintVisitor extends Visitor { " ", "type", " ", - node.name.accept(this), + node.name!.accept(this), " ", visitImplementsSetNode(node.interfaces), visitDirectiveSetNode(node.directives), @@ -669,7 +669,7 @@ class _PrintVisitor extends Visitor { " ", "interface", " ", - node.name.accept(this), + node.name!.accept(this), " ", visitDirectiveSetNode(node.directives), visitFieldSetNode(node.fields), @@ -681,7 +681,7 @@ class _PrintVisitor extends Visitor { " ", "union", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -695,7 +695,7 @@ class _PrintVisitor extends Visitor { " ", "enum", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -710,7 +710,7 @@ class _PrintVisitor extends Visitor { " ", "input", " ", - node.name.accept(this), + node.name!.accept(this), if (node.directives != null && node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), @@ -719,7 +719,7 @@ class _PrintVisitor extends Visitor { ].join(); } -String _opType(OperationType t) { +String? _opType(OperationType t) { switch (t) { case OperationType.query: return "query"; @@ -733,7 +733,7 @@ String _opType(OperationType t) { return null; } -String _directiveLocation(DirectiveLocation location) { +String? _directiveLocation(DirectiveLocation location) { switch (location) { case DirectiveLocation.query: return "QUERY"; diff --git a/gql/lib/src/operation/definitions/base_types.dart b/gql/lib/src/operation/definitions/base_types.dart index c4f6546e..67683298 100644 --- a/gql/lib/src/operation/definitions/base_types.dart +++ b/gql/lib/src/operation/definitions/base_types.dart @@ -12,7 +12,7 @@ abstract class ExecutableGraphQLEntity extends GraphQLEntity { @immutable abstract class ExecutableWithResolver extends ExecutableGraphQLEntity implements ExecutableTypeResolver { - const ExecutableWithResolver([GetExecutableType getType]) + const ExecutableWithResolver([GetExecutableType? getType]) : getType = getType ?? GetExecutableType.withoutContext, super(); @@ -32,7 +32,7 @@ abstract class ExecutableWithResolver extends ExecutableGraphQLEntity } @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash([astNode, getType]); } diff --git a/gql/lib/src/operation/definitions/definitions.dart b/gql/lib/src/operation/definitions/definitions.dart index b432585a..0d0abdf4 100644 --- a/gql/lib/src/operation/definitions/definitions.dart +++ b/gql/lib/src/operation/definitions/definitions.dart @@ -9,15 +9,15 @@ import "package:gql/src/operation/definitions/selections.dart"; @immutable abstract class ExecutableDefinition extends ExecutableWithResolver { - const ExecutableDefinition([GetExecutableType getType]) : super(getType); + const ExecutableDefinition([GetExecutableType? getType]) : super(getType); @override ExecutableDefinitionNode get astNode; - String get name => astNode.name?.value; + String? get name => astNode.name?.value; static ExecutableDefinition fromNode(ExecutableDefinitionNode astNode, - [GetExecutableType getType]) { + [GetExecutableType? getType]) { if (astNode is OperationDefinitionNode) { return OperationDefinition(astNode, getType); } @@ -40,7 +40,7 @@ abstract class ExecutableDefinition extends ExecutableWithResolver { class OperationDefinition extends ExecutableDefinition { const OperationDefinition( this.astNode, [ - GetExecutableType getType, + GetExecutableType? getType, ]) : super(getType); @override @@ -48,15 +48,15 @@ class OperationDefinition extends ExecutableDefinition { OperationType get type => astNode.type; - ObjectTypeDefinition get schemaType => - getType.fromSchema(type.name) as ObjectTypeDefinition; + ObjectTypeDefinition? get schemaType => + getType.fromSchema!(type.name) as ObjectTypeDefinition?; List get variables => astNode.variableDefinitions.map((v) => VariableDefinition(v)).toList(); SelectionSet get selectionSet => SelectionSet( astNode.selectionSet, - getType.fromSchema(type.name) as ObjectTypeDefinition, + getType.fromSchema!(type.name) as ObjectTypeDefinition?, getType, ); } @@ -72,7 +72,7 @@ class OperationDefinition extends ExecutableDefinition { /// when querying against an [InterfaceTypeDefinition] or [UnionTypeDefinition]. @immutable class FragmentDefinition extends ExecutableDefinition { - const FragmentDefinition(this.astNode, [GetExecutableType getType]) + const FragmentDefinition(this.astNode, [GetExecutableType? getType]) : super(getType); @override @@ -80,7 +80,7 @@ class FragmentDefinition extends ExecutableDefinition { TypeCondition get _typeCondition => TypeCondition(astNode.typeCondition); - TypeDefinition get onType => getType.fromSchema(_typeCondition.on.name); + TypeDefinition? get onType => getType.fromSchema!(_typeCondition.on.name); List get directives => astNode.directives.map((d) => Directive(d)).toList(); @@ -104,9 +104,9 @@ class TypeCondition extends ExecutableGraphQLEntity { const TypeCondition(this.astNode); @override - final TypeConditionNode astNode; + final TypeConditionNode? astNode; - NamedType get on => NamedType(astNode.on); + NamedType get on => NamedType(astNode!.on); } /// [Variables](https://spec.graphql.org/June2018/#sec-Language.Variables) @@ -120,7 +120,7 @@ class TypeCondition extends ExecutableGraphQLEntity { /// the execution of that operation. @immutable class VariableDefinition extends ExecutableWithResolver { - const VariableDefinition(this.astNode, [GetExecutableType getType]) + const VariableDefinition(this.astNode, [GetExecutableType? getType]) : super(getType); @override diff --git a/gql/lib/src/operation/definitions/selections.dart b/gql/lib/src/operation/definitions/selections.dart index 32dcddf8..f4372016 100644 --- a/gql/lib/src/operation/definitions/selections.dart +++ b/gql/lib/src/operation/definitions/selections.dart @@ -21,15 +21,15 @@ class SelectionSet extends ExecutableWithResolver { const SelectionSet( this.astNode, [ this.schemaType, - GetExecutableType getType, + GetExecutableType? getType, ]) : super(getType); - final TypeDefinition schemaType; + final TypeDefinition? schemaType; @override - final SelectionSetNode astNode; + final SelectionSetNode? astNode; - List get selections => astNode.selections + List get selections => astNode!.selections .map((selection) => Selection.fromNode(selection, schemaType, getType)) .toList(); @@ -46,9 +46,9 @@ class SelectionSet extends ExecutableWithResolver { /// ([Field]s, [FragmentSpread]s, or [InlineFragment]s)s @immutable abstract class Selection extends ExecutableWithResolver { - const Selection([GetExecutableType getType]) : super(getType); + const Selection([GetExecutableType? getType]) : super(getType); - GraphQLEntity get schemaType; + GraphQLEntity? get schemaType; @override SelectionNode get astNode; @@ -59,8 +59,8 @@ abstract class Selection extends ExecutableWithResolver { SelectionNode astNode, [ /// The [schemaType] of the containing element - TypeDefinition schemaType, - GetExecutableType getType, + TypeDefinition? schemaType, + GetExecutableType? getType, ]) { if (astNode is FieldNode) { // fields can only be selected on Interface and Object types @@ -79,7 +79,7 @@ abstract class Selection extends ExecutableWithResolver { } if (astNode is InlineFragmentNode) { // inline fragments must always specify a type condition - final onType = getType.fromSchema(astNode.typeCondition.on.name.value); + final onType = getType!.fromSchema!(astNode.typeCondition!.on.name.value); return InlineFragment(astNode, onType, getType); } @@ -102,21 +102,21 @@ class Field extends Selection { const Field( this.astNode, [ this.schemaType, - GetExecutableType getType, + GetExecutableType? getType, ]) : super(getType); @override final FieldNode astNode; @override - final FieldDefinition schemaType; + final FieldDefinition? schemaType; @override String get alias => astNode.alias?.value ?? name; String get name => astNode.name.value; - GraphQLType get type => schemaType.type; + GraphQLType? get type => schemaType!.type; List get arguments => astNode.arguments.map((a) => Argument(a)).toList(); @@ -124,10 +124,10 @@ class Field extends Selection { List get directives => astNode.directives.map((d) => Directive(d)).toList(); - SelectionSet get selectionSet => astNode.selectionSet != null + SelectionSet? get selectionSet => astNode.selectionSet != null ? SelectionSet( astNode.selectionSet, - getType.fromSchema(type.baseTypeName), + getType.fromSchema!(type!.baseTypeName), getType, ) : null; @@ -143,14 +143,14 @@ class Field extends Selection { @immutable class FragmentSpread extends Selection { const FragmentSpread(this.astNode, - [this.schemaType, GetExecutableType getType]) + [this.schemaType, GetExecutableType? getType]) : super(getType); @override final FragmentSpreadNode astNode; @override - final TypeDefinition schemaType; + final TypeDefinition? schemaType; String get name => astNode.name.value; @@ -180,7 +180,7 @@ class InlineFragment extends Selection { const InlineFragment( this.astNode, [ this.schemaType, - GetExecutableType getType, + GetExecutableType? getType, ]) : super(getType); @override @@ -188,8 +188,8 @@ class InlineFragment extends Selection { TypeCondition get typeCondition => TypeCondition(astNode.typeCondition); - TypeDefinitionWithFieldSet get onType => - getType.fromSchema(onTypeName) as TypeDefinitionWithFieldSet; + TypeDefinitionWithFieldSet? get onType => + getType.fromSchema!(onTypeName) as TypeDefinitionWithFieldSet?; String get onTypeName => typeCondition.on.name; @@ -197,7 +197,7 @@ class InlineFragment extends Selection { String get alias => "on$onTypeName"; @override - final TypeDefinition schemaType; + final TypeDefinition? schemaType; List get directives => astNode.directives.map((d) => Directive(d)).toList(); diff --git a/gql/lib/src/operation/definitions/type_resolver.dart b/gql/lib/src/operation/definitions/type_resolver.dart index 0a63e7fc..d63de64c 100644 --- a/gql/lib/src/operation/definitions/type_resolver.dart +++ b/gql/lib/src/operation/definitions/type_resolver.dart @@ -5,7 +5,7 @@ import "package:gql/src/schema/definitions.dart"; import "package:gql/src/operation/definitions.dart"; /// Callback to dereference a full fragment definition by name -typedef ResolveFragment = FragmentDefinition Function(String name); +typedef ResolveFragment = FragmentDefinition? Function(String name); /// Container for the [fromSchema] and [fromFragments] /// dereferencing callbacks necessary for full type information while @@ -23,7 +23,7 @@ class GetExecutableType { /// usually defined within the given context such as a `GraphQLSchema`. /// /// See `gql/schema.dart`'s [TypeResolver]. - final ResolveType fromSchema; + final ResolveType? fromSchema; final ResolveFragment fromFragments; @@ -40,7 +40,7 @@ class GetExecutableType { } @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash([fromFragments, fromSchema]); diff --git a/gql/lib/src/operation/executable.dart b/gql/lib/src/operation/executable.dart index db43614d..aad2ad20 100644 --- a/gql/lib/src/operation/executable.dart +++ b/gql/lib/src/operation/executable.dart @@ -26,7 +26,7 @@ class ExecutableDocument extends ExecutableWithResolver { ]) : _fragmentNodeMap = _collectImportedFragmentNodes([astNode, ...imports]), super(); - final ResolveType getSchemaType; + final ResolveType? getSchemaType; final Map _fragmentNodeMap; @override @@ -36,7 +36,7 @@ class ExecutableDocument extends ExecutableWithResolver { @override final DocumentNode astNode; - FragmentDefinition getFragment(String name) { + FragmentDefinition? getFragment(String name) { final node = _fragmentNodeMap[name]; if (node == null) { return null; @@ -65,7 +65,7 @@ Map _collectImportedFragmentNodes( .whereType() .map( (fragmentNode) => MapEntry( - fragmentNode.name.value, + fragmentNode.name!.value, fragmentNode, ), ), diff --git a/gql/lib/src/schema/defaults.dart b/gql/lib/src/schema/defaults.dart index f76ddd88..b9858ee4 100644 --- a/gql/lib/src/schema/defaults.dart +++ b/gql/lib/src/schema/defaults.dart @@ -45,19 +45,19 @@ class _BuiltInFieldDefinition extends FieldDefinition { }) : super(null); @override - final String name; + final String? name; @override - final String description; + final String? description; @override - final GraphQLType type; + final GraphQLType? type; @override - final List directives; + final List? directives; @override - final List args; + final List? args; } const typeNameField = _BuiltInFieldDefinition( @@ -83,15 +83,15 @@ class _BuiltInArgument extends InputValueDefinition { }) : super(null); @override - final String description; + final String? description; @override - final String name; + final String? name; @override - final GraphQLType type; + final GraphQLType? type; @override - final Value defaultValue; + final Value? defaultValue; @override - final List directives; + final List? directives; } @immutable @@ -105,13 +105,13 @@ class _BuiltInDirective extends DirectiveDefinition { }) : super(null); @override - final String name; + final String? name; @override - final String description; + final String? description; @override - final List args; + final List? args; @override - final List locations; + final List? locations; @override final bool repeatable; diff --git a/gql/lib/src/schema/definitions/base_types.dart b/gql/lib/src/schema/definitions/base_types.dart index 4986b673..5618caef 100644 --- a/gql/lib/src/schema/definitions/base_types.dart +++ b/gql/lib/src/schema/definitions/base_types.dart @@ -21,9 +21,9 @@ abstract class GraphQLEntity { const GraphQLEntity(); @override - String toString() => printNode(astNode); + String toString() => printNode(astNode!); - Node get astNode; + Node? get astNode; @override bool operator ==(Object o) { @@ -43,7 +43,7 @@ abstract class GraphQLEntity { @immutable abstract class EntityWithResolver extends GraphQLEntity implements TypeResolver { - const EntityWithResolver([ResolveType getType]) + const EntityWithResolver([ResolveType? getType]) : getType = getType ?? TypeResolver.withoutContext, super(); @@ -63,7 +63,7 @@ abstract class EntityWithResolver extends GraphQLEntity } @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash([astNode, getType]); } @@ -109,7 +109,7 @@ abstract class GraphQLType extends EntityWithResolver { static GraphQLType fromNode( TypeNode astNode, [ - ResolveType getType, + ResolveType? getType, ]) { if (astNode is NamedTypeNode) { return NamedType(astNode, getType); @@ -129,7 +129,7 @@ abstract class GraphQLType extends EntityWithResolver { class NamedType extends GraphQLType { const NamedType( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext, super(); @@ -142,7 +142,7 @@ class NamedType extends GraphQLType { /// (verifiable via [hasResolver]). /// /// See [TypeResolver] for mor details on type resolution. - TypeDefinition get type => getType(name); + TypeDefinition? get type => getType(name); /// Whether it is safe to resolve the referenced type via [type] bool get hasResolver => getType != TypeResolver.withoutContext; @@ -167,7 +167,7 @@ class NamedType extends GraphQLType { class ListType extends GraphQLType { const ListType( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext, super(); @@ -222,9 +222,9 @@ abstract class TypeSystemDefinition extends GraphQLEntity { /// The underlying definition node from `gql/ast.dart` @override - TypeSystemDefinitionNode get astNode; + TypeSystemDefinitionNode? get astNode; - String get name => astNode.name.value; + String? get name => astNode!.name!.value; } /// The fundamental unit of any GraphQL Schema ([spec](https://spec.graphql.org/June2018/#TypeDefinition)). @@ -262,7 +262,7 @@ abstract class TypeDefinition extends TypeSystemDefinition { @override TypeDefinitionNode get astNode; - String get description => astNode.description?.value; + String? get description => astNode.description?.value; List get directives => astNode.directives.map((d) => Directive(d)).toList(); @@ -307,7 +307,7 @@ abstract class TypeDefinition extends TypeSystemDefinition { @immutable abstract class TypeDefinitionWithResolver extends TypeDefinition implements TypeResolver { - const TypeDefinitionWithResolver([ResolveType getType]) + const TypeDefinitionWithResolver([ResolveType? getType]) : getType = getType ?? TypeResolver.withoutContext, super(); @@ -327,7 +327,7 @@ abstract class TypeDefinitionWithResolver extends TypeDefinition } @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash([astNode, getType]); } diff --git a/gql/lib/src/schema/definitions/definitions.dart b/gql/lib/src/schema/definitions/definitions.dart index 0b3bb211..aedb4a0a 100644 --- a/gql/lib/src/schema/definitions/definitions.dart +++ b/gql/lib/src/schema/definitions/definitions.dart @@ -48,8 +48,8 @@ extension WithTypeName on OperationType { class FieldDefinition extends EntityWithResolver { const FieldDefinition( this.astNode, [ - ResolveType getType, - bool isOverride, + ResolveType? getType, + bool? isOverride, ]) : getType = getType ?? TypeResolver.withoutContext, isOverride = isOverride ?? false; @@ -59,18 +59,18 @@ class FieldDefinition extends EntityWithResolver { final bool isOverride; @override - final FieldDefinitionNode astNode; + final FieldDefinitionNode? astNode; - String get name => astNode.name.value; + String? get name => astNode!.name.value; - String get description => astNode.description?.value; + String? get description => astNode!.description?.value; - GraphQLType get type => GraphQLType.fromNode(astNode.type, getType); + GraphQLType? get type => GraphQLType.fromNode(astNode!.type, getType); - List get directives => - astNode.directives.map((d) => Directive(d)).toList(); + List? get directives => + astNode!.directives.map((d) => Directive(d)).toList(); - List get args => astNode.args + List? get args => astNode!.args .map( (arg) => InputValueDefinition(arg, getType), ) @@ -81,7 +81,7 @@ class FieldDefinition extends EntityWithResolver { @immutable abstract class TypeDefinitionWithFieldSet extends TypeDefinitionWithResolver { const TypeDefinitionWithFieldSet([ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext, super(); @@ -107,7 +107,7 @@ class InterfaceTypeDefinition extends TypeDefinitionWithFieldSet with AbstractType { const InterfaceTypeDefinition( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : super(getType); @override @@ -117,9 +117,9 @@ class InterfaceTypeDefinition extends TypeDefinitionWithFieldSet @override FieldDefinition getField(String fieldName) => _fields.firstWhere( (field) => field.name == fieldName, - orElse: () => throw StateError( + orElse: (() => throw StateError( "No such field $fieldName on $this", - ), + )) as FieldDefinition Function()?, ); @override @@ -150,7 +150,7 @@ class InterfaceTypeDefinition extends TypeDefinitionWithFieldSet class ObjectTypeDefinition extends TypeDefinitionWithFieldSet { const ObjectTypeDefinition( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : super(getType); @override @@ -171,9 +171,9 @@ class ObjectTypeDefinition extends TypeDefinitionWithFieldSet { @override FieldDefinition getField(String fieldName) => _fields.firstWhere( (field) => field.name == fieldName, - orElse: () => throw StateError( + orElse: (() => throw StateError( "No such field $fieldName on $this", - ), + )) as FieldDefinition Function()?, ); List get interfaceNames => astNode.interfaces @@ -182,14 +182,14 @@ class ObjectTypeDefinition extends TypeDefinitionWithFieldSet { ) .toList(); - List get interfaces => interfaceNames - .map((i) => getType(i.name) as InterfaceTypeDefinition) + List get interfaces => interfaceNames + .map((i) => getType(i.name) as InterfaceTypeDefinition?) .toList(); /// Extract all inherited interface names recursively - Set get _inheritedFieldNames => interfaces + Set get _inheritedFieldNames => interfaces .expand( - (face) => face._fields.map((f) => f.name), + (face) => face!._fields.map((f) => f.name), ) .toSet(); } @@ -206,7 +206,7 @@ class ObjectTypeDefinition extends TypeDefinitionWithFieldSet { class UnionTypeDefinition extends TypeDefinitionWithResolver with AbstractType { const UnionTypeDefinition( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext; @override @@ -242,7 +242,7 @@ class UnionTypeDefinition extends TypeDefinitionWithResolver with AbstractType { class InputObjectTypeDefinition extends TypeDefinitionWithResolver { const InputObjectTypeDefinition( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext; @override @@ -264,25 +264,25 @@ class InputObjectTypeDefinition extends TypeDefinitionWithResolver { class InputValueDefinition extends EntityWithResolver { const InputValueDefinition( this.astNode, [ - ResolveType getType, + ResolveType? getType, ]) : getType = getType ?? TypeResolver.withoutContext; @override final ResolveType getType; @override - final InputValueDefinitionNode astNode; + final InputValueDefinitionNode? astNode; - String get name => astNode.name.value; + String? get name => astNode!.name.value; - String get description => astNode.description?.value; + String? get description => astNode!.description?.value; - GraphQLType get type => GraphQLType.fromNode(astNode.type, getType); + GraphQLType? get type => GraphQLType.fromNode(astNode!.type, getType); - Value get defaultValue => Value.fromNode(astNode.defaultValue); + Value? get defaultValue => Value.fromNode(astNode!.defaultValue); - List get directives => - astNode.directives.map((d) => Directive(d)).toList(); + List? get directives => + astNode!.directives.map((d) => Directive(d)).toList(); } /* @@ -341,17 +341,17 @@ class DirectiveDefinition extends TypeSystemDefinition { const DirectiveDefinition(this.astNode); @override - final DirectiveDefinitionNode astNode; + final DirectiveDefinitionNode? astNode; - String get description => astNode.description?.value; + String? get description => astNode!.description?.value; - List get args => astNode.args + List? get args => astNode!.args .map((inputValue) => InputValueDefinition(inputValue)) .toList(); - List get locations => astNode.locations; + List? get locations => astNode!.locations; - bool get repeatable => astNode.repeatable; + bool get repeatable => astNode!.repeatable; } /// A [Root Operation](https://spec.graphql.org/June2018/#sec-Root-Operation-Types). diff --git a/gql/lib/src/schema/definitions/type_resolver.dart b/gql/lib/src/schema/definitions/type_resolver.dart index 278c6742..439eaeb9 100644 --- a/gql/lib/src/schema/definitions/type_resolver.dart +++ b/gql/lib/src/schema/definitions/type_resolver.dart @@ -9,7 +9,7 @@ import "./definitions.dart" InputObjectTypeDefinition; /// Callback to dereference a full type definition by name -typedef ResolveType = TypeDefinition Function(String name); +typedef ResolveType = TypeDefinition? Function(String name); /// Enables "type resolution" for implementing classes, /// allowing for type-dereferencing, such as is done by `GraphQLSchema`. @@ -22,8 +22,8 @@ abstract class TypeResolver { ResolveType get getType; /// Saturates the [definition] with a [getType] if it extends from [TypeResolver] - static TypeDefinition addedTo( - TypeDefinition definition, + static TypeDefinition? addedTo( + TypeDefinition? definition, ResolveType getType, ) { if (definition == null) { diff --git a/gql/lib/src/schema/definitions/value_types.dart b/gql/lib/src/schema/definitions/value_types.dart index dd9b373f..bf92993a 100644 --- a/gql/lib/src/schema/definitions/value_types.dart +++ b/gql/lib/src/schema/definitions/value_types.dart @@ -21,9 +21,9 @@ abstract class Value extends GraphQLEntity { const Value(); @override - ValueNode get astNode; + ValueNode? get astNode; - static Value fromNode(ValueNode node) { + static Value fromNode(ValueNode? node) { if (node is IntValueNode) { return IntValue(node); } @@ -79,9 +79,9 @@ class StringValue extends Value { const StringValue(this.astNode); @override - final StringValueNode astNode; + final StringValueNode? astNode; - String get value => astNode.value; + String get value => astNode!.value; } @immutable @@ -155,9 +155,9 @@ class DefaultValue extends GraphQLEntity { const DefaultValue(this.astNode); @override - final DefaultValueNode astNode; + final DefaultValueNode? astNode; - Value get value => Value.fromNode(astNode.value); + Value get value => Value.fromNode(astNode!.value); } // While I don't believe VariableValues are possible in the schema definition, diff --git a/gql/lib/src/schema/schema.dart b/gql/lib/src/schema/schema.dart index 66ce0e3d..1b17e996 100644 --- a/gql/lib/src/schema/schema.dart +++ b/gql/lib/src/schema/schema.dart @@ -1,5 +1,6 @@ import "dart:collection"; +import 'package:collection/collection.dart' show IterableExtension; import "package:meta/meta.dart"; import "package:gql/ast.dart"; @@ -21,35 +22,34 @@ class GraphQLSchema extends TypeSystemDefinition { const GraphQLSchema( this.astNode, { this.fullDocumentAst, - Map typeMap, + Map? typeMap, this.directives, }) : _typeMap = typeMap; @override - final SchemaDefinitionNode astNode; + final SchemaDefinitionNode? astNode; - final DocumentNode fullDocumentAst; + final DocumentNode? fullDocumentAst; - final List directives; + final List? directives; /// Definition for the given directive [name], if any exists - DirectiveDefinition getDirective(String name) => directives.firstWhere( + DirectiveDefinition? getDirective(String name) => directives!.firstWhereOrNull( (d) => d.name == name, - orElse: () => null, ); - List get operationTypes => astNode.operationTypes + List get operationTypes => astNode!.operationTypes .map( (o) => OperationTypeDefinition(o), ) .toList(); /// Map of all type names to their respective [TypeDefinition]s - final Map _typeMap; + final Map? _typeMap; /// Map of all type names to their respective [TypeDefinition]s, /// with type resolution enabled (if applicable) - Map get typeMap => _typeMap.map( + Map get typeMap => _typeMap!.map( (name, definition) => MapEntry( name, _withAwareness(definition), @@ -60,21 +60,21 @@ class GraphQLSchema extends TypeSystemDefinition { /// /// [EnumTypeDefinition] and [ScalarTypeDefinition] do not accept [getType] /// because they cannot include references - TypeDefinition _withAwareness(TypeDefinition definition) => + TypeDefinition? _withAwareness(TypeDefinition? definition) => TypeResolver.addedTo(definition, getType) ?? definition; /// Resolve the given [name] into a [TypeDefinition] defined within the schema - TypeDefinition getType(String name) => _withAwareness(_typeMap[name]); + TypeDefinition? getType(String name) => _withAwareness(_typeMap![name]); - ObjectTypeDefinition _getObjectType(String name) => - _withAwareness(_typeMap[name]) as ObjectTypeDefinition; + ObjectTypeDefinition? _getObjectType(String name) => + _withAwareness(_typeMap![name]) as ObjectTypeDefinition?; - Iterable get _allTypeDefinitions => - LinkedHashSet.from(_typeMap.values).map(_withAwareness); + Iterable get _allTypeDefinitions => + LinkedHashSet.from(_typeMap!.values).map(_withAwareness); - ObjectTypeDefinition get query => _getObjectType("query"); - ObjectTypeDefinition get mutation => _getObjectType("mutation"); - ObjectTypeDefinition get subscription => _getObjectType("subscription"); + ObjectTypeDefinition? get query => _getObjectType("query"); + ObjectTypeDefinition? get mutation => _getObjectType("mutation"); + ObjectTypeDefinition? get subscription => _getObjectType("subscription"); List get interaces => _getAll(); @@ -93,7 +93,7 @@ class GraphQLSchema extends TypeSystemDefinition { _allTypeDefinitions.whereType().toList(); /// Get the possible [ObjectTypeDefinition]s that the given [abstractType] could be resolved into - List getPossibleTypes(AbstractType abstractType) { + List getPossibleTypes(AbstractType? abstractType) { if (abstractType is UnionTypeDefinition) { return abstractType.types; } @@ -128,7 +128,7 @@ GraphQLSchema buildSchema( assertValidSDL(documentAST); } */ - SchemaDefinitionNode schemaDef; + SchemaDefinitionNode? schemaDef; final _typeDefs = []; final _directiveDefs = []; @@ -165,16 +165,16 @@ GraphQLSchema buildSchema( ); } -Map _operationTypeMap( - Map typeMap, - SchemaDefinitionNode schemaDef, +Map _operationTypeMap( + Map typeMap, + SchemaDefinitionNode? schemaDef, ) { final operationTypeNames = _getOperationTypeNames(schemaDef); return Map.fromEntries( operationTypeNames.entries .map((e) => MapEntry( e.key.name, - typeMap[e.value] as ObjectTypeDefinition, + typeMap[e.value] as ObjectTypeDefinition?, )) .where((e) => e.value != null), ); @@ -182,7 +182,7 @@ Map _operationTypeMap( /// Resolve a map of { [OperationType]: [String] typeName } Map _getOperationTypeNames( - [SchemaDefinitionNode schema]) { + [SchemaDefinitionNode? schema]) { if (schema == null) { return { OperationType.query: "Query", diff --git a/gql/lib/src/validation/rules/lone_schema_definition.dart b/gql/lib/src/validation/rules/lone_schema_definition.dart index c10e17a6..c987d9dd 100644 --- a/gql/lib/src/validation/rules/lone_schema_definition.dart +++ b/gql/lib/src/validation/rules/lone_schema_definition.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class MultipleSchemaDefinitionsError extends ValidationError { const MultipleSchemaDefinitionsError({ - SchemaDefinitionNode node, + SchemaDefinitionNode? node, }) : super( node: node, ); diff --git a/gql/lib/src/validation/rules/unique_argument_names.dart b/gql/lib/src/validation/rules/unique_argument_names.dart index 31562ada..2b98a87e 100644 --- a/gql/lib/src/validation/rules/unique_argument_names.dart +++ b/gql/lib/src/validation/rules/unique_argument_names.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class DuplicateArgumentNameError extends ValidationError { const DuplicateArgumentNameError({ - ArgumentNode node, + ArgumentNode? node, }) : super( node: node, ); diff --git a/gql/lib/src/validation/rules/unique_directive_names.dart b/gql/lib/src/validation/rules/unique_directive_names.dart index 2a1b1351..2121bdd0 100644 --- a/gql/lib/src/validation/rules/unique_directive_names.dart +++ b/gql/lib/src/validation/rules/unique_directive_names.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class DuplicateDirectiveNameError extends ValidationError { const DuplicateDirectiveNameError({ - DirectiveDefinitionNode node, + DirectiveDefinitionNode? node, }) : super( node: node, ); @@ -16,13 +16,13 @@ class UniqueDirectiveNames extends ValidatingVisitor { @override List visitDirectiveDefinitionNode( DirectiveDefinitionNode node) { - if (directiveNames.contains(node.name.value)) { + if (directiveNames.contains(node.name!.value)) { return [ DuplicateDirectiveNameError(node: node), ]; } - directiveNames.add(node.name.value); + directiveNames.add(node.name!.value); return []; } diff --git a/gql/lib/src/validation/rules/unique_enum_value_names.dart b/gql/lib/src/validation/rules/unique_enum_value_names.dart index 54a57ef9..7199b24a 100644 --- a/gql/lib/src/validation/rules/unique_enum_value_names.dart +++ b/gql/lib/src/validation/rules/unique_enum_value_names.dart @@ -3,11 +3,11 @@ import "package:gql/src/validation/validating_visitor.dart"; import "package:gql/src/validation/validator.dart"; class DuplicateEnumValueNameError extends ValidationError { - final EnumValueDefinitionNode valueNode; + final EnumValueDefinitionNode? valueNode; const DuplicateEnumValueNameError({ this.valueNode, - NameNode nameNode, + NameNode? nameNode, }) : super( node: nameNode, ); @@ -31,7 +31,7 @@ class UniqueEnumValueNames extends ValidatingVisitor { node.values.fold<_Accumulator>( _Accumulator(), (fold, node) { - if (fold.valueNames.contains(node.name.value)) { + if (fold.valueNames.contains(node.name!.value)) { return _Accumulator( valueNames: fold.valueNames, errors: [ @@ -47,7 +47,7 @@ class UniqueEnumValueNames extends ValidatingVisitor { return _Accumulator( valueNames: [ ...fold.valueNames, - node.name.value, + node.name!.value, ], errors: fold.errors, ); diff --git a/gql/lib/src/validation/rules/unique_field_definition_names.dart b/gql/lib/src/validation/rules/unique_field_definition_names.dart index 42c9e119..1e874466 100644 --- a/gql/lib/src/validation/rules/unique_field_definition_names.dart +++ b/gql/lib/src/validation/rules/unique_field_definition_names.dart @@ -3,11 +3,11 @@ import "package:gql/src/validation/validating_visitor.dart"; import "package:gql/src/validation/validator.dart"; class DuplicateFieldDefinitionNameError extends ValidationError { - final TypeDefinitionNode typeNode; + final TypeDefinitionNode? typeNode; const DuplicateFieldDefinitionNameError({ this.typeNode, - NameNode nameNode, + NameNode? nameNode, }) : super( node: nameNode, ); diff --git a/gql/lib/src/validation/rules/unique_input_field_names.dart b/gql/lib/src/validation/rules/unique_input_field_names.dart index 7336fa8f..5e8f451d 100644 --- a/gql/lib/src/validation/rules/unique_input_field_names.dart +++ b/gql/lib/src/validation/rules/unique_input_field_names.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class DuplicateInputFieldNameError extends ValidationError { const DuplicateInputFieldNameError({ - ObjectFieldNode node, + ObjectFieldNode? node, }) : super( node: node, ); diff --git a/gql/lib/src/validation/rules/unique_operation_types.dart b/gql/lib/src/validation/rules/unique_operation_types.dart index 5a704b1d..607fe4c8 100644 --- a/gql/lib/src/validation/rules/unique_operation_types.dart +++ b/gql/lib/src/validation/rules/unique_operation_types.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class DuplicateOperationTypeError extends ValidationError { const DuplicateOperationTypeError({ - OperationTypeDefinitionNode node, + OperationTypeDefinitionNode? node, }) : super( node: node, ); diff --git a/gql/lib/src/validation/rules/unique_type_names.dart b/gql/lib/src/validation/rules/unique_type_names.dart index d0534802..33663df8 100644 --- a/gql/lib/src/validation/rules/unique_type_names.dart +++ b/gql/lib/src/validation/rules/unique_type_names.dart @@ -4,7 +4,7 @@ import "package:gql/src/validation/validator.dart"; class DuplicateTypeNameError extends ValidationError { const DuplicateTypeNameError({ - TypeDefinitionNode node, + TypeDefinitionNode? node, }) : super( node: node, ); @@ -14,13 +14,13 @@ class UniqueTypeNames extends ValidatingVisitor { List typeDefinitionsNames = []; List _visitTypeDefinitionNode(TypeDefinitionNode node) { - if (typeDefinitionsNames.contains(node.name.value)) { + if (typeDefinitionsNames.contains(node.name!.value)) { return [ DuplicateTypeNameError(node: node), ]; } - typeDefinitionsNames.add(node.name.value); + typeDefinitionsNames.add(node.name!.value); return []; } diff --git a/gql/lib/src/validation/validator.dart b/gql/lib/src/validation/validator.dart index 4c32aff2..573c4606 100644 --- a/gql/lib/src/validation/validator.dart +++ b/gql/lib/src/validation/validator.dart @@ -78,8 +78,8 @@ List validateRequest( /// A base class for validation errors @immutable abstract class ValidationError { - final String message; - final ast.Node node; + final String? message; + final ast.Node? node; const ValidationError({ this.message, @@ -99,7 +99,7 @@ enum ValidationRule { uniqueArgumentNames } -ValidatingVisitor _mapRule(ValidationRule rule) { +ValidatingVisitor? _mapRule(ValidationRule rule) { switch (rule) { case ValidationRule.uniqueDirectiveNames: return UniqueDirectiveNames(); @@ -123,17 +123,17 @@ ValidatingVisitor _mapRule(ValidationRule rule) { } class _Validator { - Set rules; + Set? rules; _Validator({ this.rules, }); List validate({ - ast.Node node, + required ast.Node node, }) { final visitor = ast.AccumulatingVisitor( - visitors: rules.map(_mapRule).toList(), + visitors: rules!.map(_mapRule).toList(), ); node.accept(visitor); diff --git a/gql/pubspec.yaml b/gql/pubspec.yaml index ae23a377..f546c2fd 100644 --- a/gql/pubspec.yaml +++ b/gql/pubspec.yaml @@ -2,14 +2,14 @@ name: gql version: 0.12.4 description: GraphQL tools for parsing, transforming and printing GraphQL documents. repository: https://github.com/gql-dart/gql -environment: - sdk: '>=2.7.2 <3.0.0' -dependencies: - source_span: ^1.5.5 - meta: ^1.1.7 - collection: ^1.14.11 -dev_dependencies: - test: ^1.0.0 - gql_pedantic: ^1.0.1 - cats: +environment: + sdk: '>=2.12.0-259.9.beta <3.0.0' +dependencies: + collection: ^1.15.0 + meta: ^1.3.0 + source_span: ^1.8.1 +dev_dependencies: + cats: path: ../cats + gql_pedantic: ^1.0.2 + test: ^1.16.0 diff --git a/gql/test/lexer_test.dart b/gql/test/lexer_test.dart index eb102b74..74eb03f7 100644 --- a/gql/test/lexer_test.dart +++ b/gql/test/lexer_test.dart @@ -3,27 +3,27 @@ import "package:source_span/source_span.dart"; import "package:test/test.dart"; Matcher token({ - TokenKind kind, - int start, - int end, - int line, - int column, - String value, + TokenKind? kind, + int? start, + int? end, + int? line, + int? column, + String? value, }) => predicate( (Token token) => token.kind == kind && - token.span.start.offset == start && - token.span.end.offset == end && - token.span.start.line == line - 1 && - token.span.start.column == column - 1 && + token.span!.start.offset == start && + token.span!.end.offset == end && + token.span!.start.line == line! - 1 && + token.span!.start.column == column! - 1 && (value == null || token.value == value), "token of ${kind} at $line:$column($start-$end) $value", ); void main() { group("Lexer", () { - Lexer lexer; + late Lexer lexer; List tokenize(String text, {bool skipComments = true}) => lexer.tokenize( diff --git a/gql/test/operation_test.dart b/gql/test/operation_test.dart index 20ee0417..a2828587 100644 --- a/gql/test/operation_test.dart +++ b/gql/test/operation_test.dart @@ -15,7 +15,7 @@ void main() { test("Can dereference schemaType", () { final query = document.operations.first; - expect(query.schemaType.name, equals("StarWarsQuery")); + expect(query.schemaType!.name, equals("StarWarsQuery")); }); }); @@ -29,7 +29,7 @@ void main() { test("Can dereference fragmentType", () { final mutationField = document.operations.first.selectionSet.fields.first; - final spreads = mutationField.selectionSet.fragmentSpreads; + final spreads = mutationField.selectionSet!.fragmentSpreads; expect(spreads.first.fragment.name, equals("info")); final relationships = spreads[1].fragment; @@ -37,7 +37,7 @@ void main() { final relationshipsFriends = relationships.selectionSet.fields.first; expect( - relationshipsFriends.selectionSet.fragmentSpreads.first.fragment.name, + relationshipsFriends.selectionSet!.fragmentSpreads.first.fragment.name, equals("friendNetwork"), ); }); diff --git a/gql/test/parser_test.dart b/gql/test/parser_test.dart index 8172d28a..313f408a 100644 --- a/gql/test/parser_test.dart +++ b/gql/test/parser_test.dart @@ -2,12 +2,12 @@ import "package:gql/src/language/parser.dart"; import "package:source_span/source_span.dart"; import "package:test/test.dart"; -final throwsSourceSpanException = ( +final Matcher Function(String, int, int, [int, int]) throwsSourceSpanException = ( String message, int startLine, int startColumn, [ - int endLine, - int endColumn, + int? endLine, + int? endColumn, ]) => throwsA( allOf( @@ -18,10 +18,10 @@ final throwsSourceSpanException = ( ), predicate( (SourceSpanException e) => - e.span.start.line == startLine - 1 && - e.span.start.column == startColumn - 1 && - e.span.end.line == (endLine ?? startLine) - 1 && - e.span.end.column == (endColumn ?? startColumn + 1) - 1, + e.span!.start.line == startLine - 1 && + e.span!.start.column == startColumn - 1 && + e.span!.end.line == (endLine ?? startLine) - 1 && + e.span!.end.column == (endColumn ?? startColumn + 1) - 1, "span matches", ), ), diff --git a/gql/test/scenarios_test.dart b/gql/test/scenarios_test.dart index 81fd54de..9d0ffd3f 100644 --- a/gql/test/scenarios_test.dart +++ b/gql/test/scenarios_test.dart @@ -9,7 +9,7 @@ class RecursiveVisitor extends ast.RecursiveVisitor {} class MyDriver extends CatDriver { @override ast.DocumentNode parse({ - source, + required source, }) => lang.parseString(source); @@ -18,7 +18,7 @@ class MyDriver extends CatDriver { schema, dynamic testData, query, - String operation, + String? operation, variables, }) => null; diff --git a/gql/test/schema_test.dart b/gql/test/schema_test.dart index fc5e6551..2d0672ba 100644 --- a/gql/test/schema_test.dart +++ b/gql/test/schema_test.dart @@ -25,7 +25,7 @@ void main() { test("Can dereference an object interace", () { final droid = schema.getType("Droid") as ObjectTypeDefinition; expect( - droid.interfaces[0].name, + droid.interfaces[0]!.name, equals("Character"), ); }); @@ -44,25 +44,25 @@ void main() { }); test("schema.getPossibleTypes results", () { - final character = schema.getType("Character") as InterfaceTypeDefinition; + final character = schema.getType("Character") as InterfaceTypeDefinition?; final searchResult = schema.getType( "SearchResult", - ) as UnionTypeDefinition; + ) as UnionTypeDefinition?; - final human = schema.getType("Human") as ObjectTypeDefinition; - final droid = schema.getType("Droid") as ObjectTypeDefinition; - final starship = schema.getType("Starship") as ObjectTypeDefinition; + final human = schema.getType("Human") as ObjectTypeDefinition?; + final droid = schema.getType("Droid") as ObjectTypeDefinition?; + final starship = schema.getType("Starship") as ObjectTypeDefinition?; expect( schema.getPossibleTypes(searchResult), unorderedEquals( - {droid, starship, human}, + {droid, starship, human}, ), ); expect( schema.getPossibleTypes(character), - unorderedEquals({ + unorderedEquals({ droid, human, }), @@ -70,50 +70,50 @@ void main() { }); test("Type dereferencing", () { - final starshipsType = schema.query.getField("starships").type as ListType; + final starshipsType = schema.query!.getField("starships").type as ListType; expect(starshipsType.baseTypeName, equals("Starship")); - final starship = (starshipsType.type as NamedType).type; + final starship = (starshipsType.type as NamedType).type!; expect(starship.runtimeType, equals(ObjectTypeDefinition)); expect(starship.name, equals("Starship")); }); test("mutation arguments", () { - final updateHuman = schema.mutation.getField("updateHuman"); + final updateHuman = schema.mutation!.getField("updateHuman"); - expect(updateHuman.args.first.name, equals("id")); - expect(updateHuman.args.first.type.isNonNull, equals(true)); + expect(updateHuman.args!.first.name, equals("id")); + expect(updateHuman.args!.first.type!.isNonNull, equals(true)); - final inputTypeRef = updateHuman.args.last.type as NamedType; + final inputTypeRef = updateHuman.args!.last.type as NamedType; expect(inputTypeRef.name, equals("HumanInput")); expect(inputTypeRef.isNonNull, equals(true)); expect(inputTypeRef.hasResolver, equals(true)); - final inputType = inputTypeRef.type; + final inputType = inputTypeRef.type!; expect(inputType.runtimeType, equals(InputObjectTypeDefinition)); expect(inputType.name, equals("HumanInput")); }); test("mutation arguments", () { - final updateHuman = schema.mutation.getField("updateHuman"); + final updateHuman = schema.mutation!.getField("updateHuman"); - expect(updateHuman.args.first.name, equals("id")); - expect(updateHuman.args.first.type.isNonNull, equals(true)); + expect(updateHuman.args!.first.name, equals("id")); + expect(updateHuman.args!.first.type!.isNonNull, equals(true)); - final inputTypeRef = updateHuman.args.last.type as NamedType; + final inputTypeRef = updateHuman.args!.last.type as NamedType; expect(inputTypeRef.name, equals("HumanInput")); expect(inputTypeRef.isNonNull, equals(true)); expect(inputTypeRef.hasResolver, equals(true)); - final inputType = inputTypeRef.type; + final inputType = inputTypeRef.type!; expect(inputType.runtimeType, equals(InputObjectTypeDefinition)); expect(inputType.name, equals("HumanInput")); }); test("Contains default directives", () { expect( - schema.directives.map((d) => d.name), + schema.directives!.map((d) => d.name), containsAll({"skip", "include", "deprecated"}), ); }); From fa1edbb1516efe4fdbeb9c92ae9d84bacba8b53a Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:04:10 -0600 Subject: [PATCH 03/42] applied quick fixes to ast.dart --- gql/lib/src/ast/ast.dart | 188 +++++++++------------------------------ 1 file changed, 44 insertions(+), 144 deletions(-) diff --git a/gql/lib/src/ast/ast.dart b/gql/lib/src/ast/ast.dart index 7b2bdf73..ee3bb6ba 100644 --- a/gql/lib/src/ast/ast.dart +++ b/gql/lib/src/ast/ast.dart @@ -7,13 +7,13 @@ void _visitOne( Node node, Visitor v, ) => - node?.accept(v); + node.accept(v); void _visitAll( List nodes, Visitor v, ) => - nodes?.forEach( + nodes.forEach( (node) => _visitOne(node, v), ); @@ -68,8 +68,7 @@ class DocumentNode extends Node { const DocumentNode({ this.definitions = const [], FileSpan? span, - }) : assert(definitions != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitDocumentNode(this); @@ -144,10 +143,7 @@ class OperationDefinitionNode extends ExecutableDefinitionNode { this.directives = const [], required this.selectionSet, FileSpan? span, - }) : assert(variableDefinitions != null), - assert(directives != null), - assert(selectionSet != null), - super( + }) : super( name: name, span: span, ); @@ -204,10 +200,7 @@ class FieldNode extends SelectionNode { this.directives = const [], this.selectionSet, FileSpan? span, - }) : assert(name != null), - assert(arguments != null), - assert(directives != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitFieldNode(this); @@ -231,9 +224,7 @@ class ArgumentNode extends Node { required this.name, required this.value, FileSpan? span, - }) : assert(name != null), - assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitArgumentNode(this); @@ -254,9 +245,7 @@ class FragmentSpreadNode extends SelectionNode { required this.name, this.directives = const [], FileSpan? span, - }) : assert(name != null), - assert(directives != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitFragmentSpreadNode(this); @@ -280,9 +269,7 @@ class InlineFragmentNode extends SelectionNode { this.directives = const [], required this.selectionSet, FileSpan? span, - }) : assert(directives != null), - assert(selectionSet != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitInlineFragmentNode(this); @@ -308,11 +295,7 @@ class FragmentDefinitionNode extends ExecutableDefinitionNode { this.directives = const [], required this.selectionSet, FileSpan? span, - }) : assert(name != null), - assert(typeCondition != null), - assert(directives != null), - assert(selectionSet != null), - super( + }) : super( name: name, span: span, ); @@ -335,8 +318,7 @@ class TypeConditionNode extends Node { const TypeConditionNode({ required this.on, FileSpan? span, - }) : assert(on != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitTypeConditionNode(this); @@ -357,8 +339,7 @@ class VariableNode extends ValueNode { const VariableNode({ required this.name, FileSpan? span, - }) : assert(name != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitVariableNode(this); @@ -375,8 +356,7 @@ class IntValueNode extends ValueNode { const IntValueNode({ required this.value, FileSpan? span, - }) : assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitIntValueNode(this); @@ -393,8 +373,7 @@ class FloatValueNode extends ValueNode { const FloatValueNode({ required this.value, FileSpan? span, - }) : assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitFloatValueNode(this); @@ -414,9 +393,7 @@ class StringValueNode extends ValueNode { required this.value, required this.isBlock, FileSpan? span, - }) : assert(value != null), - assert(isBlock != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitStringValueNode(this); @@ -434,8 +411,7 @@ class BooleanValueNode extends ValueNode { const BooleanValueNode({ required this.value, FileSpan? span, - }) : assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitBooleanValueNode(this); @@ -464,8 +440,7 @@ class EnumValueNode extends ValueNode { const EnumValueNode({ required this.name, FileSpan? span, - }) : assert(name != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitEnumValueNode(this); @@ -519,9 +494,7 @@ class ObjectFieldNode extends Node { required this.name, required this.value, FileSpan? span, - }) : assert(name != null), - assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitObjectFieldNode(this); @@ -548,10 +521,7 @@ class VariableDefinitionNode extends Node { this.defaultValue, this.directives = const [], FileSpan? span, - }) : assert(variable != null), - assert(type != null), - assert(directives != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitVariableDefinitionNode(this); @@ -585,9 +555,7 @@ class DefaultValueNode extends Node { abstract class TypeNode extends Node { final bool isNonNull; - const TypeNode(this.isNonNull, FileSpan? span) - : assert(isNonNull != null), - super(span); + const TypeNode(this.isNonNull, FileSpan? span) : super(span); } class NamedTypeNode extends TypeNode { @@ -597,9 +565,7 @@ class NamedTypeNode extends TypeNode { required this.name, bool isNonNull = false, FileSpan? span, - }) : assert(name != null), - assert(isNonNull != null), - super(isNonNull, span); + }) : super(isNonNull, span); @override R accept(Visitor v) => v.visitNamedTypeNode(this); @@ -618,9 +584,7 @@ class ListTypeNode extends TypeNode { required this.type, required bool isNonNull, FileSpan? span, - }) : assert(type != null), - assert(isNonNull != null), - super(isNonNull, span); + }) : super(isNonNull, span); @override R accept(Visitor v) => v.visitListTypeNode(this); @@ -641,9 +605,7 @@ class DirectiveNode extends Node { required this.name, this.arguments = const [], FileSpan? span, - }) : assert(name != null), - assert(arguments != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitDirectiveNode(this); @@ -661,8 +623,7 @@ class NameNode extends Node { const NameNode({ required this.value, FileSpan? span, - }) : assert(value != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitNameNode(this); @@ -692,9 +653,7 @@ abstract class TypeDefinitionNode extends TypeSystemDefinitionNode { required NameNode name, this.directives = const [], FileSpan? span, - }) : assert(name != null), - assert(directives != null), - super( + }) : super( name: name, span: span, ); @@ -717,9 +676,7 @@ abstract class TypeExtensionNode extends TypeSystemExtensionNode { FileSpan? span, required NameNode name, this.directives = const [], - }) : assert(name != null), - assert(directives != null), - super( + }) : super( name: name, span: span, ); @@ -733,9 +690,7 @@ class SchemaDefinitionNode extends TypeSystemDefinitionNode { this.directives = const [], this.operationTypes = const [], FileSpan? span, - }) : assert(directives != null), - assert(operationTypes != null), - super( + }) : super( name: null, span: span, ); @@ -758,9 +713,7 @@ class OperationTypeDefinitionNode extends Node { required this.operation, required this.type, FileSpan? span, - }) : assert(operation != null), - assert(type != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitOperationTypeDefinitionNode(this); @@ -778,9 +731,7 @@ class ScalarTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -809,11 +760,7 @@ class ObjectTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(interfaces != null), - assert(fields != null), - assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -847,11 +794,7 @@ class FieldDefinitionNode extends Node { this.args = const [], this.directives = const [], FileSpan? span, - }) : assert(type != null), - assert(args != null), - assert(name != null), - assert(directives != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitFieldDefinitionNode(this); @@ -880,11 +823,7 @@ class InputValueDefinitionNode extends Node { this.defaultValue, this.directives = const [], FileSpan? span, - }) : assert(type != null), - assert(name != null), - assert(type != null), - assert(directives != null), - super(span); + }) : super(span); @override R accept(Visitor v) => v.visitInputValueDefinitionNode(this); @@ -908,10 +847,7 @@ class InterfaceTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(fields != null), - assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -939,10 +875,7 @@ class UnionTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(types != null), - assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -970,10 +903,7 @@ class EnumTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(values != null), - assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -1001,10 +931,7 @@ class EnumValueDefinitionNode extends TypeDefinitionNode { List directives = const [], FileSpan? span, this.fallback = false, - }) : assert(name != null), - assert(directives != null), - assert(fallback != null), - super( + }) : super( span: span, name: name, description: description, @@ -1031,10 +958,7 @@ class InputObjectTypeDefinitionNode extends TypeDefinitionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(fields != null), - assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, description: description, @@ -1066,11 +990,7 @@ class DirectiveDefinitionNode extends TypeSystemDefinitionNode { this.locations = const [], this.repeatable = false, FileSpan? span, - }) : assert(name != null), - assert(args != null), - assert(locations != null), - assert(repeatable != null), - super( + }) : super( name: name, span: span, ); @@ -1096,9 +1016,7 @@ class SchemaExtensionNode extends TypeSystemExtensionNode { this.directives = const [], this.operationTypes = const [], FileSpan? span, - }) : assert(directives != null), - assert(operationTypes != null), - super( + }) : super( name: null, span: span, ); @@ -1119,9 +1037,7 @@ class ScalarTypeExtensionNode extends TypeExtensionNode { FileSpan? span, required NameNode name, List directives = const [], - }) : assert(name != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, @@ -1147,11 +1063,7 @@ class ObjectTypeExtensionNode extends TypeExtensionNode { this.fields = const [], FileSpan? span, List directives = const [], - }) : assert(name != null), - assert(interfaces != null), - assert(fields != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, @@ -1177,10 +1089,7 @@ class InterfaceTypeExtensionNode extends TypeExtensionNode { required NameNode name, FileSpan? span, List directives = const [], - }) : assert(name != null), - assert(fields != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, @@ -1205,10 +1114,7 @@ class UnionTypeExtensionNode extends TypeExtensionNode { required NameNode name, List directives = const [], FileSpan? span, - }) : assert(name != null), - assert(types != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, @@ -1233,10 +1139,7 @@ class EnumTypeExtensionNode extends TypeExtensionNode { FileSpan? span, required NameNode name, List directives = const [], - }) : assert(name != null), - assert(values != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, @@ -1261,10 +1164,7 @@ class InputObjectTypeExtensionNode extends TypeExtensionNode { FileSpan? span, required NameNode name, List directives = const [], - }) : assert(name != null), - assert(fields != null), - assert(directives != null), - super( + }) : super( span: span, name: name, directives: directives, From 924352d83bffe59a17e77511ac79583533ea5a09 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:09:16 -0600 Subject: [PATCH 04/42] more suggestions and quickfixes --- cats/lib/src/cats_base.dart | 2 +- gql/lib/src/ast/transformer.dart | 23 ++++++++----------- gql/lib/src/language/lexer.dart | 10 +++----- .../src/schema/definitions/definitions.dart | 9 ++++---- gql/lib/src/schema/schema.dart | 5 ++-- gql/test/scenarios_test.dart | 2 +- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/cats/lib/src/cats_base.dart b/cats/lib/src/cats_base.dart index 4bb26388..13ab6e2f 100644 --- a/cats/lib/src/cats_base.dart +++ b/cats/lib/src/cats_base.dart @@ -4,7 +4,7 @@ import './cat_model.dart'; abstract class CatDriver { Doc parse({ - String? source, + required String source, }); Iterable validate({ diff --git a/gql/lib/src/ast/transformer.dart b/gql/lib/src/ast/transformer.dart index 84d9bc52..ec009809 100644 --- a/gql/lib/src/ast/transformer.dart +++ b/gql/lib/src/ast/transformer.dart @@ -303,19 +303,16 @@ class _Transformer extends Visitor { List _visitAll( List nodes, - ) { - if (nodes == null) return nodes; - - return nodes - .map( - ( - node, - ) => - node.accept(this), - ) - .cast() - .toList(growable: false); - } + ) => + nodes + .map( + ( + node, + ) => + node.accept(this), + ) + .cast() + .toList(growable: false); @override DocumentNode visitDocumentNode( diff --git a/gql/lib/src/language/lexer.dart b/gql/lib/src/language/lexer.dart index 7d9f536f..53ae0a76 100644 --- a/gql/lib/src/language/lexer.dart +++ b/gql/lib/src/language/lexer.dart @@ -304,7 +304,7 @@ class _Scanner { if (code >= 48 && code <= 57) { do { code = peek(offset: ++digitOffset)!; - } while (code != null && code >= 48 && code <= 57); + } while (code >= 48 && code <= 57); return digitOffset; } @@ -352,7 +352,7 @@ class _Scanner { ); } - if (code == null || (code < 0x0020 && code != 0x0009)) { + if (code < 0x0020 && code != 0x0009) { throw SourceSpanException( "Unexpected character in a string literal", src.span( @@ -429,11 +429,7 @@ class _Scanner { ); } - if (code == null || - (code < 0x0020 && - code != 0x0009 && - code != 0x000a && - code != 0x000d)) { + if (code < 0x0020 && code != 0x0009 && code != 0x000a && code != 0x000d) { throw SourceSpanException( "Unexpected character in a string literal", src.span(position, position), diff --git a/gql/lib/src/schema/definitions/definitions.dart b/gql/lib/src/schema/definitions/definitions.dart index aedb4a0a..40ce8a86 100644 --- a/gql/lib/src/schema/definitions/definitions.dart +++ b/gql/lib/src/schema/definitions/definitions.dart @@ -27,7 +27,6 @@ extension WithTypeName on OperationType { case OperationType.subscription: return "subscription"; } - throw StateError("Impossible OperationType $this"); } } @@ -117,9 +116,9 @@ class InterfaceTypeDefinition extends TypeDefinitionWithFieldSet @override FieldDefinition getField(String fieldName) => _fields.firstWhere( (field) => field.name == fieldName, - orElse: (() => throw StateError( + orElse: () => throw StateError( "No such field $fieldName on $this", - )) as FieldDefinition Function()?, + ), ); @override @@ -171,9 +170,9 @@ class ObjectTypeDefinition extends TypeDefinitionWithFieldSet { @override FieldDefinition getField(String fieldName) => _fields.firstWhere( (field) => field.name == fieldName, - orElse: (() => throw StateError( + orElse: () => throw StateError( "No such field $fieldName on $this", - )) as FieldDefinition Function()?, + ), ); List get interfaceNames => astNode.interfaces diff --git a/gql/lib/src/schema/schema.dart b/gql/lib/src/schema/schema.dart index 1b17e996..fdc5db2a 100644 --- a/gql/lib/src/schema/schema.dart +++ b/gql/lib/src/schema/schema.dart @@ -1,6 +1,6 @@ import "dart:collection"; -import 'package:collection/collection.dart' show IterableExtension; +import "package:collection/collection.dart" show IterableExtension; import "package:meta/meta.dart"; import "package:gql/ast.dart"; @@ -34,7 +34,8 @@ class GraphQLSchema extends TypeSystemDefinition { final List? directives; /// Definition for the given directive [name], if any exists - DirectiveDefinition? getDirective(String name) => directives!.firstWhereOrNull( + DirectiveDefinition? getDirective(String name) => + directives!.firstWhereOrNull( (d) => d.name == name, ); diff --git a/gql/test/scenarios_test.dart b/gql/test/scenarios_test.dart index 9d0ffd3f..e6120c06 100644 --- a/gql/test/scenarios_test.dart +++ b/gql/test/scenarios_test.dart @@ -29,7 +29,7 @@ class MyDriver extends CatDriver { query, validationRules, }) => - null; + []; } void main() { From a6805a8378177ac27eeac39bef188117c1a69236 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:17:48 -0600 Subject: [PATCH 05/42] suggestions and quickfixes for printer --- gql/lib/src/language/printer.dart | 75 +++++++------------ .../src/schema/definitions/type_resolver.dart | 1 - 2 files changed, 28 insertions(+), 48 deletions(-) diff --git a/gql/lib/src/language/printer.dart b/gql/lib/src/language/printer.dart index 9faf5710..17c3c84d 100644 --- a/gql/lib/src/language/printer.dart +++ b/gql/lib/src/language/printer.dart @@ -89,9 +89,9 @@ class _PrintVisitor extends Visitor { " ", op.name!.accept(this), ], - if (op.variableDefinitions != null && op.variableDefinitions.isNotEmpty) + if (op.variableDefinitions.isNotEmpty) visitVariableDefinitionSetNode(op.variableDefinitions), - if (op.directives != null && op.directives.isNotEmpty) ...[ + if (op.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(op.directives), ], @@ -106,8 +106,7 @@ class _PrintVisitor extends Visitor { String visitDirectiveNode(DirectiveNode directiveNode) => [ "@", directiveNode.name.accept(this), - if (directiveNode.arguments != null && - directiveNode.arguments.isNotEmpty) + if (directiveNode.arguments.isNotEmpty) visitArgumentSetNode(directiveNode.arguments), ].join(); @@ -209,45 +208,34 @@ class _PrintVisitor extends Visitor { [ "fragment ", fragmentDefinitionNode.name!.accept(this), - if (fragmentDefinitionNode.typeCondition != null) ...[ - " ", - fragmentDefinitionNode.typeCondition.accept(this), - ], - if (fragmentDefinitionNode.directives != null && - fragmentDefinitionNode.directives.isNotEmpty) ...[ + " ", + fragmentDefinitionNode.typeCondition.accept(this), + if (fragmentDefinitionNode.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(fragmentDefinitionNode.directives), ], - if (fragmentDefinitionNode.selectionSet != null) ...[ - " ", - fragmentDefinitionNode.selectionSet.accept(this), - ], + " ", + fragmentDefinitionNode.selectionSet.accept(this), ].join(); @override String visitInlineFragmentNode(InlineFragmentNode inlineFragmentNode) => [ "...", - if (inlineFragmentNode.typeCondition != null) ...[ - " ", - inlineFragmentNode.typeCondition!.accept(this), - ], - if (inlineFragmentNode.directives != null && - inlineFragmentNode.directives.isNotEmpty) ...[ + " ", + inlineFragmentNode.typeCondition!.accept(this), + if (inlineFragmentNode.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(inlineFragmentNode.directives), ], - if (inlineFragmentNode.selectionSet != null) ...[ - " ", - inlineFragmentNode.selectionSet.accept(this), - ], + " ", + inlineFragmentNode.selectionSet.accept(this), ].join(); @override String visitFragmentSpreadNode(FragmentSpreadNode fragmentSpreadNode) => [ "...", fragmentSpreadNode.name.accept(this), - if (fragmentSpreadNode.directives != null && - fragmentSpreadNode.directives.isNotEmpty) ...[ + if (fragmentSpreadNode.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(fragmentSpreadNode.directives), ], @@ -267,10 +255,9 @@ class _PrintVisitor extends Visitor { ": ", ], fieldNode.name.accept(this), - if (fieldNode.arguments != null && fieldNode.arguments.isNotEmpty) + if (fieldNode.arguments.isNotEmpty) visitArgumentSetNode(fieldNode.arguments), - if (fieldNode.directives != null && - fieldNode.directives.isNotEmpty) ...[ + if (fieldNode.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(fieldNode.directives), ], @@ -323,7 +310,7 @@ class _PrintVisitor extends Visitor { "scalar", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -395,7 +382,7 @@ class _PrintVisitor extends Visitor { ":", " ", node.type.accept(this), - if (node.directives != null && node.directives.isNotEmpty) " ", + if (node.directives.isNotEmpty) " ", visitDirectiveSetNode(node.directives), ].join(); @@ -434,7 +421,7 @@ class _PrintVisitor extends Visitor { " ", node.defaultValue!.accept(this), ], - if (node.directives != null && node.directives.isNotEmpty) " ", + if (node.directives.isNotEmpty) " ", visitDirectiveSetNode(node.directives), ].join(); @@ -461,7 +448,7 @@ class _PrintVisitor extends Visitor { "union", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -500,7 +487,7 @@ class _PrintVisitor extends Visitor { "enum", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -538,7 +525,7 @@ class _PrintVisitor extends Visitor { _indent(_tabs), ], node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) " ", + if (node.directives.isNotEmpty) " ", visitDirectiveSetNode(node.directives), ].join(); @@ -627,11 +614,11 @@ class _PrintVisitor extends Visitor { "extend", " ", "schema", - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], - if (node.operationTypes != null && node.operationTypes.isNotEmpty) ...[ + if (node.operationTypes.isNotEmpty) ...[ " ", visitOperationTypeDefinitionSetNode(node.operationTypes), ], @@ -644,7 +631,7 @@ class _PrintVisitor extends Visitor { "scalar", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -682,7 +669,7 @@ class _PrintVisitor extends Visitor { "union", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -696,7 +683,7 @@ class _PrintVisitor extends Visitor { "enum", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -711,7 +698,7 @@ class _PrintVisitor extends Visitor { "input", " ", node.name!.accept(this), - if (node.directives != null && node.directives.isNotEmpty) ...[ + if (node.directives.isNotEmpty) ...[ " ", visitDirectiveSetNode(node.directives), ], @@ -728,9 +715,6 @@ String? _opType(OperationType t) { case OperationType.subscription: return "subscription"; } - - // dead code to satisfy lint - return null; } String? _directiveLocation(DirectiveLocation location) { @@ -772,7 +756,4 @@ String? _directiveLocation(DirectiveLocation location) { case DirectiveLocation.inputFieldDefinition: return "INPUT_FIELD_DEFINITION"; } - - // dead code to satisfy lint - return null; } diff --git a/gql/lib/src/schema/definitions/type_resolver.dart b/gql/lib/src/schema/definitions/type_resolver.dart index 439eaeb9..080edff6 100644 --- a/gql/lib/src/schema/definitions/type_resolver.dart +++ b/gql/lib/src/schema/definitions/type_resolver.dart @@ -1,4 +1,3 @@ -import "package:collection/collection.dart"; import "package:meta/meta.dart"; import "./base_types.dart" show TypeDefinition; import "./definitions.dart" From cb7349a47cae2515ecbb598e5f943f08bad7f402 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:19:04 -0600 Subject: [PATCH 06/42] changed _peek(TokenKind.name) != null to _peek(TokenKind.name) in _parseTypeSystemExtension conditional, as it looks like an old bug of some kind --- gql/lib/src/language/parser.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gql/lib/src/language/parser.dart b/gql/lib/src/language/parser.dart index eab484c1..f08ae57b 100644 --- a/gql/lib/src/language/parser.dart +++ b/gql/lib/src/language/parser.dart @@ -414,7 +414,8 @@ class _Parser { ); } - List _parseArguments({required bool isConst}) => _maybeParseMany( + List _parseArguments({required bool isConst}) => + _maybeParseMany( TokenKind.parenL, isConst ? _parseConstArgument : _parseNonConstArgument, TokenKind.parenR, @@ -582,7 +583,7 @@ class _Parser { final token = _next(); - if (_peek(TokenKind.name) != null) { + if (_peek(TokenKind.name)) { switch (token!.value) { case "schema": return _parseSchemaExtension(); From ff7197073927111206aafa84257fc5ed76fb8b04 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:24:30 -0600 Subject: [PATCH 07/42] fix lexer digit parsing --- cats/lib/src/cat_model.dart | 4 ++-- cats/lib/src/cats_base.dart | 4 ++-- gql/lib/src/language/lexer.dart | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cats/lib/src/cat_model.dart b/cats/lib/src/cat_model.dart index 8914f051..5b21f2c2 100644 --- a/cats/lib/src/cat_model.dart +++ b/cats/lib/src/cat_model.dart @@ -33,7 +33,7 @@ class Scenario { class TestCase { String? name; - String? query; + String query; String? schema; Map? testData; @@ -43,7 +43,7 @@ class TestCase { TestCase({ this.name, - this.query, + required this.query, this.schema, this.testData, this.action, diff --git a/cats/lib/src/cats_base.dart b/cats/lib/src/cats_base.dart index 13ab6e2f..70bc111d 100644 --- a/cats/lib/src/cats_base.dart +++ b/cats/lib/src/cats_base.dart @@ -13,7 +13,7 @@ abstract class CatDriver { Iterable? validationRules, }); - execute({ + dynamic execute({ Doc? schema, dynamic testData, Doc? query, @@ -23,7 +23,7 @@ abstract class CatDriver { } class CatRunner { - CatBuilder _builder = CatBuilder(); + final _builder = CatBuilder(); CatDriver? driver; List? whitelist; diff --git a/gql/lib/src/language/lexer.dart b/gql/lib/src/language/lexer.dart index 53ae0a76..167f3109 100644 --- a/gql/lib/src/language/lexer.dart +++ b/gql/lib/src/language/lexer.dart @@ -299,12 +299,12 @@ class _Scanner { int _scanDigits(int offset) { var digitOffset = offset; - var code = peek(offset: digitOffset)!; + var code = peek(offset: digitOffset); - if (code >= 48 && code <= 57) { + if (code != null && code >= 48 && code <= 57) { do { - code = peek(offset: ++digitOffset)!; - } while (code >= 48 && code <= 57); + code = peek(offset: ++digitOffset); + } while (code != null && code >= 48 && code <= 57); return digitOffset; } From 691e0e328ebfc6afa2d0ed9b662861edc8101f46 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 12:51:20 -0600 Subject: [PATCH 08/42] fix gql pubspec --- gql/pubspec.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gql/pubspec.yaml b/gql/pubspec.yaml index f546c2fd..096426d9 100644 --- a/gql/pubspec.yaml +++ b/gql/pubspec.yaml @@ -1,15 +1,15 @@ name: gql -version: 0.12.4 +version: 1.0.0-nullsafety.0 description: GraphQL tools for parsing, transforming and printing GraphQL documents. repository: https://github.com/gql-dart/gql -environment: +environment: sdk: '>=2.12.0-259.9.beta <3.0.0' -dependencies: +dependencies: collection: ^1.15.0 meta: ^1.3.0 source_span: ^1.8.1 -dev_dependencies: - cats: - path: ../cats +dev_dependencies: gql_pedantic: ^1.0.2 - test: ^1.16.0 + test: ^1.16.2 + cats: + path: ../cats From 848c74e1fde1fb64e95de4b38093639b92db502d Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:18:17 -0600 Subject: [PATCH 09/42] gql_exec dart migrate to nullsafety --- links/gql_exec/lib/src/context.dart | 29 +++++++++++++-------------- links/gql_exec/lib/src/error.dart | 22 ++++++++++---------- links/gql_exec/lib/src/operation.dart | 10 ++++----- links/gql_exec/lib/src/request.dart | 8 ++++---- links/gql_exec/lib/src/response.dart | 16 +++++++-------- links/gql_exec/pubspec.yaml | 10 ++++----- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/links/gql_exec/lib/src/context.dart b/links/gql_exec/lib/src/context.dart index 0574d99a..5c22abb1 100644 --- a/links/gql_exec/lib/src/context.dart +++ b/links/gql_exec/lib/src/context.dart @@ -20,7 +20,7 @@ abstract class ContextEntry { bool operator ==(Object o) => identical(this, o) || (o.runtimeType == runtimeType && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( (o as ContextEntry).fieldsForEquality, @@ -28,7 +28,7 @@ abstract class ContextEntry { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( fieldsForEquality, @@ -41,21 +41,21 @@ abstract class ContextEntry { /// Context entries appear only once per type. @immutable class Context { - final Map _context; + final Map _context; /// Create an empty context. /// /// Entries may be added later using [withEntry]. const Context() : _context = const {}; - const Context._fromMap(Map context) + const Context._fromMap(Map context) : _context = context, assert(context != null); /// Creates a context from initial values represented as a map /// /// Every values runtime [Type] must be exactly the [Type] defined by the key. - factory Context.fromMap(Map context) { + factory Context.fromMap(Map context) { assert( context.entries.every( (entry) => entry.value == null || entry.value.runtimeType == entry.key, @@ -70,8 +70,7 @@ class Context { /// /// If more then one entry per type is provided, the last one is used. Context.fromList(List entries) - : assert(entries != null), - _context = entries.fold( + : _context = entries.fold>( {}, (ctx, e) => { ...ctx, @@ -80,7 +79,7 @@ class Context { ); /// Create a [Context] with [entry] added to the existing entries. - Context withEntry(T entry) { + Context withEntry(T entry) { if (entry != null && T != entry.runtimeType) { throw ArgumentError.value( entry, @@ -90,7 +89,7 @@ class Context { } return Context.fromMap( - { + { ..._context, T: entry, }, @@ -99,9 +98,9 @@ class Context { /// Create a [Context] by updating entry of type [T] Context updateEntry( - ContextUpdater update, + ContextUpdater update, ) => - withEntry( + withEntry( update( entry(), ), @@ -113,7 +112,7 @@ class Context { /// the [defaultValue] is returned. /// /// If provided, [defaultValue] must exactly match the return type [T]. - T entry([T defaultValue]) { + T? entry([T? defaultValue]) { if (defaultValue != null && T != defaultValue.runtimeType) { throw ArgumentError.value( defaultValue, @@ -121,7 +120,7 @@ class Context { "does not match the expected return type '${T}'", ); } - return _context.containsKey(T) ? _context[T] as T : defaultValue; + return _context.containsKey(T) ? _context[T] as T? : defaultValue; } List _getChildren() => [ @@ -132,7 +131,7 @@ class Context { bool operator ==(Object o) => identical(this, o) || (o is Context && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -140,7 +139,7 @@ class Context { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), diff --git a/links/gql_exec/lib/src/error.dart b/links/gql_exec/lib/src/error.dart index 570e0631..05c15ea4 100644 --- a/links/gql_exec/lib/src/error.dart +++ b/links/gql_exec/lib/src/error.dart @@ -8,22 +8,22 @@ class GraphQLError { final String message; /// Locations of the nodes in document which caused the error - final List locations; + final List? locations; /// Path of the error node in the query - final List path; + final List? path; /// Implementation-specific extensions to this error - final Map extensions; + final Map? extensions; const GraphQLError({ - @required this.message, + required this.message, this.locations, this.path, this.extensions, }) : assert(message != null); - List _getChildren() => [ + List _getChildren() => [ message, locations, path, @@ -38,7 +38,7 @@ class GraphQLError { bool operator ==(Object o) => identical(this, o) || (o is GraphQLError && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -46,7 +46,7 @@ class GraphQLError { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), @@ -60,8 +60,8 @@ class ErrorLocation { final int column; const ErrorLocation({ - @required this.line, - @required this.column, + required this.line, + required this.column, }) : assert(line != null), assert(column != null); @@ -74,7 +74,7 @@ class ErrorLocation { bool operator ==(Object o) => identical(this, o) || (o is ErrorLocation && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -82,7 +82,7 @@ class ErrorLocation { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), diff --git a/links/gql_exec/lib/src/operation.dart b/links/gql_exec/lib/src/operation.dart index a4822e80..0b0fc652 100644 --- a/links/gql_exec/lib/src/operation.dart +++ b/links/gql_exec/lib/src/operation.dart @@ -14,14 +14,14 @@ class Operation { /// Name of the executable definition /// /// Must be specified if [document] contains more than one [OperationDefinitionNode] - final String operationName; + final String? operationName; const Operation({ - @required this.document, + required this.document, this.operationName, }) : assert(document != null); - List _getChildren() => [ + List _getChildren() => [ document, operationName, ]; @@ -30,7 +30,7 @@ class Operation { bool operator ==(Object o) => identical(this, o) || (o is Operation && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -38,7 +38,7 @@ class Operation { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), diff --git a/links/gql_exec/lib/src/request.dart b/links/gql_exec/lib/src/request.dart index 16f51217..ceb0b731 100644 --- a/links/gql_exec/lib/src/request.dart +++ b/links/gql_exec/lib/src/request.dart @@ -16,7 +16,7 @@ class Request { final Context context; const Request({ - @required this.operation, + required this.operation, this.variables = const {}, this.context = const Context(), }) : assert(operation != null), @@ -31,7 +31,7 @@ class Request { /// Clone this request updating an [entry] in the [context] Request updateContextEntry( - ContextUpdater update, + ContextUpdater update, ) => Request( operation: operation, @@ -49,7 +49,7 @@ class Request { bool operator ==(Object o) => identical(this, o) || (o is Request && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -57,7 +57,7 @@ class Request { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), diff --git a/links/gql_exec/lib/src/response.dart b/links/gql_exec/lib/src/response.dart index 0de81123..d735ae5b 100644 --- a/links/gql_exec/lib/src/response.dart +++ b/links/gql_exec/lib/src/response.dart @@ -7,12 +7,12 @@ import "package:meta/meta.dart"; @immutable class Response { /// Error returned executing the [Request] - final List errors; + final List? errors; /// Data returned executing the [Request] /// /// Follows the shape of requested document. - final Map data; + final Map? data; /// A [Context] to be returned along with a [Response] final Context context; @@ -21,7 +21,7 @@ class Response { this.errors, this.data, this.context = const Context(), - }) : assert(context != null); + }); /// Clone this response adding an [entry] to [context] Response withContextEntry(T entry) => Response( @@ -32,7 +32,7 @@ class Response { /// Clone this response updating an [entry] to [context] Response updateContextEntry( - ContextUpdater update, + ContextUpdater update, ) => Response( errors: errors, @@ -40,7 +40,7 @@ class Response { context: context.updateEntry(update), ); - List _getChildren() => [ + List _getChildren() => [ errors, data, context, @@ -50,7 +50,7 @@ class Response { bool operator ==(Object o) => identical(this, o) || (o is Response && - const ListEquality( + const ListEquality( DeepCollectionEquality(), ).equals( o._getChildren(), @@ -58,7 +58,7 @@ class Response { )); @override - int get hashCode => const ListEquality( + int get hashCode => const ListEquality( DeepCollectionEquality(), ).hash( _getChildren(), @@ -73,7 +73,7 @@ class Response { @immutable class ResponseExtensions extends ContextEntry { /// [Response] extensions - final dynamic extensions; + final Object extensions; const ResponseExtensions( this.extensions, diff --git a/links/gql_exec/pubspec.yaml b/links/gql_exec/pubspec.yaml index f3e4a690..20b33aae 100644 --- a/links/gql_exec/pubspec.yaml +++ b/links/gql_exec/pubspec.yaml @@ -1,13 +1,13 @@ name: gql_exec -version: 0.2.5 +version: 0.3.0-nullsafety.0 description: Basis for GraphQL execution layer to support Link and Client. repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.9.beta <3.0.0' dependencies: + collection: ^1.15.0 + meta: ^1.3.0 gql: ^0.12.3 - meta: ^1.1.7 - collection: ^1.14.11 dev_dependencies: - test: ^1.0.0 + test: ^1.16.2 gql_pedantic: ^1.0.2 From cf4e4a26c5db30b1e41b864c850f632aa7c1b0b6 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:18:36 -0600 Subject: [PATCH 10/42] gql_exec dart migrate to nullsafety --- links/gql_exec/lib/src/context.dart | 4 +--- links/gql_exec/lib/src/error.dart | 5 ++--- links/gql_exec/lib/src/operation.dart | 2 +- links/gql_exec/lib/src/request.dart | 3 +-- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/links/gql_exec/lib/src/context.dart b/links/gql_exec/lib/src/context.dart index 5c22abb1..b1250a8a 100644 --- a/links/gql_exec/lib/src/context.dart +++ b/links/gql_exec/lib/src/context.dart @@ -48,9 +48,7 @@ class Context { /// Entries may be added later using [withEntry]. const Context() : _context = const {}; - const Context._fromMap(Map context) - : _context = context, - assert(context != null); + const Context._fromMap(Map context) : _context = context; /// Creates a context from initial values represented as a map /// diff --git a/links/gql_exec/lib/src/error.dart b/links/gql_exec/lib/src/error.dart index 05c15ea4..9a3c3729 100644 --- a/links/gql_exec/lib/src/error.dart +++ b/links/gql_exec/lib/src/error.dart @@ -21,7 +21,7 @@ class GraphQLError { this.locations, this.path, this.extensions, - }) : assert(message != null); + }); List _getChildren() => [ message, @@ -62,8 +62,7 @@ class ErrorLocation { const ErrorLocation({ required this.line, required this.column, - }) : assert(line != null), - assert(column != null); + }); List _getChildren() => [ line, diff --git a/links/gql_exec/lib/src/operation.dart b/links/gql_exec/lib/src/operation.dart index 0b0fc652..8199fcc9 100644 --- a/links/gql_exec/lib/src/operation.dart +++ b/links/gql_exec/lib/src/operation.dart @@ -19,7 +19,7 @@ class Operation { const Operation({ required this.document, this.operationName, - }) : assert(document != null); + }); List _getChildren() => [ document, diff --git a/links/gql_exec/lib/src/request.dart b/links/gql_exec/lib/src/request.dart index ceb0b731..7b4dbcaf 100644 --- a/links/gql_exec/lib/src/request.dart +++ b/links/gql_exec/lib/src/request.dart @@ -19,8 +19,7 @@ class Request { required this.operation, this.variables = const {}, this.context = const Context(), - }) : assert(operation != null), - assert(context != null); + }); /// Clone this request adding an [entry] to [context] Request withContextEntry(T entry) => Request( From c1289f0df62ec1a6459b97726791569aa8721c15 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:21:51 -0600 Subject: [PATCH 11/42] gql_link dart migrate to nullsafety --- links/gql_link/example/gql_link_example.dart | 2 +- links/gql_link/lib/src/exceptions.dart | 4 ++-- links/gql_link/lib/src/link.dart | 18 +++++++++--------- links/gql_link/lib/src/request_serializer.dart | 2 +- links/gql_link/lib/src/response_parser.dart | 8 ++++---- links/gql_link/pubspec.yaml | 10 ++++++---- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/links/gql_link/example/gql_link_example.dart b/links/gql_link/example/gql_link_example.dart index 0dcf06d5..633f5fcd 100644 --- a/links/gql_link/example/gql_link_example.dart +++ b/links/gql_link/example/gql_link_example.dart @@ -8,7 +8,7 @@ class MyLinkContext extends ContextEntry { const MyLinkContext(this.value); @override - List get fieldsForEquality => null; + List get fieldsForEquality => []; } class MyLink extends Link { diff --git a/links/gql_link/lib/src/exceptions.dart b/links/gql_link/lib/src/exceptions.dart index 9a504867..54881f28 100644 --- a/links/gql_link/lib/src/exceptions.dart +++ b/links/gql_link/lib/src/exceptions.dart @@ -23,7 +23,7 @@ class RequestFormatException extends LinkException { final Request request; const RequestFormatException({ - @required this.request, + required this.request, dynamic originalException, }) : super(originalException); @@ -77,7 +77,7 @@ class ServerException extends LinkException { final Response parsedResponse; const ServerException({ - @required this.parsedResponse, + required this.parsedResponse, dynamic originalException, }) : super(originalException); diff --git a/links/gql_link/lib/src/link.dart b/links/gql_link/lib/src/link.dart index e86cafee..6d5a4fa3 100644 --- a/links/gql_link/lib/src/link.dart +++ b/links/gql_link/lib/src/link.dart @@ -17,7 +17,7 @@ typedef LinkRouter = Link Function( /// Used by [Link.function] typedef LinkFunction = Stream Function( Request request, [ - NextLink forward, + NextLink? forward, ]); /// [DocumentNode]-based GraphQL execution interface @@ -93,7 +93,7 @@ abstract class Link { /// the next [Link] /// /// Terminating [Link]s do not call this function. - NextLink forward, + NextLink? forward, ]); } @@ -105,7 +105,7 @@ class _FunctionLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) => function(request, forward); } @@ -118,12 +118,12 @@ class _LinkChain extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) => - links.reversed.fold( + links.reversed.fold( forward, (fw, link) => (op) => link.request(op, fw), - )(request); + )!(request); } class _PassthroughLink extends Link { @@ -132,9 +132,9 @@ class _PassthroughLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) => - forward(request); + forward!(request); } class _RouterLink extends Link { @@ -147,7 +147,7 @@ class _RouterLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) async* { final link = routeFn(request); diff --git a/links/gql_link/lib/src/request_serializer.dart b/links/gql_link/lib/src/request_serializer.dart index 8c242aa6..ce85854e 100644 --- a/links/gql_link/lib/src/request_serializer.dart +++ b/links/gql_link/lib/src/request_serializer.dart @@ -9,7 +9,7 @@ class RequestSerializer { /// /// Extend this to add non-standard behavior Map serializeRequest(Request request) { - final RequestExtensionsThunk thunk = request.context.entry(); + final RequestExtensionsThunk? thunk = request.context.entry(); return { "operationName": request.operation.operationName, diff --git a/links/gql_link/lib/src/response_parser.dart b/links/gql_link/lib/src/response_parser.dart index 18050270..ea4d3d54 100644 --- a/links/gql_link/lib/src/response_parser.dart +++ b/links/gql_link/lib/src/response_parser.dart @@ -8,11 +8,11 @@ class ResponseParser { /// /// Extend this to add non-standard behavior Response parseResponse(Map body) => Response( - errors: (body["errors"] as List) + errors: (body["errors"] as List?) ?.map( (dynamic error) => parseError(error as Map), ) - ?.toList(), + .toList(), data: body["data"] as Map, context: Context().withEntry( ResponseExtensions( @@ -27,11 +27,11 @@ class ResponseParser { GraphQLError parseError(Map error) => GraphQLError( message: error["message"] as String, path: error["path"] as List, - locations: (error["locations"] as List) + locations: (error["locations"] as List?) ?.map( (dynamic error) => parseLocation(error as Map), ) - ?.toList(), + ?.toList()!, extensions: error["extensions"] as Map, ); diff --git a/links/gql_link/pubspec.yaml b/links/gql_link/pubspec.yaml index bb89ec3b..89dc6b58 100644 --- a/links/gql_link/pubspec.yaml +++ b/links/gql_link/pubspec.yaml @@ -1,13 +1,15 @@ name: gql_link -version: 0.3.1 +version: 0.4.0-nullsafety.0 description: A simple and modular AST-based GraphQL request execution interface. repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.9.beta <3.0.0' dependencies: meta: ^1.1.7 - gql: ^0.12.3 - gql_exec: ^0.2.5 + gql: #^0.12.3 + path: ../../gql + gql_exec: #^0.2.5 + path: ../gql_exec dev_dependencies: test: ^1.0.0 mockito: ^4.1.1 From b5e9b39fcd6778ebf123cacb011272ba92c502ac Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:29:35 -0600 Subject: [PATCH 12/42] try and resolve issues for gql_exec and gql_link at least --- links/gql_exec/lib/src/response.dart | 4 ++-- links/gql_link/example/gql_link_example.dart | 2 +- links/gql_link/pubspec.yaml | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/links/gql_exec/lib/src/response.dart b/links/gql_exec/lib/src/response.dart index d735ae5b..ce052c7f 100644 --- a/links/gql_exec/lib/src/response.dart +++ b/links/gql_exec/lib/src/response.dart @@ -73,7 +73,7 @@ class Response { @immutable class ResponseExtensions extends ContextEntry { /// [Response] extensions - final Object extensions; + final dynamic extensions; const ResponseExtensions( this.extensions, @@ -81,6 +81,6 @@ class ResponseExtensions extends ContextEntry { @override List get fieldsForEquality => [ - extensions, + extensions as Object, ]; } diff --git a/links/gql_link/example/gql_link_example.dart b/links/gql_link/example/gql_link_example.dart index 633f5fcd..41409e7b 100644 --- a/links/gql_link/example/gql_link_example.dart +++ b/links/gql_link/example/gql_link_example.dart @@ -17,7 +17,7 @@ class MyLink extends Link { [ Response( data: { - "context": request.context.entry().value, + "context": request.context.entry()?.value, }, ), ], diff --git a/links/gql_link/pubspec.yaml b/links/gql_link/pubspec.yaml index 89dc6b58..74d22972 100644 --- a/links/gql_link/pubspec.yaml +++ b/links/gql_link/pubspec.yaml @@ -6,10 +6,8 @@ environment: sdk: '>=2.12.0-259.9.beta <3.0.0' dependencies: meta: ^1.1.7 - gql: #^0.12.3 - path: ../../gql - gql_exec: #^0.2.5 - path: ../gql_exec + gql: ^0.12.3 + gql_exec: ^0.2.5 dev_dependencies: test: ^1.0.0 mockito: ^4.1.1 From 99a334d2d945f059337b0b2e4bbcecfe8bca78d1 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:50:11 -0600 Subject: [PATCH 13/42] depend on 2.12-beta for CI --- .github/workflows/dart.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index ac115b2e..7bcd58c3 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -22,7 +22,7 @@ jobs: - gql_example_http_auth_link runs-on: ubuntu-latest container: - image: google/dart:latest + image: google/dart:2.12-beta name: Check ${{ matrix.package }} env: PACKAGE: ${{ matrix.package }} @@ -67,7 +67,7 @@ jobs: - gql_example_build runs-on: ubuntu-latest container: - image: google/dart:latest + image: google/dart:2.12-beta name: Check ${{ matrix.package }} env: PACKAGE: ${{ matrix.package }} @@ -112,7 +112,7 @@ jobs: - end_to_end_test runs-on: ubuntu-latest container: - image: google/dart:latest + image: google/dart:2.12-beta name: Check ${{ matrix.package }} env: PACKAGE: ${{ matrix.package }} @@ -158,7 +158,7 @@ jobs: publish_dry_run: runs-on: ubuntu-latest container: - image: google/dart:latest + image: google/dart:2.12-beta env: PACKAGES: 'gql,gql_build,gql_code_builder,gql_dedupe_link,gql_dio_link,gql_exec,gql_http_link,gql_link,gql_pedantic,gql_transform_link,gql_error_link,gql_websocket_link' PUB_ACCESS_TOKEN: ${{ secrets.PUB_ACCESS_TOKEN }} @@ -183,7 +183,7 @@ jobs: check_svg: runs-on: ubuntu-latest container: - image: google/dart:latest + image: google/dart:2.12-beta steps: - name: Clone repository uses: actions/checkout@v2 From ee974f424ba5bfde1b2b8fce7a93d3d0bf2070ef Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 13:56:44 -0600 Subject: [PATCH 14/42] fix formatting of gql tests --- gql/test/parser_test.dart | 37 +++++++++++++++++++------------------ gql/test/schema_test.dart | 3 ++- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gql/test/parser_test.dart b/gql/test/parser_test.dart index 313f408a..5dab499f 100644 --- a/gql/test/parser_test.dart +++ b/gql/test/parser_test.dart @@ -2,30 +2,31 @@ import "package:gql/src/language/parser.dart"; import "package:source_span/source_span.dart"; import "package:test/test.dart"; -final Matcher Function(String, int, int, [int, int]) throwsSourceSpanException = ( +final Matcher Function(String, int, int, [int, int]) throwsSourceSpanException = + ( String message, int startLine, int startColumn, [ int? endLine, int? endColumn, ]) => - throwsA( - allOf( - TypeMatcher(), - predicate( - (SourceSpanException e) => e.message == message, - "error messages match", - ), - predicate( - (SourceSpanException e) => - e.span!.start.line == startLine - 1 && - e.span!.start.column == startColumn - 1 && - e.span!.end.line == (endLine ?? startLine) - 1 && - e.span!.end.column == (endColumn ?? startColumn + 1) - 1, - "span matches", - ), - ), - ); + throwsA( + allOf( + TypeMatcher(), + predicate( + (SourceSpanException e) => e.message == message, + "error messages match", + ), + predicate( + (SourceSpanException e) => + e.span!.start.line == startLine - 1 && + e.span!.start.column == startColumn - 1 && + e.span!.end.line == (endLine ?? startLine) - 1 && + e.span!.end.column == (endColumn ?? startColumn + 1) - 1, + "span matches", + ), + ), + ); void main() { group("Parser", () { diff --git a/gql/test/schema_test.dart b/gql/test/schema_test.dart index 2d0672ba..753b5297 100644 --- a/gql/test/schema_test.dart +++ b/gql/test/schema_test.dart @@ -70,7 +70,8 @@ void main() { }); test("Type dereferencing", () { - final starshipsType = schema.query!.getField("starships").type as ListType; + final starshipsType = + schema.query!.getField("starships").type as ListType; expect(starshipsType.baseTypeName, equals("Starship")); From 429d717efd5098fb339bf46bc25f4e1cfe81909c Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 14:02:43 -0600 Subject: [PATCH 15/42] fix some lints in gql_link --- links/gql_link/lib/src/link.dart | 2 +- links/gql_link/lib/src/response_parser.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/links/gql_link/lib/src/link.dart b/links/gql_link/lib/src/link.dart index 6d5a4fa3..cd83d35f 100644 --- a/links/gql_link/lib/src/link.dart +++ b/links/gql_link/lib/src/link.dart @@ -142,7 +142,7 @@ class _RouterLink extends Link { const _RouterLink( this.routeFn, - ) : assert(routeFn != null); + ); @override Stream request( diff --git a/links/gql_link/lib/src/response_parser.dart b/links/gql_link/lib/src/response_parser.dart index ea4d3d54..04a666c4 100644 --- a/links/gql_link/lib/src/response_parser.dart +++ b/links/gql_link/lib/src/response_parser.dart @@ -31,7 +31,7 @@ class ResponseParser { ?.map( (dynamic error) => parseLocation(error as Map), ) - ?.toList()!, + .toList(), extensions: error["extensions"] as Map, ); From ffc032f6d0d8360819dab545c18bac5d0653c483 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 14:05:12 -0600 Subject: [PATCH 16/42] fix cats pubspec --- cats/pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cats/pubspec.yaml b/cats/pubspec.yaml index 979c87b7..297b3c97 100644 --- a/cats/pubspec.yaml +++ b/cats/pubspec.yaml @@ -1,10 +1,10 @@ name: cats description: A starting point for Dart libraries or applications. repository: https://github.com/gql-dart/gql -environment: +environment: sdk: '>=2.12.0-259.9.beta <3.0.0' -dependencies: +dependencies: test: ^1.16.0 -dev_dependencies: +dev_dependencies: pedantic: ^1.10.0 yaml: ^3.0.0 From f9c9bb54e07051f572da567652851db23d6377e9 Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 14:26:14 -0600 Subject: [PATCH 17/42] prefer const literals --- .github/workflows/dart.yml | 1 + .../test/enum/enum_fallback_test.dart | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7bcd58c3..55b95fbf 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -4,6 +4,7 @@ on: pull_request jobs: packages: strategy: + fail-fast: false matrix: package: - gql diff --git a/codegen/gql_code_builder/test/enum/enum_fallback_test.dart b/codegen/gql_code_builder/test/enum/enum_fallback_test.dart index b8886d3a..1a4b8db2 100644 --- a/codegen/gql_code_builder/test/enum/enum_fallback_test.dart +++ b/codegen/gql_code_builder/test/enum/enum_fallback_test.dart @@ -6,7 +6,7 @@ import "package:test/test.dart"; void main() { final simpleEnum = - EnumTypeDefinitionNode(name: NameNode(value: "testEnum"), values: [ + EnumTypeDefinitionNode(name: NameNode(value: "testEnum"), values: const [ EnumValueDefinitionNode(name: NameNode(value: "val1")), EnumValueDefinitionNode(name: NameNode(value: "val2")) ]); @@ -132,10 +132,12 @@ void main() { test("works with escaped names", () { final clazz = buildEnumClass( - EnumTypeDefinitionNode(name: NameNode(value: "testEnum"), values: [ - EnumValueDefinitionNode(name: NameNode(value: "name")), - EnumValueDefinitionNode(name: NameNode(value: "default")) - ]), + EnumTypeDefinitionNode( + name: NameNode(value: "testEnum"), + values: const [ + EnumValueDefinitionNode(name: NameNode(value: "name")), + EnumValueDefinitionNode(name: NameNode(value: "default")) + ]), EnumFallbackConfig( generateFallbackValuesGlobally: false, fallbackValueMap: {"testEnum": "default"})); From dd93c031f2bddad5c621e1f86a6d699340a54d2f Mon Sep 17 00:00:00 2001 From: micimize Date: Sat, 13 Feb 2021 14:37:50 -0600 Subject: [PATCH 18/42] remove second gql_link from workflow --- .github/workflows/dart.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 55b95fbf..158e949a 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -17,7 +17,6 @@ jobs: - gql_error_link - gql_http_link - gql_websocket_link - - gql_link - gql_transform_link - cats - gql_example_http_auth_link From 118ad83070d325e8164bbd350d703098217f908d Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 10:34:24 -0600 Subject: [PATCH 19/42] automatic migration --- links/gql_http_link/lib/src/_utils.dart | 4 +- links/gql_http_link/lib/src/exceptions.dart | 8 +- links/gql_http_link/lib/src/link.dart | 22 ++--- links/gql_http_link/pubspec.yaml | 21 +++-- .../test/gql_http_link_test.dart | 80 +++++++++---------- links/gql_http_link/test/helpers.dart | 2 +- .../test/multipart_upload_test.dart | 26 +++--- 7 files changed, 85 insertions(+), 78 deletions(-) diff --git a/links/gql_http_link/lib/src/_utils.dart b/links/gql_http_link/lib/src/_utils.dart index 97ece858..0023a261 100644 --- a/links/gql_http_link/lib/src/_utils.dart +++ b/links/gql_http_link/lib/src/_utils.dart @@ -13,7 +13,7 @@ extension WithType on gql.Request { .toList(); if (operation.operationName != null) { definitions.removeWhere( - (node) => node.name.value != operation.operationName, + (node) => node.name!.value != operation.operationName, ); } // TODO differentiate error types, add exception @@ -38,7 +38,7 @@ extension WithType on gql.Request { /// ``` Map extractFlattenedFileMap( dynamic body, { - Map currentMap, + Map? currentMap, List currentPath = const [], }) { currentMap ??= {}; diff --git a/links/gql_http_link/lib/src/exceptions.dart b/links/gql_http_link/lib/src/exceptions.dart index 236fc6ff..ebce8d7b 100644 --- a/links/gql_http_link/lib/src/exceptions.dart +++ b/links/gql_http_link/lib/src/exceptions.dart @@ -10,8 +10,8 @@ class HttpLinkParserException extends ResponseFormatException { final http.Response response; const HttpLinkParserException({ - @required dynamic originalException, - @required this.response, + required dynamic originalException, + required this.response, }) : super( originalException: originalException, ); @@ -25,8 +25,8 @@ class HttpLinkServerException extends ServerException { final http.Response response; const HttpLinkServerException({ - @required this.response, - @required Response parsedResponse, + required this.response, + required Response parsedResponse, }) : super( parsedResponse: parsedResponse, ); diff --git a/links/gql_http_link/lib/src/link.dart b/links/gql_http_link/lib/src/link.dart index be72cea3..8e518101 100644 --- a/links/gql_http_link/lib/src/link.dart +++ b/links/gql_http_link/lib/src/link.dart @@ -9,7 +9,7 @@ import "package:meta/meta.dart"; import "./_utils.dart"; import "./exceptions.dart"; -typedef HttpResponseDecoder = FutureOr> Function( +typedef HttpResponseDecoder = FutureOr>? Function( http.Response httpResponse); /// HTTP link headers @@ -40,8 +40,8 @@ class HttpLinkResponseContext extends ContextEntry { final Map headers; const HttpLinkResponseContext({ - @required this.statusCode, - @required this.headers, + required this.statusCode, + required this.headers, }) : assert(statusCode != null), assert(headers != null); @@ -84,15 +84,15 @@ class HttpLink extends Link { /// ``` HttpResponseDecoder httpResponseDecoder; - static Map _defaultHttpResponseDecoder( + static Map? _defaultHttpResponseDecoder( http.Response httpResponse) => json.decode( utf8.decode( httpResponse.bodyBytes, ), - ) as Map; + ) as Map?; - http.Client _httpClient; + http.Client? _httpClient; /// Construct the Link /// @@ -101,7 +101,7 @@ class HttpLink extends Link { String uri, { this.defaultHeaders = const {}, this.useGETForQueries = false, - http.Client httpClient, + http.Client? httpClient, this.serializer = const RequestSerializer(), this.parser = const ResponseParser(), this.httpResponseDecoder = _defaultHttpResponseDecoder, @@ -112,7 +112,7 @@ class HttpLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) async* { final httpResponse = await _executeRequest(request); @@ -153,7 +153,7 @@ class HttpLink extends Link { Future _parseHttpResponse(http.Response httpResponse) async { try { - final responseBody = await httpResponseDecoder(httpResponse); + final responseBody = await httpResponseDecoder(httpResponse)!; return parser.parseResponse(responseBody); } catch (e) { throw HttpLinkParserException( @@ -166,7 +166,7 @@ class HttpLink extends Link { Future _executeRequest(Request request) async { final httpRequest = _prepareRequest(request); try { - final response = await _httpClient.send(httpRequest); + final response = await _httpClient!.send(httpRequest); return http.Response.fromStream(response); } catch (e) { throw ServerException( @@ -251,7 +251,7 @@ class HttpLink extends Link { Map _getHttpLinkHeaders(Request request) { try { - final HttpLinkHeaders linkHeaders = request.context.entry(); + final HttpLinkHeaders? linkHeaders = request.context.entry(); return { if (linkHeaders != null) ...linkHeaders.headers, diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index 839c12cd..2de39e32 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -3,16 +3,23 @@ version: 0.3.3 description: GQL Terminating Link to execute requests via HTTP using JSON. repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.12.beta <3.0.0' dependencies: - meta: ^1.1.7 + meta: ^1.3.0 gql: ^0.12.3 gql_exec: ^0.2.5 gql_link: ^0.3.1 - http: ^0.12.1 - http_parser: ^3.1.4 + http: ^0.13.0 + http_parser: ^4.0.0 dev_dependencies: - test: ^1.0.0 - mockito: ^4.1.1 + test: ^1.16.2 + mockito: ^5.0.0-nullsafety.7 gql_pedantic: ^1.0.2 - http_parser: ^3.1.4 + +dependency_overrides: + gql: + path: ../../gql + gql_exec: + path: ../gql_exec + gql_link: + path: ../gql_link diff --git a/links/gql_http_link/test/gql_http_link_test.dart b/links/gql_http_link/test/gql_http_link_test.dart index ca5574b2..c2296254 100644 --- a/links/gql_http_link/test/gql_http_link_test.dart +++ b/links/gql_http_link/test/gql_http_link_test.dart @@ -25,14 +25,14 @@ class CustomScalar { void main() { group("HttpLink", () { - MockClient client; - Request request; - HttpLink link; + late MockClient client; + late Request request; + late HttpLink link; final Stream Function([ - Request customRequest, + Request? customRequest, ]) execute = ([ - Request customRequest, + Request? customRequest, ]) => link.request(customRequest ?? request); @@ -52,7 +52,7 @@ void main() { test("parses a successful response", () { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -89,7 +89,7 @@ void main() { test("uses the defined endpoint", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -111,14 +111,14 @@ void main() { "expected endpoint", Uri.parse("/graphql-test"), ), - ), + )!, ), ).called(1); }); test("uses json mime types", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -143,14 +143,14 @@ void main() { containsPair("Accept", "*/*"), ]), ), - ), + )!, ), ).called(1); }); test("adds headers from context", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -188,7 +188,7 @@ void main() { "context headers", containsPair("foo", "bar"), ), - ), + )!, ), ).called(1); }); @@ -204,7 +204,7 @@ void main() { ); when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -235,14 +235,14 @@ void main() { "default headers", containsPair("foo", "bar"), ), - ), + )!, ), ).called(1); }); test("headers from context override defaults", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -280,14 +280,14 @@ void main() { "headers from context", containsPair("Content-type", "application/jsonize"), ), - ), + )!, ), ).called(1); }); test("serializes the request", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -309,14 +309,14 @@ void main() { "serialized body", '{"operationName":null,"variables":{"i":12},"query":"query MyQuery {\\n \\n}"}', ), - ), + )!, ), ).called(1); }); test("serializes all types", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -368,13 +368,13 @@ void main() { r'"query":"query MyQuery($richInput: RichInput) {\n \n}"' r"}", ), - ), + )!, ), ).called(1); }); test("parses a successful response with errors", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -439,14 +439,14 @@ void main() { }); when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse(data, 300), ), ); - HttpLinkServerException exception; + HttpLinkServerException? exception; try { await execute().first; @@ -458,7 +458,7 @@ void main() { exception, TypeMatcher(), ); - expect(exception.response.body, data); + expect(exception!.response.body, data); expect( exception.parsedResponse, equals( @@ -478,14 +478,14 @@ void main() { final _response = simpleResponse(data, 200); when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( _response, ), ); - HttpLinkServerException exception; + HttpLinkServerException? exception; try { await execute().first; @@ -498,7 +498,7 @@ void main() { TypeMatcher(), ); expect( - exception.response.body, + exception!.response.body, data, ); expect( @@ -527,7 +527,7 @@ void main() { final originalException = Exception("Foo bar"); when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -541,11 +541,11 @@ void main() { when( serializer.serializeRequest( - any, + any!, ), ).thenThrow(originalException); - RequestFormatException exception; + RequestFormatException? exception; try { await link @@ -567,14 +567,14 @@ void main() { TypeMatcher(), ); expect( - exception.originalException, + exception!.originalException, originalException, ); }); test("throws ParserException when unable to serialize request", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -584,7 +584,7 @@ void main() { ), ); - ResponseFormatException exception; + ResponseFormatException? exception; try { await link @@ -606,7 +606,7 @@ void main() { TypeMatcher(), ); expect( - exception.originalException, + exception!.originalException, TypeMatcher(), ); }); @@ -621,8 +621,8 @@ void main() { }); group("HttpLink useGETForQueries", () { - MockClient client; - HttpLink link; + late MockClient client; + late HttpLink link; setUp(() { client = MockClient(); @@ -635,7 +635,7 @@ void main() { test("uses GET for query without files", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -664,14 +664,14 @@ void main() { "method", "GET", ), - ), + )!, ), ).called(1); }); test("uses POST for mutation", () async { when( - client.send(any), + client.send(any!), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -700,7 +700,7 @@ void main() { "method", "POST", ), - ), + )!, ), ).called(1); }); diff --git a/links/gql_http_link/test/helpers.dart b/links/gql_http_link/test/helpers.dart index c7e124cf..0dc7928f 100644 --- a/links/gql_http_link/test/helpers.dart +++ b/links/gql_http_link/test/helpers.dart @@ -5,7 +5,7 @@ import "package:http/http.dart" as http; http.StreamedResponse simpleResponse( String body, [ - int status, + int? status, Map headers = const {}, ]) { final List bytes = utf8.encode(body); diff --git a/links/gql_http_link/test/multipart_upload_test.dart b/links/gql_http_link/test/multipart_upload_test.dart index 5f536500..bffa6f00 100644 --- a/links/gql_http_link/test/multipart_upload_test.dart +++ b/links/gql_http_link/test/multipart_upload_test.dart @@ -19,8 +19,8 @@ class MockRequestSerializer extends Mock implements RequestSerializer {} class MockResponseParser extends Mock implements ResponseParser {} void main() { - MockClient mockHttpClient; - HttpLink httpLink; + MockClient? mockHttpClient; + late HttpLink httpLink; const String uploadMutation = r""" mutation($files: [Upload!]!) { @@ -82,7 +82,7 @@ void main() { ]; group("upload", () { - Request gqlRequest; + late Request gqlRequest; setUp(() { mockHttpClient = MockClient(); @@ -102,9 +102,9 @@ void main() { }); test("request encoding", () async { - Uint8List bodyBytes; + Uint8List? bodyBytes; when( - mockHttpClient.send(any), + mockHttpClient!.send(any!), ).thenAnswer((i) async { bodyBytes = await (i.positionalArguments[0] as http.BaseRequest) .finalize() @@ -115,11 +115,11 @@ void main() { await httpLink.request(gqlRequest).first; final http.MultipartRequest request = verify( - mockHttpClient.send(captureAny), + mockHttpClient!.send(captureAny!), ).captured.first as http.MultipartRequest; final List contentTypeStringSplit = - request.headers["content-type"].split("; boundary="); + request.headers["content-type"]!.split("; boundary="); expect(request.method, "POST"); expect(request.url.toString(), "http://localhost:3001/graphql"); @@ -169,14 +169,14 @@ void main() { test("response data", () async { when( - mockHttpClient.send(any), + mockHttpClient!.send(any!), ).thenAnswer( (i) async => simpleResponse(expectedResponse), ); final response = await httpLink.request(gqlRequest).first; - final multipleUpload = (response.data["multipleUpload"] as List) + final multipleUpload = (response.data!["multipleUpload"] as List) .cast>(); expect(multipleUpload, >[ @@ -208,9 +208,9 @@ void main() { }); test("query request encoding with files", () async { - Uint8List bodyBytes; + Uint8List? bodyBytes; when( - mockHttpClient.send(any), + mockHttpClient!.send(any!), ).thenAnswer((i) async { bodyBytes = await (i.positionalArguments[0] as http.BaseRequest) .finalize() @@ -230,11 +230,11 @@ void main() { await httpLink.request(gqlQueryWithFiles).first; final http.MultipartRequest request = verify( - mockHttpClient.send(captureAny), + mockHttpClient!.send(captureAny!), ).captured.first as http.MultipartRequest; final List contentTypeStringSplit = - request.headers["content-type"].split("; boundary="); + request.headers["content-type"]!.split("; boundary="); expect(request.method, "POST"); expect(request.url.toString(), "http://localhost:3001/graphql"); From 8edfa3cedb39c9ffbbcb1ee1be1a7a373ef95015 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 10:46:29 -0600 Subject: [PATCH 20/42] nullable parsedResponse --- links/gql_http_link/lib/src/_utils.dart | 2 -- links/gql_http_link/lib/src/link.dart | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/links/gql_http_link/lib/src/_utils.dart b/links/gql_http_link/lib/src/_utils.dart index 0023a261..af2709a8 100644 --- a/links/gql_http_link/lib/src/_utils.dart +++ b/links/gql_http_link/lib/src/_utils.dart @@ -1,6 +1,4 @@ import "dart:convert"; -import "dart:typed_data"; -import "package:meta/meta.dart"; import "package:http/http.dart"; import "package:gql/ast.dart"; diff --git a/links/gql_http_link/lib/src/link.dart b/links/gql_http_link/lib/src/link.dart index 8e518101..11304116 100644 --- a/links/gql_http_link/lib/src/link.dart +++ b/links/gql_http_link/lib/src/link.dart @@ -22,7 +22,7 @@ class HttpLinkHeaders extends ContextEntry { const HttpLinkHeaders({ this.headers = const {}, - }) : assert(headers != null); + }); @override List get fieldsForEquality => [ @@ -42,8 +42,7 @@ class HttpLinkResponseContext extends ContextEntry { const HttpLinkResponseContext({ required this.statusCode, required this.headers, - }) : assert(statusCode != null), - assert(headers != null); + }); @override List get fieldsForEquality => [ From da8fc71a0119d79207e76ca64b0f8ecc48e77a81 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 10:46:41 -0600 Subject: [PATCH 21/42] nullable parsedResponse --- links/gql_link/lib/src/exceptions.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/links/gql_link/lib/src/exceptions.dart b/links/gql_link/lib/src/exceptions.dart index 54881f28..3f196be3 100644 --- a/links/gql_link/lib/src/exceptions.dart +++ b/links/gql_link/lib/src/exceptions.dart @@ -74,10 +74,10 @@ class ContextWriteException extends LinkException { @immutable class ServerException extends LinkException { /// The parsed response - final Response parsedResponse; + final Response? parsedResponse; const ServerException({ - required this.parsedResponse, + this.parsedResponse, dynamic originalException, }) : super(originalException); From 5aa8bb35be57d6078b56ec301a06e955af770866 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 10:47:03 -0600 Subject: [PATCH 22/42] mockito migration for gql_http_link --- links/gql_http_link/analysis_options.yaml | 4 + links/gql_http_link/pubspec.yaml | 1 + .../test/gql_http_link_test.dart | 57 ++++--- links/gql_http_link/test/mocks.dart | 9 ++ links/gql_http_link/test/mocks.mocks.dart | 145 ++++++++++++++++++ 5 files changed, 185 insertions(+), 31 deletions(-) create mode 100644 links/gql_http_link/test/mocks.dart create mode 100644 links/gql_http_link/test/mocks.mocks.dart diff --git a/links/gql_http_link/analysis_options.yaml b/links/gql_http_link/analysis_options.yaml index 8dd3be2b..dca240a4 100644 --- a/links/gql_http_link/analysis_options.yaml +++ b/links/gql_http_link/analysis_options.yaml @@ -1 +1,5 @@ include: package:gql_pedantic/analysis_options.yaml + +analyzer: + exclude: + - test/**.mocks.dart diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index 2de39e32..2d10395a 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -15,6 +15,7 @@ dev_dependencies: test: ^1.16.2 mockito: ^5.0.0-nullsafety.7 gql_pedantic: ^1.0.2 + build_runner: ^1.11.1 dependency_overrides: gql: diff --git a/links/gql_http_link/test/gql_http_link_test.dart b/links/gql_http_link/test/gql_http_link_test.dart index c2296254..fe32bc99 100644 --- a/links/gql_http_link/test/gql_http_link_test.dart +++ b/links/gql_http_link/test/gql_http_link_test.dart @@ -10,12 +10,7 @@ import "package:mockito/mockito.dart"; import "package:test/test.dart"; import "./helpers.dart"; - -class MockClient extends Mock implements http.Client {} - -class MockRequestSerializer extends Mock implements RequestSerializer {} - -class MockResponseParser extends Mock implements ResponseParser {} +import "./mocks.dart"; class CustomScalar { const CustomScalar(this.value); @@ -52,7 +47,7 @@ void main() { test("parses a successful response", () { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -89,7 +84,7 @@ void main() { test("uses the defined endpoint", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -111,14 +106,14 @@ void main() { "expected endpoint", Uri.parse("/graphql-test"), ), - )!, + ), ), ).called(1); }); test("uses json mime types", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -143,14 +138,14 @@ void main() { containsPair("Accept", "*/*"), ]), ), - )!, + ), ), ).called(1); }); test("adds headers from context", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -188,7 +183,7 @@ void main() { "context headers", containsPair("foo", "bar"), ), - )!, + ), ), ).called(1); }); @@ -204,7 +199,7 @@ void main() { ); when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -235,14 +230,14 @@ void main() { "default headers", containsPair("foo", "bar"), ), - )!, + ), ), ).called(1); }); test("headers from context override defaults", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -280,14 +275,14 @@ void main() { "headers from context", containsPair("Content-type", "application/jsonize"), ), - )!, + ), ), ).called(1); }); test("serializes the request", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -309,14 +304,14 @@ void main() { "serialized body", '{"operationName":null,"variables":{"i":12},"query":"query MyQuery {\\n \\n}"}', ), - )!, + ), ), ).called(1); }); test("serializes all types", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -368,13 +363,13 @@ void main() { r'"query":"query MyQuery($richInput: RichInput) {\n \n}"' r"}", ), - )!, + ), ), ).called(1); }); test("parses a successful response with errors", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -439,7 +434,7 @@ void main() { }); when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse(data, 300), @@ -478,7 +473,7 @@ void main() { final _response = simpleResponse(data, 200); when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( _response, @@ -527,7 +522,7 @@ void main() { final originalException = Exception("Foo bar"); when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -541,7 +536,7 @@ void main() { when( serializer.serializeRequest( - any!, + any, ), ).thenThrow(originalException); @@ -574,7 +569,7 @@ void main() { test("throws ParserException when unable to serialize request", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -635,7 +630,7 @@ void main() { test("uses GET for query without files", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -664,14 +659,14 @@ void main() { "method", "GET", ), - )!, + ), ), ).called(1); }); test("uses POST for mutation", () async { when( - client.send(any!), + client.send(any), ).thenAnswer( (_) => Future.value( simpleResponse( @@ -700,7 +695,7 @@ void main() { "method", "POST", ), - )!, + ), ), ).called(1); }); diff --git a/links/gql_http_link/test/mocks.dart b/links/gql_http_link/test/mocks.dart new file mode 100644 index 00000000..b35b6913 --- /dev/null +++ b/links/gql_http_link/test/mocks.dart @@ -0,0 +1,9 @@ +import "package:mockito/annotations.dart"; + +import "package:http/http.dart" as http; +import "package:gql_link/gql_link.dart"; + +export "./mocks.mocks.dart"; + +@GenerateMocks([http.Client, RequestSerializer, ResponseParser]) +void main() {} diff --git a/links/gql_http_link/test/mocks.mocks.dart b/links/gql_http_link/test/mocks.mocks.dart new file mode 100644 index 00000000..44dc98a5 --- /dev/null +++ b/links/gql_http_link/test/mocks.mocks.dart @@ -0,0 +1,145 @@ +// Mocks generated by Mockito 5.0.0-nullsafety.7 from annotations +// in gql_http_link/test/mocks.dart. +// Do not manually edit this file. + +import 'dart:async' as _i8; +import 'dart:convert' as _i9; +import 'dart:typed_data' as _i3; + +import 'package:gql_exec/src/error.dart' as _i6; +import 'package:gql_exec/src/request.dart' as _i12; +import 'package:gql_exec/src/response.dart' as _i5; +import 'package:gql_link/src/request_serializer.dart' as _i11; +import 'package:gql_link/src/response_parser.dart' as _i13; +import 'package:http/src/base_request.dart' as _i10; +import 'package:http/src/client.dart' as _i7; +import 'package:http/src/response.dart' as _i2; +import 'package:http/src/streamed_response.dart' as _i4; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: comment_references +// ignore_for_file: unnecessary_parenthesis + +class _FakeResponse extends _i1.Fake implements _i2.Response {} + +class _FakeUint8List extends _i1.Fake implements _i3.Uint8List {} + +class _FakeStreamedResponse extends _i1.Fake implements _i4.StreamedResponse {} + +class _FakeResponse extends _i1.Fake implements _i5.Response {} + +class _FakeGraphQLError extends _i1.Fake implements _i6.GraphQLError {} + +class _FakeErrorLocation extends _i1.Fake implements _i6.ErrorLocation {} + +/// A class which mocks [Client]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClient extends _i1.Mock implements _i7.Client { + MockClient() { + _i1.throwOnMissingStub(this); + } + + @override + _i8.Future<_i2.Response> head(Uri? url, {Map? headers}) => + (super.noSuchMethod(Invocation.method(#head, [url], {#headers: headers}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future<_i2.Response> get(Uri? url, {Map? headers}) => + (super.noSuchMethod(Invocation.method(#get, [url], {#headers: headers}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future<_i2.Response> post(Uri? url, + {Map? headers, + Object? body, + _i9.Encoding? encoding}) => + (super.noSuchMethod( + Invocation.method(#post, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future<_i2.Response> put(Uri? url, + {Map? headers, + Object? body, + _i9.Encoding? encoding}) => + (super.noSuchMethod( + Invocation.method(#put, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future<_i2.Response> patch(Uri? url, + {Map? headers, + Object? body, + _i9.Encoding? encoding}) => + (super.noSuchMethod( + Invocation.method(#patch, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future<_i2.Response> delete(Uri? url, + {Map? headers, + Object? body, + _i9.Encoding? encoding}) => + (super.noSuchMethod( + Invocation.method(#delete, [url], + {#headers: headers, #body: body, #encoding: encoding}), + returnValue: Future.value(_FakeResponse())) + as _i8.Future<_i2.Response>); + @override + _i8.Future read(Uri? url, {Map? headers}) => + (super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}), + returnValue: Future.value('')) as _i8.Future); + @override + _i8.Future<_i3.Uint8List> readBytes(Uri? url, + {Map? headers}) => + (super.noSuchMethod( + Invocation.method(#readBytes, [url], {#headers: headers}), + returnValue: Future.value(_FakeUint8List())) + as _i8.Future<_i3.Uint8List>); + @override + _i8.Future<_i4.StreamedResponse> send(_i10.BaseRequest? request) => + (super.noSuchMethod(Invocation.method(#send, [request]), + returnValue: Future.value(_FakeStreamedResponse())) + as _i8.Future<_i4.StreamedResponse>); +} + +/// A class which mocks [RequestSerializer]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockRequestSerializer extends _i1.Mock implements _i11.RequestSerializer { + MockRequestSerializer() { + _i1.throwOnMissingStub(this); + } + + @override + Map serializeRequest(_i12.Request? request) => + (super.noSuchMethod(Invocation.method(#serializeRequest, [request]), + returnValue: {}) as Map); +} + +/// A class which mocks [ResponseParser]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResponseParser extends _i1.Mock implements _i13.ResponseParser { + MockResponseParser() { + _i1.throwOnMissingStub(this); + } + + @override + _i5.Response parseResponse(Map? body) => + (super.noSuchMethod(Invocation.method(#parseResponse, [body]), + returnValue: _FakeResponse()) as _i5.Response); + @override + _i6.GraphQLError parseError(Map? error) => + (super.noSuchMethod(Invocation.method(#parseError, [error]), + returnValue: _FakeGraphQLError()) as _i6.GraphQLError); + @override + _i6.ErrorLocation parseLocation(Map? location) => + (super.noSuchMethod(Invocation.method(#parseLocation, [location]), + returnValue: _FakeErrorLocation()) as _i6.ErrorLocation); +} From b792c305f9125711931c60c07a634f95723e9d53 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 11:20:26 -0600 Subject: [PATCH 23/42] mockito omck generation and test fixes --- links/gql_exec/lib/src/context.dart | 2 +- links/gql_exec/lib/src/response.dart | 6 +- links/gql_http_link/.gitignore | 2 + .../test/gql_http_link_test.dart | 2 +- links/gql_http_link/test/mocks.dart | 9 -- links/gql_http_link/test/mocks.mocks.dart | 145 ------------------ links/gql_http_link/test/mocks/gql_exec.dart | 8 + links/gql_http_link/test/mocks/http.dart | 8 + links/gql_http_link/test/mocks/mocks.dart | 2 + .../test/multipart_upload_test.dart | 18 +-- 10 files changed, 31 insertions(+), 171 deletions(-) delete mode 100644 links/gql_http_link/test/mocks.dart delete mode 100644 links/gql_http_link/test/mocks.mocks.dart create mode 100644 links/gql_http_link/test/mocks/gql_exec.dart create mode 100644 links/gql_http_link/test/mocks/http.dart create mode 100644 links/gql_http_link/test/mocks/mocks.dart diff --git a/links/gql_exec/lib/src/context.dart b/links/gql_exec/lib/src/context.dart index b1250a8a..b42ff1fc 100644 --- a/links/gql_exec/lib/src/context.dart +++ b/links/gql_exec/lib/src/context.dart @@ -14,7 +14,7 @@ abstract class ContextEntry { const ContextEntry(); /// List of values to be used for equality. - List get fieldsForEquality; + List get fieldsForEquality; @override bool operator ==(Object o) => diff --git a/links/gql_exec/lib/src/response.dart b/links/gql_exec/lib/src/response.dart index ce052c7f..88850cbe 100644 --- a/links/gql_exec/lib/src/response.dart +++ b/links/gql_exec/lib/src/response.dart @@ -73,14 +73,14 @@ class Response { @immutable class ResponseExtensions extends ContextEntry { /// [Response] extensions - final dynamic extensions; + final dynamic? extensions; const ResponseExtensions( this.extensions, ); @override - List get fieldsForEquality => [ - extensions as Object, + List get fieldsForEquality => [ + extensions as Object?, ]; } diff --git a/links/gql_http_link/.gitignore b/links/gql_http_link/.gitignore index 50602ac6..41ce92d9 100644 --- a/links/gql_http_link/.gitignore +++ b/links/gql_http_link/.gitignore @@ -4,6 +4,8 @@ # Remove the following pattern if you wish to check in your lock file pubspec.lock +test/**/*.mocks.dart + # Conventional directory for build outputs build/ diff --git a/links/gql_http_link/test/gql_http_link_test.dart b/links/gql_http_link/test/gql_http_link_test.dart index fe32bc99..367135b5 100644 --- a/links/gql_http_link/test/gql_http_link_test.dart +++ b/links/gql_http_link/test/gql_http_link_test.dart @@ -10,7 +10,7 @@ import "package:mockito/mockito.dart"; import "package:test/test.dart"; import "./helpers.dart"; -import "./mocks.dart"; +import "./mocks/mocks.dart"; class CustomScalar { const CustomScalar(this.value); diff --git a/links/gql_http_link/test/mocks.dart b/links/gql_http_link/test/mocks.dart deleted file mode 100644 index b35b6913..00000000 --- a/links/gql_http_link/test/mocks.dart +++ /dev/null @@ -1,9 +0,0 @@ -import "package:mockito/annotations.dart"; - -import "package:http/http.dart" as http; -import "package:gql_link/gql_link.dart"; - -export "./mocks.mocks.dart"; - -@GenerateMocks([http.Client, RequestSerializer, ResponseParser]) -void main() {} diff --git a/links/gql_http_link/test/mocks.mocks.dart b/links/gql_http_link/test/mocks.mocks.dart deleted file mode 100644 index 44dc98a5..00000000 --- a/links/gql_http_link/test/mocks.mocks.dart +++ /dev/null @@ -1,145 +0,0 @@ -// Mocks generated by Mockito 5.0.0-nullsafety.7 from annotations -// in gql_http_link/test/mocks.dart. -// Do not manually edit this file. - -import 'dart:async' as _i8; -import 'dart:convert' as _i9; -import 'dart:typed_data' as _i3; - -import 'package:gql_exec/src/error.dart' as _i6; -import 'package:gql_exec/src/request.dart' as _i12; -import 'package:gql_exec/src/response.dart' as _i5; -import 'package:gql_link/src/request_serializer.dart' as _i11; -import 'package:gql_link/src/response_parser.dart' as _i13; -import 'package:http/src/base_request.dart' as _i10; -import 'package:http/src/client.dart' as _i7; -import 'package:http/src/response.dart' as _i2; -import 'package:http/src/streamed_response.dart' as _i4; -import 'package:mockito/mockito.dart' as _i1; - -// ignore_for_file: comment_references -// ignore_for_file: unnecessary_parenthesis - -class _FakeResponse extends _i1.Fake implements _i2.Response {} - -class _FakeUint8List extends _i1.Fake implements _i3.Uint8List {} - -class _FakeStreamedResponse extends _i1.Fake implements _i4.StreamedResponse {} - -class _FakeResponse extends _i1.Fake implements _i5.Response {} - -class _FakeGraphQLError extends _i1.Fake implements _i6.GraphQLError {} - -class _FakeErrorLocation extends _i1.Fake implements _i6.ErrorLocation {} - -/// A class which mocks [Client]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockClient extends _i1.Mock implements _i7.Client { - MockClient() { - _i1.throwOnMissingStub(this); - } - - @override - _i8.Future<_i2.Response> head(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#head, [url], {#headers: headers}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future<_i2.Response> get(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#get, [url], {#headers: headers}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future<_i2.Response> post(Uri? url, - {Map? headers, - Object? body, - _i9.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#post, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future<_i2.Response> put(Uri? url, - {Map? headers, - Object? body, - _i9.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#put, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future<_i2.Response> patch(Uri? url, - {Map? headers, - Object? body, - _i9.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#patch, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future<_i2.Response> delete(Uri? url, - {Map? headers, - Object? body, - _i9.Encoding? encoding}) => - (super.noSuchMethod( - Invocation.method(#delete, [url], - {#headers: headers, #body: body, #encoding: encoding}), - returnValue: Future.value(_FakeResponse())) - as _i8.Future<_i2.Response>); - @override - _i8.Future read(Uri? url, {Map? headers}) => - (super.noSuchMethod(Invocation.method(#read, [url], {#headers: headers}), - returnValue: Future.value('')) as _i8.Future); - @override - _i8.Future<_i3.Uint8List> readBytes(Uri? url, - {Map? headers}) => - (super.noSuchMethod( - Invocation.method(#readBytes, [url], {#headers: headers}), - returnValue: Future.value(_FakeUint8List())) - as _i8.Future<_i3.Uint8List>); - @override - _i8.Future<_i4.StreamedResponse> send(_i10.BaseRequest? request) => - (super.noSuchMethod(Invocation.method(#send, [request]), - returnValue: Future.value(_FakeStreamedResponse())) - as _i8.Future<_i4.StreamedResponse>); -} - -/// A class which mocks [RequestSerializer]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockRequestSerializer extends _i1.Mock implements _i11.RequestSerializer { - MockRequestSerializer() { - _i1.throwOnMissingStub(this); - } - - @override - Map serializeRequest(_i12.Request? request) => - (super.noSuchMethod(Invocation.method(#serializeRequest, [request]), - returnValue: {}) as Map); -} - -/// A class which mocks [ResponseParser]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockResponseParser extends _i1.Mock implements _i13.ResponseParser { - MockResponseParser() { - _i1.throwOnMissingStub(this); - } - - @override - _i5.Response parseResponse(Map? body) => - (super.noSuchMethod(Invocation.method(#parseResponse, [body]), - returnValue: _FakeResponse()) as _i5.Response); - @override - _i6.GraphQLError parseError(Map? error) => - (super.noSuchMethod(Invocation.method(#parseError, [error]), - returnValue: _FakeGraphQLError()) as _i6.GraphQLError); - @override - _i6.ErrorLocation parseLocation(Map? location) => - (super.noSuchMethod(Invocation.method(#parseLocation, [location]), - returnValue: _FakeErrorLocation()) as _i6.ErrorLocation); -} diff --git a/links/gql_http_link/test/mocks/gql_exec.dart b/links/gql_http_link/test/mocks/gql_exec.dart new file mode 100644 index 00000000..8b3ba6be --- /dev/null +++ b/links/gql_http_link/test/mocks/gql_exec.dart @@ -0,0 +1,8 @@ +import "package:mockito/annotations.dart"; + +import "package:gql_link/gql_link.dart"; + +export "./gql_exec.mocks.dart"; + +@GenerateMocks([RequestSerializer, ResponseParser]) +void main() {} diff --git a/links/gql_http_link/test/mocks/http.dart b/links/gql_http_link/test/mocks/http.dart new file mode 100644 index 00000000..6bf16e22 --- /dev/null +++ b/links/gql_http_link/test/mocks/http.dart @@ -0,0 +1,8 @@ +import "package:mockito/annotations.dart"; + +import "package:http/http.dart" as http; + +export "./http.mocks.dart"; + +@GenerateMocks([http.Client]) +void main() {} diff --git a/links/gql_http_link/test/mocks/mocks.dart b/links/gql_http_link/test/mocks/mocks.dart new file mode 100644 index 00000000..6cbc93ef --- /dev/null +++ b/links/gql_http_link/test/mocks/mocks.dart @@ -0,0 +1,2 @@ +export "./gql_exec.dart" hide main; +export "./http.dart" hide main; diff --git a/links/gql_http_link/test/multipart_upload_test.dart b/links/gql_http_link/test/multipart_upload_test.dart index bffa6f00..14b37318 100644 --- a/links/gql_http_link/test/multipart_upload_test.dart +++ b/links/gql_http_link/test/multipart_upload_test.dart @@ -4,19 +4,13 @@ import "dart:typed_data"; import "package:gql_exec/gql_exec.dart"; import "package:gql/language.dart"; import "package:gql_http_link/gql_http_link.dart"; -import "package:gql_link/gql_link.dart"; import "package:http/http.dart" as http; import "package:http_parser/http_parser.dart"; import "package:mockito/mockito.dart"; import "package:test/test.dart"; import "./helpers.dart"; - -class MockClient extends Mock implements http.Client {} - -class MockRequestSerializer extends Mock implements RequestSerializer {} - -class MockResponseParser extends Mock implements ResponseParser {} +import "./mocks/mocks.dart"; void main() { MockClient? mockHttpClient; @@ -104,7 +98,7 @@ void main() { test("request encoding", () async { Uint8List? bodyBytes; when( - mockHttpClient!.send(any!), + mockHttpClient!.send(any), ).thenAnswer((i) async { bodyBytes = await (i.positionalArguments[0] as http.BaseRequest) .finalize() @@ -115,7 +109,7 @@ void main() { await httpLink.request(gqlRequest).first; final http.MultipartRequest request = verify( - mockHttpClient!.send(captureAny!), + mockHttpClient!.send(captureAny), ).captured.first as http.MultipartRequest; final List contentTypeStringSplit = @@ -169,7 +163,7 @@ void main() { test("response data", () async { when( - mockHttpClient!.send(any!), + mockHttpClient!.send(any), ).thenAnswer( (i) async => simpleResponse(expectedResponse), ); @@ -210,7 +204,7 @@ void main() { test("query request encoding with files", () async { Uint8List? bodyBytes; when( - mockHttpClient!.send(any!), + mockHttpClient!.send(any), ).thenAnswer((i) async { bodyBytes = await (i.positionalArguments[0] as http.BaseRequest) .finalize() @@ -230,7 +224,7 @@ void main() { await httpLink.request(gqlQueryWithFiles).first; final http.MultipartRequest request = verify( - mockHttpClient!.send(captureAny!), + mockHttpClient!.send(captureAny), ).captured.first as http.MultipartRequest; final List contentTypeStringSplit = From 64092c980d4d15917d6d9387b811b338848c8982 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 12:23:49 -0600 Subject: [PATCH 24/42] finally got tests to pass with generated mockito types --- links/gql_exec/lib/src/response.dart | 4 ++-- links/gql_http_link/lib/src/link.dart | 6 +++--- links/gql_http_link/test/gql_http_link_test.dart | 16 ++++++++-------- links/gql_http_link/test/mocks/http.dart | 5 +++-- .../test/multipart_upload_test.dart | 6 +++--- links/gql_link/lib/src/response_parser.dart | 2 +- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/links/gql_exec/lib/src/response.dart b/links/gql_exec/lib/src/response.dart index 88850cbe..aab91421 100644 --- a/links/gql_exec/lib/src/response.dart +++ b/links/gql_exec/lib/src/response.dart @@ -75,9 +75,9 @@ class ResponseExtensions extends ContextEntry { /// [Response] extensions final dynamic? extensions; - const ResponseExtensions( + const ResponseExtensions([ this.extensions, - ); + ]); @override List get fieldsForEquality => [ diff --git a/links/gql_http_link/lib/src/link.dart b/links/gql_http_link/lib/src/link.dart index 11304116..8c30e33a 100644 --- a/links/gql_http_link/lib/src/link.dart +++ b/links/gql_http_link/lib/src/link.dart @@ -9,7 +9,7 @@ import "package:meta/meta.dart"; import "./_utils.dart"; import "./exceptions.dart"; -typedef HttpResponseDecoder = FutureOr>? Function( +typedef HttpResponseDecoder = FutureOr?> Function( http.Response httpResponse); /// HTTP link headers @@ -152,8 +152,8 @@ class HttpLink extends Link { Future _parseHttpResponse(http.Response httpResponse) async { try { - final responseBody = await httpResponseDecoder(httpResponse)!; - return parser.parseResponse(responseBody); + final responseBody = await httpResponseDecoder(httpResponse); + return parser.parseResponse(responseBody!); } catch (e) { throw HttpLinkParserException( originalException: e, diff --git a/links/gql_http_link/test/gql_http_link_test.dart b/links/gql_http_link/test/gql_http_link_test.dart index 367135b5..f730dcca 100644 --- a/links/gql_http_link/test/gql_http_link_test.dart +++ b/links/gql_http_link/test/gql_http_link_test.dart @@ -20,7 +20,7 @@ class CustomScalar { void main() { group("HttpLink", () { - late MockClient client; + late MockHttpClient client; late Request request; late HttpLink link; @@ -32,7 +32,7 @@ void main() { link.request(customRequest ?? request); setUp(() { - client = MockClient(); + client = MockHttpClient(); request = Request( operation: Operation( document: parseString("query MyQuery {}"), @@ -189,7 +189,7 @@ void main() { }); test("adds default headers", () async { - final client = MockClient(); + final client = MockHttpClient(); final link = HttpLink( "/graphql-test", httpClient: client, @@ -484,8 +484,8 @@ void main() { try { await execute().first; - } catch (e) { - exception = e as HttpLinkServerException; + } on HttpLinkServerException catch (e) { + exception = e; } expect( @@ -511,7 +511,7 @@ void main() { test("throws SerializerException when unable to serialize request", () async { - final client = MockClient(); + final client = MockHttpClient(); final serializer = MockRequestSerializer(); final link = HttpLink( "/graphql-test", @@ -616,11 +616,11 @@ void main() { }); group("HttpLink useGETForQueries", () { - late MockClient client; + late MockHttpClient client; late HttpLink link; setUp(() { - client = MockClient(); + client = MockHttpClient(); link = HttpLink( "/graphql-test", httpClient: client, diff --git a/links/gql_http_link/test/mocks/http.dart b/links/gql_http_link/test/mocks/http.dart index 6bf16e22..704902a6 100644 --- a/links/gql_http_link/test/mocks/http.dart +++ b/links/gql_http_link/test/mocks/http.dart @@ -1,8 +1,9 @@ import "package:mockito/annotations.dart"; - import "package:http/http.dart" as http; export "./http.mocks.dart"; -@GenerateMocks([http.Client]) +@GenerateMocks([], customMocks: [ + MockSpec(returnNullOnMissingStub: true, as: #MockHttpClient) +]) void main() {} diff --git a/links/gql_http_link/test/multipart_upload_test.dart b/links/gql_http_link/test/multipart_upload_test.dart index 14b37318..dc8c83cd 100644 --- a/links/gql_http_link/test/multipart_upload_test.dart +++ b/links/gql_http_link/test/multipart_upload_test.dart @@ -13,7 +13,7 @@ import "./helpers.dart"; import "./mocks/mocks.dart"; void main() { - MockClient? mockHttpClient; + MockHttpClient? mockHttpClient; late HttpLink httpLink; const String uploadMutation = r""" @@ -78,7 +78,7 @@ void main() { group("upload", () { late Request gqlRequest; setUp(() { - mockHttpClient = MockClient(); + mockHttpClient = MockHttpClient(); httpLink = HttpLink( "http://localhost:3001/graphql", @@ -192,7 +192,7 @@ void main() { group("file upload useGETForQueries behavior", () { setUp(() { - mockHttpClient = MockClient(); + mockHttpClient = MockHttpClient(); httpLink = HttpLink( "http://localhost:3001/graphql", diff --git a/links/gql_link/lib/src/response_parser.dart b/links/gql_link/lib/src/response_parser.dart index 04a666c4..bd807de5 100644 --- a/links/gql_link/lib/src/response_parser.dart +++ b/links/gql_link/lib/src/response_parser.dart @@ -13,7 +13,7 @@ class ResponseParser { (dynamic error) => parseError(error as Map), ) .toList(), - data: body["data"] as Map, + data: body["data"] as Map?, context: Context().withEntry( ResponseExtensions( body["extensions"], From 72259a576b096ad39253c1092d90c2a750656c2c Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:25:47 -0600 Subject: [PATCH 25/42] testing CI --- .github/workflows/dart.yml | 2 ++ check_package.sh | 31 +++++++++++++++++++++++++++++++ links/gql_http_link/pubspec.yaml | 8 -------- 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100755 check_package.sh diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 158e949a..609f2b59 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -56,6 +56,8 @@ jobs: multipack --only $PACKAGE analyze --fatal-warnings --no-hints . - name: Run tests run: | + # mockito requires build runner now + multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test examples: diff --git a/check_package.sh b/check_package.sh new file mode 100755 index 00000000..d339e28e --- /dev/null +++ b/check_package.sh @@ -0,0 +1,31 @@ +#/bin/bash + +set -e + +PACKAGE=$1 + +# Check pubspec +multipack --only $PACKAGE pubspec clean +multipack --only $PACKAGE exec git diff --exit-code pubspec.yaml + +# Override local dependencies +multipack pubspec hard_override + +multipack --only $PACKAGE pub get + +# Check formatting +echo "" +echo "A list of incorrectly formatted files may follow:" +echo "" +multipack --only $PACKAGE fmt -n . --set-exit-if-changed +echo "" + +# Analyze package +multipack --only $PACKAGE analyze --version +multipack --only $PACKAGE analyze --fatal-warnings --no-hints . + +# Run tests +# mockito requires build runner now +multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs +multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 +multipack --only $PACKAGE pub run test diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index 2d10395a..49db6da4 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -16,11 +16,3 @@ dev_dependencies: mockito: ^5.0.0-nullsafety.7 gql_pedantic: ^1.0.2 build_runner: ^1.11.1 - -dependency_overrides: - gql: - path: ../../gql - gql_exec: - path: ../gql_exec - gql_link: - path: ../gql_link From 523465ac0d4abf219d2a1a50a5a7db4df36768d8 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:31:16 -0600 Subject: [PATCH 26/42] CI analysis issue --- check_package.sh => .github/check_package.sh | 0 links/gql_http_link/analysis_options.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename check_package.sh => .github/check_package.sh (100%) diff --git a/check_package.sh b/.github/check_package.sh similarity index 100% rename from check_package.sh rename to .github/check_package.sh diff --git a/links/gql_http_link/analysis_options.yaml b/links/gql_http_link/analysis_options.yaml index dca240a4..c2fb402d 100644 --- a/links/gql_http_link/analysis_options.yaml +++ b/links/gql_http_link/analysis_options.yaml @@ -2,4 +2,4 @@ include: package:gql_pedantic/analysis_options.yaml analyzer: exclude: - - test/**.mocks.dart + - **/*.mocks.dart From 0f1edb7866ad6a4e9638e57da9093a059daaf69b Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:40:41 -0600 Subject: [PATCH 27/42] check only if no diff --- .github/check_package.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/check_package.sh b/.github/check_package.sh index d339e28e..ea1aeccd 100755 --- a/.github/check_package.sh +++ b/.github/check_package.sh @@ -4,12 +4,23 @@ set -e PACKAGE=$1 +git diff --exit-code + +clean_up () { + ARG=$? + git checkout . + exit $ARG +} + +trap clean_up EXIT + + # Check pubspec multipack --only $PACKAGE pubspec clean multipack --only $PACKAGE exec git diff --exit-code pubspec.yaml # Override local dependencies -multipack pubspec hard_override +multipack pubspec override multipack --only $PACKAGE pub get @@ -29,3 +40,5 @@ multipack --only $PACKAGE analyze --fatal-warnings --no-hints . multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test + +git checkout . From cf46960b986eb9ecd6810662a103fb9b00a312c6 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:41:12 -0600 Subject: [PATCH 28/42] hard override --- .github/check_package.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/check_package.sh b/.github/check_package.sh index ea1aeccd..72a33c7c 100755 --- a/.github/check_package.sh +++ b/.github/check_package.sh @@ -14,13 +14,12 @@ clean_up () { trap clean_up EXIT - # Check pubspec multipack --only $PACKAGE pubspec clean multipack --only $PACKAGE exec git diff --exit-code pubspec.yaml # Override local dependencies -multipack pubspec override +multipack pubspec hard_override multipack --only $PACKAGE pub get From d50fadfa519540fdcceb220bb2a73d73daff9817 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:45:43 -0600 Subject: [PATCH 29/42] loosen gql_http_link build_runner constraint --- links/gql_http_link/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index 49db6da4..bff847af 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -15,4 +15,4 @@ dev_dependencies: test: ^1.16.2 mockito: ^5.0.0-nullsafety.7 gql_pedantic: ^1.0.2 - build_runner: ^1.11.1 + build_runner: ^1.10.1 From d0d08dcb9527450ba2b2451457730e11469ce231 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:53:33 -0600 Subject: [PATCH 30/42] attempt bumping build runner and analyzer --- codegen/end_to_end_test/pubspec.yaml | 2 +- codegen/gql_build/pubspec.yaml | 2 +- codegen/gql_code_builder/pubspec.yaml | 4 ++-- examples/gql_example_build/pubspec.yaml | 2 +- examples/gql_example_cli/pubspec.yaml | 2 +- examples/gql_example_cli_github/pubspec.yaml | 2 +- examples/gql_example_flutter/pubspec.yaml | 2 +- links/gql_http_link/pubspec.yaml | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/codegen/end_to_end_test/pubspec.yaml b/codegen/end_to_end_test/pubspec.yaml index 9e7fffbe..6553b90e 100644 --- a/codegen/end_to_end_test/pubspec.yaml +++ b/codegen/end_to_end_test/pubspec.yaml @@ -14,5 +14,5 @@ dependencies: dev_dependencies: collection: ^1.14.13 build: ^1.0.0 - build_runner: ^1.10.1 + build_runner: ^1.11.1 test: ^1.0.0 diff --git a/codegen/gql_build/pubspec.yaml b/codegen/gql_build/pubspec.yaml index bc69d288..d7b75820 100644 --- a/codegen/gql_build/pubspec.yaml +++ b/codegen/gql_build/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/gql-dart/gql environment: sdk: '>=2.7.2 <3.0.0' dependencies: - analyzer: ^0.39.14 + analyzer: ^0.40.1 gql: ^0.12.4 path: ^1.6.4 glob: ^1.2.0 diff --git a/codegen/gql_code_builder/pubspec.yaml b/codegen/gql_code_builder/pubspec.yaml index 8dc39612..ed669dd5 100644 --- a/codegen/gql_code_builder/pubspec.yaml +++ b/codegen/gql_code_builder/pubspec.yaml @@ -5,7 +5,7 @@ repository: https://github.com/gql-dart/gql environment: sdk: '>=2.7.2 <3.0.0' dependencies: - analyzer: ^0.39.14 + analyzer: ^0.40.1 gql: ^0.12.4 code_builder: ^3.3.0 meta: ^1.1.7 @@ -16,5 +16,5 @@ dependencies: gql_exec: ^0.2.5 dev_dependencies: gql_pedantic: ^1.0.2 - build_runner: ^1.7.4 + build_runner: ^1.11.1 test: ^1.0.0 diff --git a/examples/gql_example_build/pubspec.yaml b/examples/gql_example_build/pubspec.yaml index 8b114f59..466c9a6a 100644 --- a/examples/gql_example_build/pubspec.yaml +++ b/examples/gql_example_build/pubspec.yaml @@ -2,7 +2,7 @@ name: gql_example_build environment: sdk: '>=2.7.2 <3.0.0' dev_dependencies: - build_runner: ^1.10.1 + build_runner: ^1.11.1 gql_pedantic: ^1.0.2 gql_build: ^0.1.3 test: ^1.0.0 diff --git a/examples/gql_example_cli/pubspec.yaml b/examples/gql_example_cli/pubspec.yaml index 6df791d7..929af19a 100644 --- a/examples/gql_example_cli/pubspec.yaml +++ b/examples/gql_example_cli/pubspec.yaml @@ -8,6 +8,6 @@ dependencies: gql_exec: ^0.2.5 gql_http_link: ^0.3.2 dev_dependencies: - build_runner: ^1.10.1 + build_runner: ^1.11.1 gql_pedantic: ^1.0.2 gql_build: ^0.1.3 diff --git a/examples/gql_example_cli_github/pubspec.yaml b/examples/gql_example_cli_github/pubspec.yaml index fc9d9547..31f070d4 100644 --- a/examples/gql_example_cli_github/pubspec.yaml +++ b/examples/gql_example_cli_github/pubspec.yaml @@ -9,6 +9,6 @@ dependencies: gql_http_link: ^0.3.2 gql_transform_link: ^0.1.5 dev_dependencies: - build_runner: ^1.10.1 + build_runner: ^1.11.1 gql_pedantic: ^1.0.2 gql_build: ^0.1.3 diff --git a/examples/gql_example_flutter/pubspec.yaml b/examples/gql_example_flutter/pubspec.yaml index 2fc4a034..a4b5f472 100644 --- a/examples/gql_example_flutter/pubspec.yaml +++ b/examples/gql_example_flutter/pubspec.yaml @@ -11,7 +11,7 @@ dependencies: flutter: sdk: flutter dev_dependencies: - build_runner: ^1.10.1 + build_runner: ^1.11.1 gql_pedantic: ^1.0.2 gql_build: ^0.1.3 flutter_test: diff --git a/links/gql_http_link/pubspec.yaml b/links/gql_http_link/pubspec.yaml index bff847af..49db6da4 100644 --- a/links/gql_http_link/pubspec.yaml +++ b/links/gql_http_link/pubspec.yaml @@ -15,4 +15,4 @@ dev_dependencies: test: ^1.16.2 mockito: ^5.0.0-nullsafety.7 gql_pedantic: ^1.0.2 - build_runner: ^1.10.1 + build_runner: ^1.11.1 From e24bfc5697ddec625255e46fe5dc8920a3f2a64a Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:55:00 -0600 Subject: [PATCH 31/42] bump built value --- codegen/gql_build/pubspec.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/gql_build/pubspec.yaml b/codegen/gql_build/pubspec.yaml index d7b75820..268328ee 100644 --- a/codegen/gql_build/pubspec.yaml +++ b/codegen/gql_build/pubspec.yaml @@ -13,8 +13,8 @@ dependencies: gql_code_builder: ^0.1.4 code_builder: ^3.3.0 dart_style: ^1.2.9 - built_value: ^7.1.0 - built_value_generator: ^7.1.0 + built_value: ^8.0.0 + built_value_generator: ^8.0.0 built_collection: ^4.3.2 yaml: ^2.2.1 dev_dependencies: From 787418723fa60ea3133f377b443c18d4504a722f Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:55:41 -0600 Subject: [PATCH 32/42] bump built value --- codegen/end_to_end_test/pubspec.yaml | 2 +- codegen/gql_code_builder/pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codegen/end_to_end_test/pubspec.yaml b/codegen/end_to_end_test/pubspec.yaml index 6553b90e..9f4f7ba2 100644 --- a/codegen/end_to_end_test/pubspec.yaml +++ b/codegen/end_to_end_test/pubspec.yaml @@ -7,7 +7,7 @@ environment: sdk: '>=2.0.0-dev <3.0.0' dependencies: built_collection: '>=2.0.0 <5.0.0' - built_value: ^7.0.2 + built_value: ^8.0.0 gql_exec: ^0.2.5 gql_build: ^0.1.3 gql_code_builder: ^0.1.3 diff --git a/codegen/gql_code_builder/pubspec.yaml b/codegen/gql_code_builder/pubspec.yaml index ed669dd5..2a7e3f77 100644 --- a/codegen/gql_code_builder/pubspec.yaml +++ b/codegen/gql_code_builder/pubspec.yaml @@ -10,7 +10,7 @@ dependencies: code_builder: ^3.3.0 meta: ^1.1.7 built_collection: ^4.0.0 - built_value: ^7.0.9 + built_value: ^8.0.0 path: ^1.6.4 recase: ^3.0.0 gql_exec: ^0.2.5 From a7f17bc60fef2c888dbfa9bcfbb218e5b5ced720 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 13:56:43 -0600 Subject: [PATCH 33/42] bump built collectoi --- codegen/end_to_end_test/pubspec.yaml | 2 +- codegen/gql_build/pubspec.yaml | 2 +- codegen/gql_code_builder/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen/end_to_end_test/pubspec.yaml b/codegen/end_to_end_test/pubspec.yaml index 9f4f7ba2..0f399961 100644 --- a/codegen/end_to_end_test/pubspec.yaml +++ b/codegen/end_to_end_test/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/gql-dart/gql environment: sdk: '>=2.0.0-dev <3.0.0' dependencies: - built_collection: '>=2.0.0 <5.0.0' + built_collection: ^5.0.0 built_value: ^8.0.0 gql_exec: ^0.2.5 gql_build: ^0.1.3 diff --git a/codegen/gql_build/pubspec.yaml b/codegen/gql_build/pubspec.yaml index 268328ee..c942c5f3 100644 --- a/codegen/gql_build/pubspec.yaml +++ b/codegen/gql_build/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: dart_style: ^1.2.9 built_value: ^8.0.0 built_value_generator: ^8.0.0 - built_collection: ^4.3.2 + built_collection: ^5.0.0 yaml: ^2.2.1 dev_dependencies: build_test: ^0.10.7 diff --git a/codegen/gql_code_builder/pubspec.yaml b/codegen/gql_code_builder/pubspec.yaml index 2a7e3f77..ff49f4ad 100644 --- a/codegen/gql_code_builder/pubspec.yaml +++ b/codegen/gql_code_builder/pubspec.yaml @@ -9,7 +9,7 @@ dependencies: gql: ^0.12.4 code_builder: ^3.3.0 meta: ^1.1.7 - built_collection: ^4.0.0 + built_collection: ^5.0.0 built_value: ^8.0.0 path: ^1.6.4 recase: ^3.0.0 From cdb37c53722661f72a6feb945ed0fcfdbe13a7b4 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 14:08:46 -0600 Subject: [PATCH 34/42] ignore mockito build failure --- .github/check_package.sh | 2 +- .github/workflows/dart.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/check_package.sh b/.github/check_package.sh index 72a33c7c..fe832fcf 100755 --- a/.github/check_package.sh +++ b/.github/check_package.sh @@ -36,7 +36,7 @@ multipack --only $PACKAGE analyze --fatal-warnings --no-hints . # Run tests # mockito requires build runner now -multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs +multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs || true multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 609f2b59..7f137274 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -57,7 +57,7 @@ jobs: - name: Run tests run: | # mockito requires build runner now - multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs + multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs || true multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test examples: From c88099014224426762d8548bfe75d50092947dc9 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 14:15:01 -0600 Subject: [PATCH 35/42] build runner as separate step --- .github/workflows/dart.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 7f137274..64deefd6 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -50,6 +50,10 @@ jobs: echo "" multipack --only $PACKAGE fmt -n . --set-exit-if-changed echo "" + - name: Run build_runner if necessary + run: | + multipack --only $PACKAGE pub run \ + build_runner build --delete-conflicting-outputs || true - name: Analyze package run: | multipack --only $PACKAGE analyze --version @@ -57,7 +61,6 @@ jobs: - name: Run tests run: | # mockito requires build runner now - multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs || true multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test examples: From 3a2cb9f30a2f085b70cc001c8adbafce81e7feb5 Mon Sep 17 00:00:00 2001 From: micimize Date: Sun, 14 Feb 2021 14:38:56 -0600 Subject: [PATCH 36/42] gql_example_http_auth_link: bump http version --- examples/gql_example_http_auth_link/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/gql_example_http_auth_link/pubspec.yaml b/examples/gql_example_http_auth_link/pubspec.yaml index 9d8a28ea..570ef0bd 100644 --- a/examples/gql_example_http_auth_link/pubspec.yaml +++ b/examples/gql_example_http_auth_link/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: gql_error_link: ^0.1.0 gql_transform_link: ^0.1.5 gql_http_link: ^0.3.2 - http: ^0.12.0+2 + http: ^0.13.0 dev_dependencies: gql_pedantic: ^1.0.2 gql_build: ^0.1.3 From 03701f6ff706156d89af79d4d027787d33836c07 Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 11:47:02 -0600 Subject: [PATCH 37/42] migrate dedupe_link --- .gitignore | 2 ++ links/gql_dedupe_link/.gitignore | 2 ++ links/gql_dedupe_link/lib/gql_dedupe_link.dart | 6 +++--- links/gql_dedupe_link/pubspec.yaml | 10 +++++----- .../gql_dedupe_link/test/gql_dedupe_link_test.dart | 13 ++++++++++++- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index bc6ef711..da9d8101 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ doc/api/ .vscode/ **/*.iml + +**/test/**/*.mocks.dart diff --git a/links/gql_dedupe_link/.gitignore b/links/gql_dedupe_link/.gitignore index 50602ac6..41ce92d9 100644 --- a/links/gql_dedupe_link/.gitignore +++ b/links/gql_dedupe_link/.gitignore @@ -4,6 +4,8 @@ # Remove the following pattern if you wish to check in your lock file pubspec.lock +test/**/*.mocks.dart + # Conventional directory for build outputs build/ diff --git a/links/gql_dedupe_link/lib/gql_dedupe_link.dart b/links/gql_dedupe_link/lib/gql_dedupe_link.dart index 7b66b942..c121d891 100644 --- a/links/gql_dedupe_link/lib/gql_dedupe_link.dart +++ b/links/gql_dedupe_link/lib/gql_dedupe_link.dart @@ -12,13 +12,13 @@ class DedupeLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) { if (_inFlight.containsKey(request)) { - return _inFlight[request].split(); + return _inFlight[request]!.split(); } - final splitter = StreamSplitter(forward(request)); + final splitter = StreamSplitter(forward!(request)); _inFlight[request] = splitter; diff --git a/links/gql_dedupe_link/pubspec.yaml b/links/gql_dedupe_link/pubspec.yaml index 305dfcba..475e2f99 100644 --- a/links/gql_dedupe_link/pubspec.yaml +++ b/links/gql_dedupe_link/pubspec.yaml @@ -3,14 +3,14 @@ version: 1.0.10 description: GQL Link to deduplicate identical in-flight execution requests repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.12.beta <3.0.0' dependencies: - meta: ^1.1.7 + meta: ^1.3.0 gql_exec: ^0.2.5 gql_link: ^0.3.1 - async: ^2.3.0 + async: ^2.5.0 dev_dependencies: - test: ^1.0.0 - mockito: ^4.1.1 + test: ^1.16.2 + mockito: ^5.0.0-nullsafety.7 gql: ^0.12.3 gql_pedantic: ^1.0.2 diff --git a/links/gql_dedupe_link/test/gql_dedupe_link_test.dart b/links/gql_dedupe_link/test/gql_dedupe_link_test.dart index edb95900..862000ae 100644 --- a/links/gql_dedupe_link/test/gql_dedupe_link_test.dart +++ b/links/gql_dedupe_link/test/gql_dedupe_link_test.dart @@ -5,10 +5,21 @@ import "package:gql_dedupe_link/gql_dedupe_link.dart"; import "package:gql_exec/gql_exec.dart"; import "package:gql_link/gql_link.dart"; import "package:mockito/mockito.dart"; +import "package:mockito/annotations.dart"; import "package:test/test.dart"; -class MockLink extends Mock implements Link {} +class MockLink extends Mock implements Link { + @override + Stream request(Request? request, [NextLink? forward]) => + super.noSuchMethod( + Invocation.method(#request, [request, forward]), + returnValue: Stream.fromIterable( + [], + ), + ) as Stream; +} +@GenerateMocks([Link]) void main() { group("DedupeLink", () { test("executes a request", () async { From 0c055c0039102283c98adf0ab06aca0a5a34f032 Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 11:52:05 -0600 Subject: [PATCH 38/42] cleanup unneeded mocklink codegen --- links/gql_dedupe_link/test/gql_dedupe_link_test.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/links/gql_dedupe_link/test/gql_dedupe_link_test.dart b/links/gql_dedupe_link/test/gql_dedupe_link_test.dart index 862000ae..c2e90db2 100644 --- a/links/gql_dedupe_link/test/gql_dedupe_link_test.dart +++ b/links/gql_dedupe_link/test/gql_dedupe_link_test.dart @@ -5,7 +5,6 @@ import "package:gql_dedupe_link/gql_dedupe_link.dart"; import "package:gql_exec/gql_exec.dart"; import "package:gql_link/gql_link.dart"; import "package:mockito/mockito.dart"; -import "package:mockito/annotations.dart"; import "package:test/test.dart"; class MockLink extends Mock implements Link { @@ -19,7 +18,6 @@ class MockLink extends Mock implements Link { ) as Stream; } -@GenerateMocks([Link]) void main() { group("DedupeLink", () { test("executes a request", () async { From 3617102ca5eef8ba471ef98b31ff49c9556259b7 Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 11:52:25 -0600 Subject: [PATCH 39/42] migrate transform link --- links/gql_transform_link/lib/gql_transform_link.dart | 12 ++++++------ links/gql_transform_link/pubspec.yaml | 6 +++--- .../test/gql_transform_link_test.dart | 11 ++++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/links/gql_transform_link/lib/gql_transform_link.dart b/links/gql_transform_link/lib/gql_transform_link.dart index 868f26e6..68d76088 100644 --- a/links/gql_transform_link/lib/gql_transform_link.dart +++ b/links/gql_transform_link/lib/gql_transform_link.dart @@ -11,8 +11,8 @@ typedef ResponseTransformer = Response Function(Response response); /// A [Link] to transform [Request]s and [Response]s class TransformLink extends Link { - final RequestTransformer requestTransformer; - final ResponseTransformer responseTransformer; + final RequestTransformer? requestTransformer; + final ResponseTransformer? responseTransformer; TransformLink({ this.requestTransformer, @@ -22,15 +22,15 @@ class TransformLink extends Link { @override Stream request( Request request, [ - NextLink forward, + NextLink? forward, ]) { final req = - requestTransformer != null ? requestTransformer(request) : request; + requestTransformer != null ? requestTransformer!(request) : request; if (responseTransformer == null) { - return forward(req); + return forward!(req); } - return forward(req).map(responseTransformer); + return forward!(req).map(responseTransformer!); } } diff --git a/links/gql_transform_link/pubspec.yaml b/links/gql_transform_link/pubspec.yaml index 2bde5caf..c2a2ac2e 100644 --- a/links/gql_transform_link/pubspec.yaml +++ b/links/gql_transform_link/pubspec.yaml @@ -3,12 +3,12 @@ version: 0.1.5 description: GQL Link to transform Requests and Responses. May be used to update context, document, variables, data, errors, etc. repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.12.beta <3.0.0' dependencies: gql_exec: ^0.2.5 gql_link: ^0.3.1 dev_dependencies: - test: ^1.0.0 - mockito: ^4.1.1 + test: ^1.16.2 + mockito: ^5.0.0-nullsafety.7 gql: ^0.12.3 gql_pedantic: ^1.0.2 diff --git a/links/gql_transform_link/test/gql_transform_link_test.dart b/links/gql_transform_link/test/gql_transform_link_test.dart index 51318e19..eb16cd8c 100644 --- a/links/gql_transform_link/test/gql_transform_link_test.dart +++ b/links/gql_transform_link/test/gql_transform_link_test.dart @@ -7,7 +7,16 @@ import "package:gql_transform_link/gql_transform_link.dart"; import "package:mockito/mockito.dart"; import "package:test/test.dart"; -class MockLink extends Mock implements Link {} +class MockLink extends Mock implements Link { + @override + Stream request(Request? request, [NextLink? forward]) => + super.noSuchMethod( + Invocation.method(#request, [request, forward]), + returnValue: Stream.fromIterable( + [], + ), + ) as Stream; +} void main() { group("Transform Link", () { From ddd20b290604fec4bc809a83f5ac0b924c4dfd19 Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 12:06:00 -0600 Subject: [PATCH 40/42] migrate error link --- .../example/gql_error_link_example.dart | 4 +-- links/gql_error_link/lib/gql_error_link.dart | 18 +++++----- links/gql_error_link/pubspec.yaml | 10 +++--- .../test/gql_error_link_test.dart | 36 +++++++++++-------- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/links/gql_error_link/example/gql_error_link_example.dart b/links/gql_error_link/example/gql_error_link_example.dart index ff7c021c..b102f517 100644 --- a/links/gql_error_link/example/gql_error_link_example.dart +++ b/links/gql_error_link/example/gql_error_link_example.dart @@ -16,7 +16,7 @@ final terminatingLink = Link.function( // Otherwise, yield some [Response]. yield Response( - data: { + data: { "magic": token.token, }, ); @@ -25,7 +25,7 @@ final terminatingLink = Link.function( // In this case [AuthToken] is a simple container of a [String] token. class AuthToken extends ContextEntry { - final String token; + final String? token; const AuthToken({this.token}); diff --git a/links/gql_error_link/lib/gql_error_link.dart b/links/gql_error_link/lib/gql_error_link.dart index 1f5a4d26..a8ff98b2 100644 --- a/links/gql_error_link/lib/gql_error_link.dart +++ b/links/gql_error_link/lib/gql_error_link.dart @@ -7,14 +7,14 @@ import "package:gql_link/gql_link.dart"; import "package:gql_exec/gql_exec.dart"; /// A handler of GraphQL errors. -typedef ErrorHandler = Stream Function( +typedef ErrorHandler = Stream? Function( Request request, NextLink forward, Response response, ); /// A handler of Link Exceptions. -typedef ExceptionHandler = Stream Function( +typedef ExceptionHandler = Stream? Function( Request request, NextLink forward, LinkException exception, @@ -28,8 +28,8 @@ typedef ExceptionHandler = Stream Function( /// `null`, the original stream is left intact and will be allowed to continue /// streaming new events. class ErrorLink extends Link { - final ErrorHandler onGraphQLError; - final ExceptionHandler onException; + final ErrorHandler? onGraphQLError; + final ExceptionHandler? onException; const ErrorLink({ this.onGraphQLError, @@ -41,12 +41,12 @@ class ErrorLink extends Link { Request request, [ forward, ]) async* { - await for (final result in Result.captureStream(forward(request))) { + await for (final result in Result.captureStream(forward!(request))) { if (result.isError) { - final error = result.asError.error; + final error = result.asError!.error; if (onException != null && error is LinkException) { - final stream = onException(request, forward, error); + final stream = onException!(request, forward, error); if (stream != null) { yield* stream; @@ -59,11 +59,11 @@ class ErrorLink extends Link { } if (result.isValue) { - final response = result.asValue.value; + final response = result.asValue!.value; final errors = response.errors; if (onGraphQLError != null && errors != null && errors.isNotEmpty) { - final stream = onGraphQLError(request, forward, response); + final stream = onGraphQLError!(request, forward, response); if (stream != null) { yield* stream; diff --git a/links/gql_error_link/pubspec.yaml b/links/gql_error_link/pubspec.yaml index 5def8136..9e6f0909 100644 --- a/links/gql_error_link/pubspec.yaml +++ b/links/gql_error_link/pubspec.yaml @@ -3,14 +3,14 @@ version: 0.1.0 description: GQL Link to handle execution errors and exceptions repository: https://github.com/gql-dart/gql environment: - sdk: '>=2.7.2 <3.0.0' + sdk: '>=2.12.0-259.12.beta <3.0.0' dependencies: - async: ^2.3.0 + async: ^2.5.0 gql_exec: ^0.2.5 gql_link: ^0.3.1 - meta: ^1.1.7 + meta: ^1.3.0 dev_dependencies: - test: ^1.0.0 - mockito: ^4.1.1 + test: ^1.16.2 + mockito: ^5.0.0-nullsafety.7 gql: ^0.12.3 gql_pedantic: ^1.0.2 diff --git a/links/gql_error_link/test/gql_error_link_test.dart b/links/gql_error_link/test/gql_error_link_test.dart index 2e9107c0..e6f4a9a9 100644 --- a/links/gql_error_link/test/gql_error_link_test.dart +++ b/links/gql_error_link/test/gql_error_link_test.dart @@ -1,5 +1,6 @@ import "dart:async"; +import "package:gql/language.dart"; import "package:gql_error_link/gql_error_link.dart"; import "package:gql_exec/gql_exec.dart"; import "package:gql_link/gql_link.dart"; @@ -19,13 +20,18 @@ class TestException extends LinkException { } void main() { + Request req() => Request( + operation: Operation(document: parseString("")), + variables: const {"i": 12}, + ); + group("ErrorLink", () { group("passthrough", () { test("response", () { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Stream.fromIterable([ Response(data: const {"a": 1}), ]), @@ -44,7 +50,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Stream.fromIterable([ Response( data: const {"a": 1}, @@ -73,7 +79,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -94,7 +100,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Stream.fromIterable([ Response(data: const {"a": 1}), Response(data: const {"a": 1}), @@ -115,7 +121,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.value(Response(data: const {"a": 1})), @@ -138,7 +144,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -161,7 +167,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -186,7 +192,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error("exception"), @@ -215,7 +221,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -249,7 +255,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -280,7 +286,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.error(TestException(1)), @@ -305,7 +311,7 @@ void main() { final link = ErrorLink(); final responseStream = link.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.value( @@ -336,7 +342,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.value( @@ -384,7 +390,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.value( @@ -429,7 +435,7 @@ void main() { ); final responseStream = errorLink.request( - null, + req(), (request) => Result.releaseStream( Stream.fromIterable([ Result.value( From 6885e14e0186acdef9bb6710caa00f05d14daa52 Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 12:10:40 -0600 Subject: [PATCH 41/42] move gql_example_http_auth_link to examples, add other examples --- .github/workflows/dart.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 64deefd6..6bd34119 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -19,7 +19,6 @@ jobs: - gql_websocket_link - gql_transform_link - cats - - gql_example_http_auth_link runs-on: ubuntu-latest container: image: google/dart:2.12-beta @@ -60,7 +59,6 @@ jobs: multipack --only $PACKAGE analyze --fatal-warnings --no-hints . - name: Run tests run: | - # mockito requires build runner now multipack --only $PACKAGE exec [ ! -d ./test ] && exit 0 multipack --only $PACKAGE pub run test examples: @@ -70,6 +68,9 @@ jobs: - gql_example_cli - gql_example_cli_github - gql_example_build + - gql_example_http_auth_link + - gql_example_dio_link + # gql_example_flutter would require flutter runs-on: ubuntu-latest container: image: google/dart:2.12-beta From 756a08d016bce1ef28cd8df3e4dcfab1ea9e8a7d Mon Sep 17 00:00:00 2001 From: micimize Date: Mon, 15 Feb 2021 12:13:30 -0600 Subject: [PATCH 42/42] ignore lack of build runners in examples --- .github/workflows/dart.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 6bd34119..c1aaa86d 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -96,7 +96,8 @@ jobs: multipack --only $PACKAGE pub get - name: Run builders run: | - multipack --only $PACKAGE pub run build_runner build --delete-conflicting-outputs + multipack --only $PACKAGE pub run \ + build_runner build --delete-conflicting-outputs || true - name: Check build diff run: | multipack --only $PACKAGE exec git diff --exit-code **/*.gql.dart