Skip to content

Commit 2c86505

Browse files
authored
feat(fdc): Update with builder notation (#13434)
1 parent e2993b0 commit 2c86505

24 files changed

Lines changed: 242 additions & 263 deletions

packages/firebase_data_connect/analysis_options.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
include: all_lint_rules.yaml
66
analyzer:
77
exclude:
8-
- firebase_data_connect/lib/src/generated/**
98
# TODO(rrousselGit): disable implicit-cast/implicit-dynamic
109
errors:
1110
# Otherwise cause the import of all_lint_rules to warn because of some rules conflicts.

packages/firebase_data_connect/firebase_data_connect/example/integration_test/generation_e2e.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ void runGenerationTest() {
3030

3131
testWidgets('should have generated correct MutationRef',
3232
(WidgetTester tester) async {
33-
final ref = MoviesConnector.instance.createMovie.ref(
34-
genre: 'Action',
35-
title: 'The Matrix',
36-
releaseYear: 1999,
37-
rating: 4.5,
38-
);
33+
final ref = MoviesConnector.instance.createMovie
34+
.ref(
35+
genre: 'Action',
36+
title: 'The Matrix',
37+
releaseYear: 1999,
38+
)
39+
.rating(4.5);
3940
expect(ref, isNotNull);
4041
expect(ref.build().execute, isNotNull);
4142
});
@@ -49,19 +50,18 @@ void runGenerationTest() {
4950

5051
testWidgets('should have generated correct MutationRef using name',
5152
(WidgetTester tester) async {
52-
final ref = MoviesConnector.instance.addPerson.ref(
53-
name: 'Keanu Reeves',
54-
);
53+
final ref =
54+
MoviesConnector.instance.addPerson.ref().name('Keanu Reeves');
5555
expect(ref, isNotNull);
5656
expect(ref.build().execute, isNotNull);
5757
});
5858

5959
testWidgets('should have generated correct MutationRef using nested id',
6060
(WidgetTester tester) async {
61-
final ref = MoviesConnector.instance.addDirectorToMovie.ref(
62-
movieId: 'movieId',
63-
personId: AddDirectorToMovieVariablesPersonId(id: 'personId'),
64-
);
61+
final ref = MoviesConnector.instance.addDirectorToMovie
62+
.ref()
63+
.movieId('movieId')
64+
.personId(AddDirectorToMovieVariablesPersonId(id: 'personId'));
6565
expect(ref, isNotNull);
6666
expect(ref.build().execute, isNotNull);
6767
});

packages/firebase_data_connect/firebase_data_connect/example/integration_test/listen_e2e.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ void runListenTests() {
5959
genre: 'Action',
6060
title: 'The Matrix',
6161
releaseYear: 1999,
62-
rating: 4.5,
6362
)
63+
.rating(4.5)
6464
.build()
6565
.execute();
6666

packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ void runQueryTests() {
4040
genre: 'Action',
4141
title: 'The Matrix',
4242
releaseYear: 1999,
43-
rating: 4.5,
4443
)
44+
.rating(4.5)
4545
.build();
4646

4747
await ref.execute();
@@ -55,9 +55,8 @@ void runQueryTests() {
5555

5656
testWidgets('can add a director to a movie', (WidgetTester tester) async {
5757
MutationRef ref = MoviesConnector.instance.addPerson
58-
.ref(
59-
name: 'Keanu Reeves',
60-
)
58+
.ref()
59+
.name('Keanu Reeves')
6160
.build();
6261

6362
await ref.execute();
@@ -78,8 +77,8 @@ void runQueryTests() {
7877
genre: 'Action',
7978
title: 'The Matrix',
8079
releaseYear: 1999,
81-
rating: 4.5,
8280
)
81+
.rating(4.5)
8382
.build();
8483

8584
await ref.execute();
@@ -92,10 +91,9 @@ void runQueryTests() {
9291
final movieId = result2.movies[0].id;
9392

9493
ref = MoviesConnector.instance.addDirectorToMovie
95-
.ref(
96-
movieId: movieId,
97-
personId: AddDirectorToMovieVariablesPersonId(id: personId),
98-
)
94+
.ref()
95+
.movieId(movieId)
96+
.personId(AddDirectorToMovieVariablesPersonId(id: personId))
9997
.build();
10098

10199
await ref.execute();
@@ -114,8 +112,8 @@ void runQueryTests() {
114112
genre: 'Action',
115113
title: 'The Matrix',
116114
releaseYear: 1999,
117-
rating: 4.5,
118115
)
116+
.rating(4.5)
119117
.build();
120118

121119
await ref.execute();

packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_date_and_timestamp.dart

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@ class AddDateAndTimestampVariablesBuilder {
44
DateTime date;
55
Timestamp timestamp;
66

7-
FirebaseDataConnect dataConnect;
7+
FirebaseDataConnect _dataConnect;
88

99
AddDateAndTimestampVariablesBuilder(
10-
this.dataConnect, {
10+
this._dataConnect, {
1111
required DateTime this.date,
1212
required Timestamp this.timestamp,
1313
});
14-
Deserializer<AddDateAndTimestampData> dataDeserializer = (String json) =>
15-
AddDateAndTimestampData.fromJson(
16-
jsonDecode(json) as Map<String, dynamic>);
14+
Deserializer<AddDateAndTimestampData> dataDeserializer =
15+
(dynamic json) => AddDateAndTimestampData.fromJson(jsonDecode(json));
1716
Serializer<AddDateAndTimestampVariables> varsSerializer =
1817
(AddDateAndTimestampVariables vars) => jsonEncode(vars.toJson());
1918
MutationRef<AddDateAndTimestampData, AddDateAndTimestampVariables> build() {
@@ -22,7 +21,7 @@ class AddDateAndTimestampVariablesBuilder {
2221
timestamp: timestamp,
2322
);
2423

25-
return dataConnect.mutation(
24+
return _dataConnect.mutation(
2625
"addDateAndTimestamp", dataDeserializer, varsSerializer, vars);
2726
}
2827
}
@@ -47,8 +46,7 @@ class AddDateAndTimestamp {
4746
class AddDateAndTimestampTimestampHolderInsert {
4847
String id;
4948

50-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
51-
AddDateAndTimestampTimestampHolderInsert.fromJson(Map<String, dynamic> json)
49+
AddDateAndTimestampTimestampHolderInsert.fromJson(dynamic json)
5250
: id = nativeFromJson<String>(json['id']) {}
5351

5452
Map<String, dynamic> toJson() {
@@ -67,8 +65,7 @@ class AddDateAndTimestampTimestampHolderInsert {
6765
class AddDateAndTimestampData {
6866
AddDateAndTimestampTimestampHolderInsert timestampHolder_insert;
6967

70-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
71-
AddDateAndTimestampData.fromJson(Map<String, dynamic> json)
68+
AddDateAndTimestampData.fromJson(dynamic json)
7269
: timestampHolder_insert =
7370
AddDateAndTimestampTimestampHolderInsert.fromJson(
7471
json['timestampHolder_insert']) {}
@@ -91,7 +88,6 @@ class AddDateAndTimestampVariables {
9188

9289
Timestamp timestamp;
9390

94-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
9591
AddDateAndTimestampVariables.fromJson(Map<String, dynamic> json)
9692
: date = nativeFromJson<DateTime>(json['date']),
9793
timestamp = Timestamp.fromJson(json['timestamp']) {}

packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
11
part of movies;
22

33
class AddDirectorToMovieVariablesBuilder {
4-
AddDirectorToMovieVariablesPersonId? personId;
5-
String? movieId;
4+
Optional<AddDirectorToMovieVariablesPersonId> _personId = Optional.optional(
5+
AddDirectorToMovieVariablesPersonId.fromJson, defaultSerializer);
6+
Optional<String> _movieId = Optional.optional(nativeFromJson, nativeToJson);
7+
8+
FirebaseDataConnect _dataConnect;
9+
AddDirectorToMovieVariablesBuilder personId(
10+
AddDirectorToMovieVariablesPersonId? t) {
11+
this._personId.value = t;
12+
return this;
13+
}
614

7-
FirebaseDataConnect dataConnect;
15+
AddDirectorToMovieVariablesBuilder movieId(String? t) {
16+
this._movieId.value = t;
17+
return this;
18+
}
819

920
AddDirectorToMovieVariablesBuilder(
10-
this.dataConnect, {
11-
AddDirectorToMovieVariablesPersonId? this.personId,
12-
String? this.movieId,
13-
});
14-
Deserializer<AddDirectorToMovieData> dataDeserializer = (String json) =>
15-
AddDirectorToMovieData.fromJson(jsonDecode(json) as Map<String, dynamic>);
21+
this._dataConnect,
22+
);
23+
Deserializer<AddDirectorToMovieData> dataDeserializer =
24+
(dynamic json) => AddDirectorToMovieData.fromJson(jsonDecode(json));
1625
Serializer<AddDirectorToMovieVariables> varsSerializer =
1726
(AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson());
1827
MutationRef<AddDirectorToMovieData, AddDirectorToMovieVariables> build() {
1928
AddDirectorToMovieVariables vars = AddDirectorToMovieVariables(
20-
personId: personId,
21-
movieId: movieId,
29+
personId: _personId,
30+
movieId: _movieId,
2231
);
2332

24-
return dataConnect.mutation(
33+
return _dataConnect.mutation(
2534
"addDirectorToMovie", dataDeserializer, varsSerializer, vars);
2635
}
2736
}
2837

2938
class AddDirectorToMovie {
3039
String name = "addDirectorToMovie";
3140
AddDirectorToMovie({required this.dataConnect});
32-
AddDirectorToMovieVariablesBuilder ref({
33-
AddDirectorToMovieVariablesPersonId? personId,
34-
String? movieId,
35-
}) {
41+
AddDirectorToMovieVariablesBuilder ref() {
3642
return AddDirectorToMovieVariablesBuilder(
3743
dataConnect,
38-
personId: personId,
39-
movieId: movieId,
4044
);
4145
}
4246

@@ -48,8 +52,7 @@ class AddDirectorToMovieDirectedByInsert {
4852

4953
String movieId;
5054

51-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
52-
AddDirectorToMovieDirectedByInsert.fromJson(Map<String, dynamic> json)
55+
AddDirectorToMovieDirectedByInsert.fromJson(dynamic json)
5356
: directedbyId = nativeFromJson<String>(json['directedbyId']),
5457
movieId = nativeFromJson<String>(json['movieId']) {}
5558

@@ -72,8 +75,7 @@ class AddDirectorToMovieDirectedByInsert {
7275
class AddDirectorToMovieData {
7376
AddDirectorToMovieDirectedByInsert directedBy_insert;
7477

75-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
76-
AddDirectorToMovieData.fromJson(Map<String, dynamic> json)
78+
AddDirectorToMovieData.fromJson(dynamic json)
7779
: directedBy_insert = AddDirectorToMovieDirectedByInsert.fromJson(
7880
json['directedBy_insert']) {}
7981

@@ -93,8 +95,7 @@ class AddDirectorToMovieData {
9395
class AddDirectorToMovieVariablesPersonId {
9496
String id;
9597

96-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
97-
AddDirectorToMovieVariablesPersonId.fromJson(Map<String, dynamic> json)
98+
AddDirectorToMovieVariablesPersonId.fromJson(dynamic json)
9899
: id = nativeFromJson<String>(json['id']) {}
99100

100101
Map<String, dynamic> toJson() {
@@ -111,37 +112,39 @@ class AddDirectorToMovieVariablesPersonId {
111112
}
112113

113114
class AddDirectorToMovieVariables {
114-
AddDirectorToMovieVariablesPersonId? personId;
115+
late Optional<AddDirectorToMovieVariablesPersonId> personId;
115116

116-
String? movieId;
117+
late Optional<String> movieId;
117118

118-
// TODO(mtewani): Check what happens when an optional field is retrieved from json.
119119
AddDirectorToMovieVariables.fromJson(Map<String, dynamic> json) {
120-
personId = json['personId'] == null
120+
personId = Optional.optional(
121+
AddDirectorToMovieVariablesPersonId.fromJson, defaultSerializer);
122+
personId.value = json['personId'] == null
121123
? null
122124
: AddDirectorToMovieVariablesPersonId.fromJson(json['personId']);
123125

124-
movieId = json['movieId'] == null
126+
movieId = Optional.optional(nativeFromJson, nativeToJson);
127+
movieId.value = json['movieId'] == null
125128
? null
126129
: nativeFromJson<String>(json['movieId']);
127130
}
128131

129132
Map<String, dynamic> toJson() {
130133
Map<String, dynamic> json = {};
131134

132-
if (personId != null) {
133-
json['personId'] = personId!.toJson();
135+
if (personId.state == OptionalState.set) {
136+
json['personId'] = personId.toJson();
134137
}
135138

136-
if (movieId != null) {
137-
json['movieId'] = nativeToJson<String?>(movieId);
139+
if (movieId.state == OptionalState.set) {
140+
json['movieId'] = movieId.toJson();
138141
}
139142

140143
return json;
141144
}
142145

143146
AddDirectorToMovieVariables({
144-
this.personId,
145-
this.movieId,
147+
required this.personId,
148+
required this.movieId,
146149
});
147150
}

0 commit comments

Comments
 (0)