Skip to content

Commit

Permalink
fix: value should be non-null (#428)
Browse files Browse the repository at this point in the history
* fix: value should be non-null
  • Loading branch information
knaeckeKami authored Nov 12, 2023
1 parent 0c94411 commit add6474
Show file tree
Hide file tree
Showing 15 changed files with 112 additions and 41 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void main() {
BuiltList([DateTime.fromMillisecondsSinceEpoch(1591892597000)]),
));
test('correctly overrides scalars in input types', () {
expect((input.seenOn! as PresentValue<BuiltList>).value!.first,
expect((input.seenOn as PresentValue<BuiltList>).value!.first,
TypeMatcher<DateTime>());
});

Expand All @@ -86,7 +86,7 @@ void main() {
);

test('correctly overrides scalars in variable types', () {
expect((vars.createdAt! as PresentValue).value, TypeMatcher<DateTime>());
expect((vars.createdAt as PresentValue).value, TypeMatcher<DateTime>());
});

test('can be serialized and deserialized with custom serializer', () {
Expand Down
2 changes: 1 addition & 1 deletion codegen/gql_code_builder/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions codegen/gql_code_builder/lib/src/schema/input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Expression> _inputClassValueInitializers(
InputObjectTypeDefinitionNode op) =>
{
for (final node in op.fields.where((element) => !element.type.isNonNull))
identifier(node.name.value): absentValueConstructorInvocation()
};

0 comments on commit add6474

Please sign in to comment.