Skip to content

Commit

Permalink
fix: tristate_optionals - defining originalSymbolName
Browse files Browse the repository at this point in the history
  • Loading branch information
LiLatee committed Feb 19, 2024
1 parent dee7eed commit 7122382
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 56 deletions.
34 changes: 24 additions & 10 deletions codegen/end_to_end_test_tristate/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,36 @@ targets:
options:
schema: end_to_end_test_tristate|lib/graphql/schema.graphql
custom_serializers:
- import: 'package:end_to_end_test_tristate/date_serializer.dart'
- import: "package:end_to_end_test_tristate/date_serializer.dart"
name: DateSerializer
- import: 'package:end_to_end_test_tristate/custom_field_serializer.dart'
- import: "package:end_to_end_test_tristate/custom_field_serializer.dart"
name: CustomFieldSerializer
- import: "package:end_to_end_test_tristate/custom_date_serializer.dart"
name: CustomDateSerializer
type_overrides:
Date:
DateTime:
name: DateTime
CustomField:
name: CustomField
import: 'package:end_to_end_test_tristate/custom_field.dart'
import: "package:end_to_end_test_tristate/custom_field.dart"
Date:
name: CustomDate
import: "package:end_to_end_test_tristate/custom_date.dart"
gql_build|schema_builder:
enabled: true
options:
tristate_optionals: true
enum_fallbacks:
LengthUnit: METER
type_overrides:
Date:
DateTime:
name: DateTime
CustomField:
name: CustomField
import: 'package:end_to_end_test_tristate/custom_field.dart'
import: "package:end_to_end_test_tristate/custom_field.dart"
Date:
name: CustomDate
import: "package:end_to_end_test_tristate/custom_date.dart"
gql_build|data_builder:
enabled: true
options:
Expand All @@ -42,20 +50,26 @@ targets:
when: true
maybeWhen: true
type_overrides:
Date:
DateTime:
name: DateTime
CustomField:
name: CustomField
import: 'package:end_to_end_test_tristate/custom_field.dart'
import: "package:end_to_end_test_tristate/custom_field.dart"
Date:
name: CustomDate
import: "package:end_to_end_test_tristate/custom_date.dart"
gql_build|var_builder:
enabled: true
options:
schema: end_to_end_test_tristate|lib/graphql/schema.graphql
tristate_optionals: true
vars_create_factories: true
type_overrides:
Date:
DateTime:
name: DateTime
CustomField:
name: CustomField
import: 'package:end_to_end_test_tristate/custom_field.dart'
import: "package:end_to_end_test_tristate/custom_field.dart"
Date:
name: CustomDate
import: "package:end_to_end_test_tristate/custom_date.dart"
19 changes: 19 additions & 0 deletions codegen/end_to_end_test_tristate/lib/custom_date.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class CustomDate extends DateTime {
CustomDate(
super.year,
super.month,
super.day,
);

static CustomDate parse(String formattedString) {
final DateTime dateTime = DateTime.parse(formattedString);
return CustomDate(dateTime.year, dateTime.month, dateTime.day);
}

@override
CustomDate toLocal() {
final DateTime localDateTime = super.toLocal();
return CustomDate(
localDateTime.year, localDateTime.month, localDateTime.day);
}
}
30 changes: 30 additions & 0 deletions codegen/end_to_end_test_tristate/lib/custom_date_serializer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:built_value/serializer.dart';
import 'package:end_to_end_test_tristate/custom_date.dart';

class CustomDateSerializer implements PrimitiveSerializer<CustomDate> {
@override
CustomDate deserialize(
Serializers serializers,
Object serialized, {
FullType specifiedType = FullType.unspecified,
}) {
assert(serialized is String,
"CustomDateSerializer expected 'String' but got ${serialized.runtimeType}");
return CustomDate.parse(serialized as String).toLocal();
}

@override
String serialize(
Serializers serializers,
CustomDate date, {
FullType specifiedType = FullType.unspecified,
}) {
return date.toUtc().toIso8601String().split('T').first;
}

@override
Iterable<Type> get types => [CustomDate];

@override
String get wireName => 'Date';
}

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.

Loading

0 comments on commit 7122382

Please sign in to comment.