Skip to content

Commit

Permalink
feat(fdc): Update with builder notation (#13434)
Browse files Browse the repository at this point in the history
  • Loading branch information
maneesht authored Oct 2, 2024
1 parent e2993b0 commit 2c86505
Show file tree
Hide file tree
Showing 24 changed files with 242 additions and 263 deletions.
1 change: 0 additions & 1 deletion packages/firebase_data_connect/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
include: all_lint_rules.yaml
analyzer:
exclude:
- firebase_data_connect/lib/src/generated/**
# TODO(rrousselGit): disable implicit-cast/implicit-dynamic
errors:
# Otherwise cause the import of all_lint_rules to warn because of some rules conflicts.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ void runGenerationTest() {

testWidgets('should have generated correct MutationRef',
(WidgetTester tester) async {
final ref = MoviesConnector.instance.createMovie.ref(
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
);
final ref = MoviesConnector.instance.createMovie
.ref(
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
)
.rating(4.5);
expect(ref, isNotNull);
expect(ref.build().execute, isNotNull);
});
Expand All @@ -49,19 +50,18 @@ void runGenerationTest() {

testWidgets('should have generated correct MutationRef using name',
(WidgetTester tester) async {
final ref = MoviesConnector.instance.addPerson.ref(
name: 'Keanu Reeves',
);
final ref =
MoviesConnector.instance.addPerson.ref().name('Keanu Reeves');
expect(ref, isNotNull);
expect(ref.build().execute, isNotNull);
});

testWidgets('should have generated correct MutationRef using nested id',
(WidgetTester tester) async {
final ref = MoviesConnector.instance.addDirectorToMovie.ref(
movieId: 'movieId',
personId: AddDirectorToMovieVariablesPersonId(id: 'personId'),
);
final ref = MoviesConnector.instance.addDirectorToMovie
.ref()
.movieId('movieId')
.personId(AddDirectorToMovieVariablesPersonId(id: 'personId'));
expect(ref, isNotNull);
expect(ref.build().execute, isNotNull);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ void runListenTests() {
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
)
.rating(4.5)
.build()
.execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void runQueryTests() {
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
)
.rating(4.5)
.build();

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

testWidgets('can add a director to a movie', (WidgetTester tester) async {
MutationRef ref = MoviesConnector.instance.addPerson
.ref(
name: 'Keanu Reeves',
)
.ref()
.name('Keanu Reeves')
.build();

await ref.execute();
Expand All @@ -78,8 +77,8 @@ void runQueryTests() {
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
)
.rating(4.5)
.build();

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

ref = MoviesConnector.instance.addDirectorToMovie
.ref(
movieId: movieId,
personId: AddDirectorToMovieVariablesPersonId(id: personId),
)
.ref()
.movieId(movieId)
.personId(AddDirectorToMovieVariablesPersonId(id: personId))
.build();

await ref.execute();
Expand All @@ -114,8 +112,8 @@ void runQueryTests() {
genre: 'Action',
title: 'The Matrix',
releaseYear: 1999,
rating: 4.5,
)
.rating(4.5)
.build();

await ref.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ class AddDateAndTimestampVariablesBuilder {
DateTime date;
Timestamp timestamp;

FirebaseDataConnect dataConnect;
FirebaseDataConnect _dataConnect;

AddDateAndTimestampVariablesBuilder(
this.dataConnect, {
this._dataConnect, {
required DateTime this.date,
required Timestamp this.timestamp,
});
Deserializer<AddDateAndTimestampData> dataDeserializer = (String json) =>
AddDateAndTimestampData.fromJson(
jsonDecode(json) as Map<String, dynamic>);
Deserializer<AddDateAndTimestampData> dataDeserializer =
(dynamic json) => AddDateAndTimestampData.fromJson(jsonDecode(json));
Serializer<AddDateAndTimestampVariables> varsSerializer =
(AddDateAndTimestampVariables vars) => jsonEncode(vars.toJson());
MutationRef<AddDateAndTimestampData, AddDateAndTimestampVariables> build() {
Expand All @@ -22,7 +21,7 @@ class AddDateAndTimestampVariablesBuilder {
timestamp: timestamp,
);

return dataConnect.mutation(
return _dataConnect.mutation(
"addDateAndTimestamp", dataDeserializer, varsSerializer, vars);
}
}
Expand All @@ -47,8 +46,7 @@ class AddDateAndTimestamp {
class AddDateAndTimestampTimestampHolderInsert {
String id;

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

Map<String, dynamic> toJson() {
Expand All @@ -67,8 +65,7 @@ class AddDateAndTimestampTimestampHolderInsert {
class AddDateAndTimestampData {
AddDateAndTimestampTimestampHolderInsert timestampHolder_insert;

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

Timestamp timestamp;

// TODO(mtewani): Check what happens when an optional field is retrieved from json.
AddDateAndTimestampVariables.fromJson(Map<String, dynamic> json)
: date = nativeFromJson<DateTime>(json['date']),
timestamp = Timestamp.fromJson(json['timestamp']) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
part of movies;

class AddDirectorToMovieVariablesBuilder {
AddDirectorToMovieVariablesPersonId? personId;
String? movieId;
Optional<AddDirectorToMovieVariablesPersonId> _personId = Optional.optional(
AddDirectorToMovieVariablesPersonId.fromJson, defaultSerializer);
Optional<String> _movieId = Optional.optional(nativeFromJson, nativeToJson);

FirebaseDataConnect _dataConnect;
AddDirectorToMovieVariablesBuilder personId(
AddDirectorToMovieVariablesPersonId? t) {
this._personId.value = t;
return this;
}

FirebaseDataConnect dataConnect;
AddDirectorToMovieVariablesBuilder movieId(String? t) {
this._movieId.value = t;
return this;
}

AddDirectorToMovieVariablesBuilder(
this.dataConnect, {
AddDirectorToMovieVariablesPersonId? this.personId,
String? this.movieId,
});
Deserializer<AddDirectorToMovieData> dataDeserializer = (String json) =>
AddDirectorToMovieData.fromJson(jsonDecode(json) as Map<String, dynamic>);
this._dataConnect,
);
Deserializer<AddDirectorToMovieData> dataDeserializer =
(dynamic json) => AddDirectorToMovieData.fromJson(jsonDecode(json));
Serializer<AddDirectorToMovieVariables> varsSerializer =
(AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson());
MutationRef<AddDirectorToMovieData, AddDirectorToMovieVariables> build() {
AddDirectorToMovieVariables vars = AddDirectorToMovieVariables(
personId: personId,
movieId: movieId,
personId: _personId,
movieId: _movieId,
);

return dataConnect.mutation(
return _dataConnect.mutation(
"addDirectorToMovie", dataDeserializer, varsSerializer, vars);
}
}

class AddDirectorToMovie {
String name = "addDirectorToMovie";
AddDirectorToMovie({required this.dataConnect});
AddDirectorToMovieVariablesBuilder ref({
AddDirectorToMovieVariablesPersonId? personId,
String? movieId,
}) {
AddDirectorToMovieVariablesBuilder ref() {
return AddDirectorToMovieVariablesBuilder(
dataConnect,
personId: personId,
movieId: movieId,
);
}

Expand All @@ -48,8 +52,7 @@ class AddDirectorToMovieDirectedByInsert {

String movieId;

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

Expand All @@ -72,8 +75,7 @@ class AddDirectorToMovieDirectedByInsert {
class AddDirectorToMovieData {
AddDirectorToMovieDirectedByInsert directedBy_insert;

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

Expand All @@ -93,8 +95,7 @@ class AddDirectorToMovieData {
class AddDirectorToMovieVariablesPersonId {
String id;

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

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

class AddDirectorToMovieVariables {
AddDirectorToMovieVariablesPersonId? personId;
late Optional<AddDirectorToMovieVariablesPersonId> personId;

String? movieId;
late Optional<String> movieId;

// TODO(mtewani): Check what happens when an optional field is retrieved from json.
AddDirectorToMovieVariables.fromJson(Map<String, dynamic> json) {
personId = json['personId'] == null
personId = Optional.optional(
AddDirectorToMovieVariablesPersonId.fromJson, defaultSerializer);
personId.value = json['personId'] == null
? null
: AddDirectorToMovieVariablesPersonId.fromJson(json['personId']);

movieId = json['movieId'] == null
movieId = Optional.optional(nativeFromJson, nativeToJson);
movieId.value = json['movieId'] == null
? null
: nativeFromJson<String>(json['movieId']);
}

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

if (personId != null) {
json['personId'] = personId!.toJson();
if (personId.state == OptionalState.set) {
json['personId'] = personId.toJson();
}

if (movieId != null) {
json['movieId'] = nativeToJson<String?>(movieId);
if (movieId.state == OptionalState.set) {
json['movieId'] = movieId.toJson();
}

return json;
}

AddDirectorToMovieVariables({
this.personId,
this.movieId,
required this.personId,
required this.movieId,
});
}
Loading

0 comments on commit 2c86505

Please sign in to comment.