diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.dart index 7832b208..2d9fc4e4 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.dart @@ -24,7 +24,7 @@ abstract class GPostsWithFixedVariableVars static void _initializeBuilder(GPostsWithFixedVariableVarsBuilder b) => b..filter = const _i1.AbsentValue(); - _i1.Value<_i2.GJson>? get filter; + _i1.Value<_i2.GJson> get filter; Map toJson() => (_i3.serializers.serializeWith( GPostsWithFixedVariableVars.serializer, this, diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.g.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.g.dart index 3bb7c025..ba3dace7 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/fragment_with_scalar_var.var.gql.g.dart @@ -8,13 +8,16 @@ part of 'fragment_with_scalar_var.var.gql.dart'; class _$GPostsWithFixedVariableVars extends GPostsWithFixedVariableVars { @override - final _i1.Value<_i2.GJson>? filter; + final _i1.Value<_i2.GJson> filter; factory _$GPostsWithFixedVariableVars( [void Function(GPostsWithFixedVariableVarsBuilder)? updates]) => (new GPostsWithFixedVariableVarsBuilder()..update(updates))._build(); - _$GPostsWithFixedVariableVars._({this.filter}) : super._(); + _$GPostsWithFixedVariableVars._({required this.filter}) : super._() { + BuiltValueNullFieldError.checkNotNull( + filter, r'GPostsWithFixedVariableVars', 'filter'); + } @override GPostsWithFixedVariableVars rebuild( @@ -85,7 +88,10 @@ class GPostsWithFixedVariableVarsBuilder GPostsWithFixedVariableVars build() => _build(); _$GPostsWithFixedVariableVars _build() { - final _$result = _$v ?? new _$GPostsWithFixedVariableVars._(filter: filter); + final _$result = _$v ?? + new _$GPostsWithFixedVariableVars._( + filter: BuiltValueNullFieldError.checkNotNull( + filter, r'GPostsWithFixedVariableVars', 'filter')); replace(_$result); return _$result; } diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.dart index d325d7dc..5d7c50cb 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.dart @@ -21,7 +21,7 @@ abstract class GHeroWithFragmentsVars static void _initializeBuilder(GHeroWithFragmentsVarsBuilder b) => b..first = const _i1.AbsentValue(); - _i1.Value? get first; + _i1.Value get first; Map toJson() => (_i2.serializers.serializeWith( GHeroWithFragmentsVars.serializer, this, diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.g.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.g.dart index d5f4e880..e62c80dc 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/hero_with_fragments.var.gql.g.dart @@ -8,13 +8,16 @@ part of 'hero_with_fragments.var.gql.dart'; class _$GHeroWithFragmentsVars extends GHeroWithFragmentsVars { @override - final _i1.Value? first; + final _i1.Value first; factory _$GHeroWithFragmentsVars( [void Function(GHeroWithFragmentsVarsBuilder)? updates]) => (new GHeroWithFragmentsVarsBuilder()..update(updates))._build(); - _$GHeroWithFragmentsVars._({this.first}) : super._(); + _$GHeroWithFragmentsVars._({required this.first}) : super._() { + BuiltValueNullFieldError.checkNotNull( + first, r'GHeroWithFragmentsVars', 'first'); + } @override GHeroWithFragmentsVars rebuild( @@ -83,7 +86,10 @@ class GHeroWithFragmentsVarsBuilder GHeroWithFragmentsVars build() => _build(); _$GHeroWithFragmentsVars _build() { - final _$result = _$v ?? new _$GHeroWithFragmentsVars._(first: first); + final _$result = _$v ?? + new _$GHeroWithFragmentsVars._( + first: BuiltValueNullFieldError.checkNotNull( + first, r'GHeroWithFragmentsVars', 'first')); replace(_$result); return _$result; } diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.dart index 255e3ac0..78637683 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.dart @@ -21,7 +21,7 @@ abstract class GHeroWith2FragmentsVars static void _initializeBuilder(GHeroWith2FragmentsVarsBuilder b) => b..first = const _i1.AbsentValue(); - _i1.Value? get first; + _i1.Value get first; Map toJson() => (_i2.serializers.serializeWith( GHeroWith2FragmentsVars.serializer, this, diff --git a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.g.dart b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.g.dart index 24362a11..abe0a438 100644 --- a/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/fragments/__generated__/multiple_fragments.var.gql.g.dart @@ -8,13 +8,16 @@ part of 'multiple_fragments.var.gql.dart'; class _$GHeroWith2FragmentsVars extends GHeroWith2FragmentsVars { @override - final _i1.Value? first; + final _i1.Value first; factory _$GHeroWith2FragmentsVars( [void Function(GHeroWith2FragmentsVarsBuilder)? updates]) => (new GHeroWith2FragmentsVarsBuilder()..update(updates))._build(); - _$GHeroWith2FragmentsVars._({this.first}) : super._(); + _$GHeroWith2FragmentsVars._({required this.first}) : super._() { + BuiltValueNullFieldError.checkNotNull( + first, r'GHeroWith2FragmentsVars', 'first'); + } @override GHeroWith2FragmentsVars rebuild( @@ -84,7 +87,10 @@ class GHeroWith2FragmentsVarsBuilder GHeroWith2FragmentsVars build() => _build(); _$GHeroWith2FragmentsVars _build() { - final _$result = _$v ?? new _$GHeroWith2FragmentsVars._(first: first); + final _$result = _$v ?? + new _$GHeroWith2FragmentsVars._( + first: BuiltValueNullFieldError.checkNotNull( + first, r'GHeroWith2FragmentsVars', 'first')); replace(_$result); return _$result; } diff --git a/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.dart b/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.dart index f89aece8..dba14ab1 100644 --- a/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.dart @@ -55,10 +55,15 @@ abstract class GReviewInput factory GReviewInput([Function(GReviewInputBuilder b) updates]) = _$GReviewInput; + static void _initializeBuilder(GReviewInputBuilder b) => b + ..commentary = const _i1.AbsentValue() + ..favorite_color = const _i1.AbsentValue() + ..seenOn = const _i1.AbsentValue(); + int get stars; - _i1.Value? get commentary; - _i1.Value? get favorite_color; - _i1.Value>? get seenOn; + _i1.Value get commentary; + _i1.Value get favorite_color; + _i1.Value> get seenOn; Map toJson() => (_i3.serializers.serializeWith( GReviewInput.serializer, this, @@ -156,8 +161,11 @@ abstract class GCustomFieldInput factory GCustomFieldInput([Function(GCustomFieldInputBuilder b) updates]) = _$GCustomFieldInput; + static void _initializeBuilder(GCustomFieldInputBuilder b) => + b..customField = const _i1.AbsentValue(); + String get id; - _i1.Value<_i2.CustomField>? get customField; + _i1.Value<_i2.CustomField> get customField; Map toJson() => (_i3.serializers.serializeWith( GCustomFieldInput.serializer, this, diff --git a/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.g.dart b/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.g.dart index 0b62d7aa..8368dc16 100644 --- a/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/graphql/__generated__/schema.schema.gql.g.dart @@ -99,19 +99,27 @@ class _$GReviewInput extends GReviewInput { @override final int stars; @override - final _i1.Value? commentary; + final _i1.Value commentary; @override - final _i1.Value? favorite_color; + final _i1.Value favorite_color; @override - final _i1.Value>? seenOn; + final _i1.Value> seenOn; factory _$GReviewInput([void Function(GReviewInputBuilder)? updates]) => (new GReviewInputBuilder()..update(updates))._build(); _$GReviewInput._( - {required this.stars, this.commentary, this.favorite_color, this.seenOn}) + {required this.stars, + required this.commentary, + required this.favorite_color, + required this.seenOn}) : super._() { BuiltValueNullFieldError.checkNotNull(stars, r'GReviewInput', 'stars'); + BuiltValueNullFieldError.checkNotNull( + commentary, r'GReviewInput', 'commentary'); + BuiltValueNullFieldError.checkNotNull( + favorite_color, r'GReviewInput', 'favorite_color'); + BuiltValueNullFieldError.checkNotNull(seenOn, r'GReviewInput', 'seenOn'); } @override @@ -176,7 +184,9 @@ class GReviewInputBuilder set seenOn(_i1.Value>? seenOn) => _$this._seenOn = seenOn; - GReviewInputBuilder(); + GReviewInputBuilder() { + GReviewInput._initializeBuilder(this); + } GReviewInputBuilder get _$this { final $v = _$v; @@ -209,9 +219,12 @@ class GReviewInputBuilder new _$GReviewInput._( stars: BuiltValueNullFieldError.checkNotNull( stars, r'GReviewInput', 'stars'), - commentary: commentary, - favorite_color: favorite_color, - seenOn: seenOn); + commentary: BuiltValueNullFieldError.checkNotNull( + commentary, r'GReviewInput', 'commentary'), + favorite_color: BuiltValueNullFieldError.checkNotNull( + favorite_color, r'GReviewInput', 'favorite_color'), + seenOn: BuiltValueNullFieldError.checkNotNull( + seenOn, r'GReviewInput', 'seenOn')); replace(_$result); return _$result; } @@ -221,14 +234,17 @@ class _$GCustomFieldInput extends GCustomFieldInput { @override final String id; @override - final _i1.Value<_i2.CustomField>? customField; + final _i1.Value<_i2.CustomField> customField; factory _$GCustomFieldInput( [void Function(GCustomFieldInputBuilder)? updates]) => (new GCustomFieldInputBuilder()..update(updates))._build(); - _$GCustomFieldInput._({required this.id, this.customField}) : super._() { + _$GCustomFieldInput._({required this.id, required this.customField}) + : super._() { BuiltValueNullFieldError.checkNotNull(id, r'GCustomFieldInput', 'id'); + BuiltValueNullFieldError.checkNotNull( + customField, r'GCustomFieldInput', 'customField'); } @override @@ -278,7 +294,9 @@ class GCustomFieldInputBuilder set customField(_i1.Value<_i2.CustomField>? customField) => _$this._customField = customField; - GCustomFieldInputBuilder(); + GCustomFieldInputBuilder() { + GCustomFieldInput._initializeBuilder(this); + } GCustomFieldInputBuilder get _$this { final $v = _$v; @@ -309,7 +327,8 @@ class GCustomFieldInputBuilder new _$GCustomFieldInput._( id: BuiltValueNullFieldError.checkNotNull( id, r'GCustomFieldInput', 'id'), - customField: customField); + customField: BuiltValueNullFieldError.checkNotNull( + customField, r'GCustomFieldInput', 'customField')); replace(_$result); return _$result; } diff --git a/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.dart b/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.dart index 71d7cc57..0445a4b1 100644 --- a/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.dart @@ -23,9 +23,9 @@ abstract class GReviewWithDateVars ..episode = const _i1.AbsentValue() ..createdAt = const _i1.AbsentValue(); - _i1.Value<_i2.GEpisode>? get episode; + _i1.Value<_i2.GEpisode> get episode; _i2.GReviewInput get review; - _i1.Value? get createdAt; + _i1.Value get createdAt; Map toJson() => (_i3.serializers.serializeWith( GReviewWithDateVars.serializer, this, diff --git a/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.g.dart b/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.g.dart index 0bedf48c..9f613f7a 100644 --- a/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/scalars/__generated__/review_with_date.var.gql.g.dart @@ -8,20 +8,25 @@ part of 'review_with_date.var.gql.dart'; class _$GReviewWithDateVars extends GReviewWithDateVars { @override - final _i1.Value<_i2.GEpisode>? episode; + final _i1.Value<_i2.GEpisode> episode; @override final _i2.GReviewInput review; @override - final _i1.Value? createdAt; + final _i1.Value createdAt; factory _$GReviewWithDateVars( [void Function(GReviewWithDateVarsBuilder)? updates]) => (new GReviewWithDateVarsBuilder()..update(updates))._build(); - _$GReviewWithDateVars._({this.episode, required this.review, this.createdAt}) + _$GReviewWithDateVars._( + {required this.episode, required this.review, required this.createdAt}) : super._() { + BuiltValueNullFieldError.checkNotNull( + episode, r'GReviewWithDateVars', 'episode'); BuiltValueNullFieldError.checkNotNull( review, r'GReviewWithDateVars', 'review'); + BuiltValueNullFieldError.checkNotNull( + createdAt, r'GReviewWithDateVars', 'createdAt'); } @override @@ -114,7 +119,11 @@ class GReviewWithDateVarsBuilder try { _$result = _$v ?? new _$GReviewWithDateVars._( - episode: episode, review: review.build(), createdAt: createdAt); + episode: BuiltValueNullFieldError.checkNotNull( + episode, r'GReviewWithDateVars', 'episode'), + review: review.build(), + createdAt: BuiltValueNullFieldError.checkNotNull( + createdAt, r'GReviewWithDateVars', 'createdAt')); } catch (_) { late String _$failedField; try { diff --git a/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.dart b/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.dart index ec863bc3..26f14312 100644 --- a/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.dart +++ b/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.dart @@ -22,7 +22,7 @@ abstract class GCreateReviewVars static void _initializeBuilder(GCreateReviewVarsBuilder b) => b..episode = const _i1.AbsentValue(); - _i1.Value<_i2.GEpisode>? get episode; + _i1.Value<_i2.GEpisode> get episode; _i2.GReviewInput get review; Map toJson() => (_i3.serializers.serializeWith( GCreateReviewVars.serializer, diff --git a/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.g.dart b/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.g.dart index da074bea..204891fa 100644 --- a/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.g.dart +++ b/codegen/end_to_end_test_tristate/lib/variables/__generated__/create_review.var.gql.g.dart @@ -8,7 +8,7 @@ part of 'create_review.var.gql.dart'; class _$GCreateReviewVars extends GCreateReviewVars { @override - final _i1.Value<_i2.GEpisode>? episode; + final _i1.Value<_i2.GEpisode> episode; @override final _i2.GReviewInput review; @@ -16,7 +16,10 @@ class _$GCreateReviewVars extends GCreateReviewVars { [void Function(GCreateReviewVarsBuilder)? updates]) => (new GCreateReviewVarsBuilder()..update(updates))._build(); - _$GCreateReviewVars._({this.episode, required this.review}) : super._() { + _$GCreateReviewVars._({required this.episode, required this.review}) + : super._() { + BuiltValueNullFieldError.checkNotNull( + episode, r'GCreateReviewVars', 'episode'); BuiltValueNullFieldError.checkNotNull( review, r'GCreateReviewVars', 'review'); } @@ -100,7 +103,10 @@ class GCreateReviewVarsBuilder _$GCreateReviewVars _$result; try { _$result = _$v ?? - new _$GCreateReviewVars._(episode: episode, review: review.build()); + new _$GCreateReviewVars._( + episode: BuiltValueNullFieldError.checkNotNull( + episode, r'GCreateReviewVars', 'episode'), + review: review.build()); } catch (_) { late String _$failedField; try { diff --git a/codegen/end_to_end_test_tristate/test/schema/scalars_test.dart b/codegen/end_to_end_test_tristate/test/schema/scalars_test.dart index 91fd3c16..7a928f64 100644 --- a/codegen/end_to_end_test_tristate/test/schema/scalars_test.dart +++ b/codegen/end_to_end_test_tristate/test/schema/scalars_test.dart @@ -63,7 +63,7 @@ void main() { BuiltList([DateTime.fromMillisecondsSinceEpoch(1591892597000)]), )); test('correctly overrides scalars in input types', () { - expect((input.seenOn! as PresentValue).value!.first, + expect((input.seenOn as PresentValue).value!.first, TypeMatcher()); }); @@ -86,7 +86,7 @@ void main() { ); test('correctly overrides scalars in variable types', () { - expect((vars.createdAt! as PresentValue).value, TypeMatcher()); + expect((vars.createdAt as PresentValue).value, TypeMatcher()); }); test('can be serialized and deserialized with custom serializer', () { diff --git a/codegen/gql_code_builder/CHANGELOG.md b/codegen/gql_code_builder/CHANGELOG.md index e58356ea..3880ece7 100644 --- a/codegen/gql_code_builder/CHANGELOG.md +++ b/codegen/gql_code_builder/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.1+1 + +- fix generating the `Value` wrappers as nullable + ## 0.9.0 - add TriStateValueConfig option in order to wrap nullable fields in input types in a `Value` class in order distinguish between three cases: diff --git a/codegen/gql_code_builder/lib/src/common.dart b/codegen/gql_code_builder/lib/src/common.dart index 890fb2a7..8f942131 100644 --- a/codegen/gql_code_builder/lib/src/common.dart +++ b/codegen/gql_code_builder/lib/src/common.dart @@ -213,7 +213,7 @@ Method buildOptionalGetter({ final optionalGetter = baseGetter.rebuild((b) => b ..returns = TypeReference((b2) => b2 - ..isNullable = true + ..isNullable = false ..url = valueTypeUrl ..symbol = valueTypeSymbol ..types.add((baseGetter.returns as TypeReference) diff --git a/codegen/gql_code_builder/lib/src/schema/input.dart b/codegen/gql_code_builder/lib/src/schema/input.dart index 1a73f099..e0516444 100644 --- a/codegen/gql_code_builder/lib/src/schema/input.dart +++ b/codegen/gql_code_builder/lib/src/schema/input.dart @@ -46,8 +46,19 @@ Class buildInputClass( ), hasCustomSerializer: triStateValueConfig == TriStateValueConfig.onAllNullableFields, + initializers: { + if (triStateValueConfig == TriStateValueConfig.onAllNullableFields) + ..._inputClassValueInitializers(node) + }, methods: [ if (triStateValueConfig == TriStateValueConfig.onAllNullableFields) nullAwareJsonSerializerField(node, "G${node.name.value}"), ], ); + +Map _inputClassValueInitializers( + InputObjectTypeDefinitionNode op) => + { + for (final node in op.fields.where((element) => !element.type.isNonNull)) + identifier(node.name.value): absentValueConstructorInvocation() + }; diff --git a/codegen/gql_code_builder/pubspec.yaml b/codegen/gql_code_builder/pubspec.yaml index 88c5458d..6935aa83 100644 --- a/codegen/gql_code_builder/pubspec.yaml +++ b/codegen/gql_code_builder/pubspec.yaml @@ -1,5 +1,5 @@ name: gql_code_builder -version: 0.9.1 +version: 0.9.1+1 description: Dart code builders taking *.graphql documents and SDL to build useful classes. repository: https://github.com/gql-dart/gql environment: