Skip to content

[gql_code_builder] #fix: tristate optionals originalSymbolName #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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