diff --git a/packages/firebase_data_connect/firebase_data_connect/example/dataconnect/connector/queries.gql b/packages/firebase_data_connect/firebase_data_connect/example/dataconnect/connector/queries.gql index c4006e2ee0b7..3c1ce8191a13 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/dataconnect/connector/queries.gql +++ b/packages/firebase_data_connect/firebase_data_connect/example/dataconnect/connector/queries.gql @@ -6,6 +6,7 @@ query ListMovies @auth(level: USER) { directed_by: people_via_DirectedBy { name } + rating } } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/generation_e2e.dart b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/generation_e2e.dart index 242acecf666d..6f6aa6afb363 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/generation_e2e.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/generation_e2e.dart @@ -37,14 +37,14 @@ void runGenerationTest() { rating: 4.5, ); expect(ref, isNotNull); - expect(ref.execute, isNotNull); + expect(ref.build().execute, isNotNull); }); testWidgets('should have generated correct QueryRef', (WidgetTester tester) async { final ref = MoviesConnector.instance.listMovies.ref(); expect(ref, isNotNull); - expect(ref.execute, isNotNull); + expect(ref.build().execute, isNotNull); }); testWidgets('should have generated correct MutationRef using name', @@ -53,7 +53,7 @@ void runGenerationTest() { name: 'Keanu Reeves', ); expect(ref, isNotNull); - expect(ref.execute, isNotNull); + expect(ref.build().execute, isNotNull); }); testWidgets('should have generated correct MutationRef using nested id', @@ -63,7 +63,7 @@ void runGenerationTest() { personId: AddDirectorToMovieVariablesPersonId(id: 'personId'), ); expect(ref, isNotNull); - expect(ref.execute, isNotNull); + expect(ref.build().execute, isNotNull); }); }, ); diff --git a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/listen_e2e.dart b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/listen_e2e.dart index a41c3668d525..9b7a96480c91 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/listen_e2e.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/listen_e2e.dart @@ -21,7 +21,7 @@ void runListenTests() { testWidgets('should be able to listen to the list of movies', (WidgetTester tester) async { final initialValue = - await MoviesConnector.instance.listMovies.ref().execute(); + await MoviesConnector.instance.listMovies.ref().build().execute(); expect(initialValue.data.movies.length, 0, reason: 'Initial movie list should be empty'); @@ -31,6 +31,7 @@ void runListenTests() { final listener = MoviesConnector.instance.listMovies .ref() + .build() .subscribe() .listen((value) { final movies = value.data.movies; @@ -60,9 +61,10 @@ void runListenTests() { releaseYear: 1999, rating: 4.5, ) + .build() .execute(); - await MoviesConnector.instance.listMovies.ref().execute(); + await MoviesConnector.instance.listMovies.ref().build().execute(); // Wait for the listener to receive the movie update final bool hasListenerReceived = await hasBeenListened.future; diff --git a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart index 55fd6e78de11..61e23e28dd5a 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/integration_test/query_e2e.dart @@ -7,10 +7,14 @@ import 'package:firebase_data_connect_example/generated/movies.dart'; import 'package:flutter_test/flutter_test.dart'; Future deleteAllMovies() async { - final value = await MoviesConnector.instance.listMovies.ref().execute(); + final value = + await MoviesConnector.instance.listMovies.ref().build().execute(); final result = value.data; for (var movie in result.movies) { - await MoviesConnector.instance.deleteMovie.ref(id: movie.id).execute(); + await MoviesConnector.instance.deleteMovie + .ref(id: movie.id) + .build() + .execute(); } } @@ -23,70 +27,81 @@ void runQueryTests() { }); testWidgets('can query', (WidgetTester tester) async { - final value = await MoviesConnector.instance.listMovies.ref().execute(); + final value = + await MoviesConnector.instance.listMovies.ref().build().execute(); final result = value.data; expect(result.movies.length, 0); }); testWidgets('can add a movie', (WidgetTester tester) async { - MutationRef ref = MoviesConnector.instance.createMovie.ref( - genre: 'Action', - title: 'The Matrix', - releaseYear: 1999, - rating: 4.5, - ); + MutationRef ref = MoviesConnector.instance.createMovie + .ref( + genre: 'Action', + title: 'The Matrix', + releaseYear: 1999, + rating: 4.5, + ) + .build(); await ref.execute(); - final value = await MoviesConnector.instance.listMovies.ref().execute(); + final value = + await MoviesConnector.instance.listMovies.ref().build().execute(); final result = value.data; expect(result.movies.length, 1); expect(result.movies[0].title, 'The Matrix'); }); testWidgets('can add a director to a movie', (WidgetTester tester) async { - MutationRef ref = MoviesConnector.instance.addPerson.ref( - name: 'Keanu Reeves', - ); + MutationRef ref = MoviesConnector.instance.addPerson + .ref( + name: 'Keanu Reeves', + ) + .build(); await ref.execute(); final personId = - (await MoviesConnector.instance.listPersons.ref().execute()) + (await MoviesConnector.instance.listPersons.ref().build().execute()) .data .people[0] .id; - final value = await MoviesConnector.instance.listMovies.ref().execute(); + final value = + await MoviesConnector.instance.listMovies.ref().build().execute(); final result = value.data; expect(result.movies.length, 0); - ref = MoviesConnector.instance.createMovie.ref( - genre: 'Action', - title: 'The Matrix', - releaseYear: 1999, - rating: 4.5, - ); + ref = MoviesConnector.instance.createMovie + .ref( + genre: 'Action', + title: 'The Matrix', + releaseYear: 1999, + rating: 4.5, + ) + .build(); await ref.execute(); final value2 = - await MoviesConnector.instance.listMovies.ref().execute(); + await MoviesConnector.instance.listMovies.ref().build().execute(); final result2 = value2.data; expect(result2.movies.length, 1); final movieId = result2.movies[0].id; - ref = MoviesConnector.instance.addDirectorToMovie.ref( - movieId: movieId, - personId: AddDirectorToMovieVariablesPersonId(id: personId), - ); + ref = MoviesConnector.instance.addDirectorToMovie + .ref( + movieId: movieId, + personId: AddDirectorToMovieVariablesPersonId(id: personId), + ) + .build(); await ref.execute(); final value3 = - await MoviesConnector.instance.listMovies.ref().execute(); + await MoviesConnector.instance.listMovies.ref().build().execute(); final result3 = value3.data; expect(result3.movies.length, 1); expect(result3.movies[0].directed_by.length, 1); @@ -94,27 +109,30 @@ void runQueryTests() { }); testWidgets('can delete a movie', (WidgetTester tester) async { - MutationRef ref = MoviesConnector.instance.createMovie.ref( - genre: 'Action', - title: 'The Matrix', - releaseYear: 1999, - rating: 4.5, - ); + MutationRef ref = MoviesConnector.instance.createMovie + .ref( + genre: 'Action', + title: 'The Matrix', + releaseYear: 1999, + rating: 4.5, + ) + .build(); await ref.execute(); - final value = await MoviesConnector.instance.listMovies.ref().execute(); + final value = + await MoviesConnector.instance.listMovies.ref().build().execute(); final result = value.data; expect(result.movies.length, 1); final movieId = result.movies[0].id; - ref = MoviesConnector.instance.deleteMovie.ref(id: movieId); + ref = MoviesConnector.instance.deleteMovie.ref(id: movieId).build(); await ref.execute(); final value2 = - await MoviesConnector.instance.listMovies.ref().execute(); + await MoviesConnector.instance.listMovies.ref().build().execute(); final result2 = value2.data; expect(result2.movies.length, 0); }); diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_date_and_timestamp.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_date_and_timestamp.dart index d8ddb7c80a7b..2ecb8a2d26a3 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_date_and_timestamp.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_date_and_timestamp.dart @@ -1,25 +1,44 @@ part of movies; -class AddDateAndTimestamp { - String name = "addDateAndTimestamp"; - AddDateAndTimestamp({required this.dataConnect}); +class AddDateAndTimestampVariablesBuilder { + DateTime date; + Timestamp timestamp; + + FirebaseDataConnect dataConnect; + AddDateAndTimestampVariablesBuilder( + this.dataConnect, { + required DateTime this.date, + required Timestamp this.timestamp, + }); Deserializer dataDeserializer = (String json) => AddDateAndTimestampData.fromJson( jsonDecode(json) as Map); Serializer varsSerializer = (AddDateAndTimestampVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - required DateTime date, - required Timestamp timestamp, - }) { + MutationRef build() { AddDateAndTimestampVariables vars = AddDateAndTimestampVariables( date: date, timestamp: timestamp, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "addDateAndTimestamp", dataDeserializer, varsSerializer, vars); + } +} + +class AddDateAndTimestamp { + String name = "addDateAndTimestamp"; + AddDateAndTimestamp({required this.dataConnect}); + AddDateAndTimestampVariablesBuilder ref({ + required DateTime date, + required Timestamp timestamp, + }) { + return AddDateAndTimestampVariablesBuilder( + dataConnect, + date: date, + timestamp: timestamp, + ); } FirebaseDataConnect dataConnect; @@ -28,6 +47,7 @@ class AddDateAndTimestamp { class AddDateAndTimestampTimestampHolderInsert { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDateAndTimestampTimestampHolderInsert.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -41,14 +61,13 @@ class AddDateAndTimestampTimestampHolderInsert { AddDateAndTimestampTimestampHolderInsert({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddDateAndTimestampData { AddDateAndTimestampTimestampHolderInsert timestampHolder_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDateAndTimestampData.fromJson(Map json) : timestampHolder_insert = AddDateAndTimestampTimestampHolderInsert.fromJson( @@ -64,9 +83,7 @@ class AddDateAndTimestampData { AddDateAndTimestampData({ required this.timestampHolder_insert, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddDateAndTimestampVariables { @@ -74,6 +91,7 @@ class AddDateAndTimestampVariables { Timestamp timestamp; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDateAndTimestampVariables.fromJson(Map json) : date = nativeFromJson(json['date']), timestamp = Timestamp.fromJson(json['timestamp']) {} @@ -91,7 +109,5 @@ class AddDateAndTimestampVariables { AddDateAndTimestampVariables({ required this.date, required this.timestamp, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart index e16570853506..2632d441039f 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart @@ -1,24 +1,43 @@ part of movies; -class AddDirectorToMovie { - String name = "addDirectorToMovie"; - AddDirectorToMovie({required this.dataConnect}); +class AddDirectorToMovieVariablesBuilder { + AddDirectorToMovieVariablesPersonId? personId; + String? movieId; + + FirebaseDataConnect dataConnect; + AddDirectorToMovieVariablesBuilder( + this.dataConnect, { + AddDirectorToMovieVariablesPersonId? this.personId, + String? this.movieId, + }); Deserializer dataDeserializer = (String json) => AddDirectorToMovieData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - AddDirectorToMovieVariablesPersonId? personId, - String? movieId, - }) { + MutationRef build() { AddDirectorToMovieVariables vars = AddDirectorToMovieVariables( personId: personId, movieId: movieId, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "addDirectorToMovie", dataDeserializer, varsSerializer, vars); + } +} + +class AddDirectorToMovie { + String name = "addDirectorToMovie"; + AddDirectorToMovie({required this.dataConnect}); + AddDirectorToMovieVariablesBuilder ref({ + AddDirectorToMovieVariablesPersonId? personId, + String? movieId, + }) { + return AddDirectorToMovieVariablesBuilder( + dataConnect, + personId: personId, + movieId: movieId, + ); } FirebaseDataConnect dataConnect; @@ -29,6 +48,7 @@ class AddDirectorToMovieDirectedByInsert { String movieId; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDirectorToMovieDirectedByInsert.fromJson(Map json) : directedbyId = nativeFromJson(json['directedbyId']), movieId = nativeFromJson(json['movieId']) {} @@ -46,14 +66,13 @@ class AddDirectorToMovieDirectedByInsert { AddDirectorToMovieDirectedByInsert({ required this.directedbyId, required this.movieId, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddDirectorToMovieData { AddDirectorToMovieDirectedByInsert directedBy_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDirectorToMovieData.fromJson(Map json) : directedBy_insert = AddDirectorToMovieDirectedByInsert.fromJson( json['directedBy_insert']) {} @@ -68,14 +87,13 @@ class AddDirectorToMovieData { AddDirectorToMovieData({ required this.directedBy_insert, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddDirectorToMovieVariablesPersonId { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDirectorToMovieVariablesPersonId.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -89,9 +107,7 @@ class AddDirectorToMovieVariablesPersonId { AddDirectorToMovieVariablesPersonId({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddDirectorToMovieVariables { @@ -99,6 +115,7 @@ class AddDirectorToMovieVariables { String? movieId; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddDirectorToMovieVariables.fromJson(Map json) { personId = json['personId'] == null ? null @@ -126,7 +143,5 @@ class AddDirectorToMovieVariables { AddDirectorToMovieVariables({ this.personId, this.movieId, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_person.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_person.dart index 7b0aa0466880..a708608d0272 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_person.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_person.dart @@ -1,22 +1,38 @@ part of movies; -class AddPerson { - String name = "addPerson"; - AddPerson({required this.dataConnect}); +class AddPersonVariablesBuilder { + String? name; + + FirebaseDataConnect dataConnect; + AddPersonVariablesBuilder( + this.dataConnect, { + String? this.name, + }); Deserializer dataDeserializer = (String json) => AddPersonData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (AddPersonVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - String? name, - }) { + MutationRef build() { AddPersonVariables vars = AddPersonVariables( name: name, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "addPerson", dataDeserializer, varsSerializer, vars); + } +} + +class AddPerson { + String name = "addPerson"; + AddPerson({required this.dataConnect}); + AddPersonVariablesBuilder ref({ + String? name, + }) { + return AddPersonVariablesBuilder( + dataConnect, + name: name, + ); } FirebaseDataConnect dataConnect; @@ -25,6 +41,7 @@ class AddPerson { class AddPersonPersonInsert { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddPersonPersonInsert.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -38,14 +55,13 @@ class AddPersonPersonInsert { AddPersonPersonInsert({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddPersonData { AddPersonPersonInsert person_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddPersonData.fromJson(Map json) : person_insert = AddPersonPersonInsert.fromJson(json['person_insert']) {} @@ -59,14 +75,13 @@ class AddPersonData { AddPersonData({ required this.person_insert, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddPersonVariables { String? name; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddPersonVariables.fromJson(Map json) { name = json['name'] == null ? null : nativeFromJson(json['name']); } @@ -83,7 +98,5 @@ class AddPersonVariables { AddPersonVariables({ this.name, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_timestamp.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_timestamp.dart index b31afbd90d3d..d7eac8014552 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_timestamp.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_timestamp.dart @@ -1,22 +1,38 @@ part of movies; -class AddTimestamp { - String name = "addTimestamp"; - AddTimestamp({required this.dataConnect}); +class AddTimestampVariablesBuilder { + Timestamp timestamp; + + FirebaseDataConnect dataConnect; + AddTimestampVariablesBuilder( + this.dataConnect, { + required Timestamp this.timestamp, + }); Deserializer dataDeserializer = (String json) => AddTimestampData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (AddTimestampVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - required Timestamp timestamp, - }) { + MutationRef build() { AddTimestampVariables vars = AddTimestampVariables( timestamp: timestamp, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "addTimestamp", dataDeserializer, varsSerializer, vars); + } +} + +class AddTimestamp { + String name = "addTimestamp"; + AddTimestamp({required this.dataConnect}); + AddTimestampVariablesBuilder ref({ + required Timestamp timestamp, + }) { + return AddTimestampVariablesBuilder( + dataConnect, + timestamp: timestamp, + ); } FirebaseDataConnect dataConnect; @@ -25,6 +41,7 @@ class AddTimestamp { class AddTimestampTimestampHolderInsert { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddTimestampTimestampHolderInsert.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -38,14 +55,13 @@ class AddTimestampTimestampHolderInsert { AddTimestampTimestampHolderInsert({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddTimestampData { AddTimestampTimestampHolderInsert timestampHolder_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddTimestampData.fromJson(Map json) : timestampHolder_insert = AddTimestampTimestampHolderInsert.fromJson( json['timestampHolder_insert']) {} @@ -60,14 +76,13 @@ class AddTimestampData { AddTimestampData({ required this.timestampHolder_insert, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class AddTimestampVariables { Timestamp timestamp; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. AddTimestampVariables.fromJson(Map json) : timestamp = Timestamp.fromJson(json['timestamp']) {} @@ -81,7 +96,5 @@ class AddTimestampVariables { AddTimestampVariables({ required this.timestamp, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/create_movie.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/create_movie.dart index e65aa02bd77d..1c19e2c8029f 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/create_movie.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/create_movie.dart @@ -1,30 +1,58 @@ part of movies; -class CreateMovie { - String name = "createMovie"; - CreateMovie({required this.dataConnect}); +class CreateMovieVariablesBuilder { + String title; + int releaseYear; + String genre; + double? rating; + String? description; + FirebaseDataConnect dataConnect; + + CreateMovieVariablesBuilder( + this.dataConnect, { + required String this.title, + required int this.releaseYear, + required String this.genre, + double? this.rating, + String? this.description, + }); Deserializer dataDeserializer = (String json) => CreateMovieData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (CreateMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ + MutationRef build() { + CreateMovieVariables vars = CreateMovieVariables( + title: title, + releaseYear: releaseYear, + genre: genre, + rating: rating, + description: description, + ); + + return dataConnect.mutation( + "createMovie", dataDeserializer, varsSerializer, vars); + } +} + +class CreateMovie { + String name = "createMovie"; + CreateMovie({required this.dataConnect}); + CreateMovieVariablesBuilder ref({ required String title, required int releaseYear, required String genre, double? rating, String? description, }) { - CreateMovieVariables vars = CreateMovieVariables( + return CreateMovieVariablesBuilder( + dataConnect, title: title, releaseYear: releaseYear, genre: genre, rating: rating, description: description, ); - - return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); } FirebaseDataConnect dataConnect; @@ -33,6 +61,7 @@ class CreateMovie { class CreateMovieMovieInsert { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. CreateMovieMovieInsert.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -46,14 +75,13 @@ class CreateMovieMovieInsert { CreateMovieMovieInsert({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class CreateMovieData { CreateMovieMovieInsert movie_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. CreateMovieData.fromJson(Map json) : movie_insert = CreateMovieMovieInsert.fromJson(json['movie_insert']) {} @@ -67,9 +95,7 @@ class CreateMovieData { CreateMovieData({ required this.movie_insert, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class CreateMovieVariables { @@ -83,6 +109,7 @@ class CreateMovieVariables { String? description; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. CreateMovieVariables.fromJson(Map json) : title = nativeFromJson(json['title']), releaseYear = nativeFromJson(json['releaseYear']), @@ -121,7 +148,5 @@ class CreateMovieVariables { required this.genre, this.rating, this.description, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/delete_movie.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/delete_movie.dart index 82868746cf39..d32c11b2f6fc 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/delete_movie.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/delete_movie.dart @@ -1,22 +1,38 @@ part of movies; -class DeleteMovie { - String name = "deleteMovie"; - DeleteMovie({required this.dataConnect}); +class DeleteMovieVariablesBuilder { + String id; + + FirebaseDataConnect dataConnect; + DeleteMovieVariablesBuilder( + this.dataConnect, { + required String this.id, + }); Deserializer dataDeserializer = (String json) => DeleteMovieData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (DeleteMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - required String id, - }) { + MutationRef build() { DeleteMovieVariables vars = DeleteMovieVariables( id: id, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "deleteMovie", dataDeserializer, varsSerializer, vars); + } +} + +class DeleteMovie { + String name = "deleteMovie"; + DeleteMovie({required this.dataConnect}); + DeleteMovieVariablesBuilder ref({ + required String id, + }) { + return DeleteMovieVariablesBuilder( + dataConnect, + id: id, + ); } FirebaseDataConnect dataConnect; @@ -25,6 +41,7 @@ class DeleteMovie { class DeleteMovieMovieDelete { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. DeleteMovieMovieDelete.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -38,14 +55,13 @@ class DeleteMovieMovieDelete { DeleteMovieMovieDelete({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class DeleteMovieData { DeleteMovieMovieDelete? movie_delete; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. DeleteMovieData.fromJson(Map json) { movie_delete = json['movie_delete'] == null ? null @@ -64,14 +80,13 @@ class DeleteMovieData { DeleteMovieData({ this.movie_delete, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class DeleteMovieVariables { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. DeleteMovieVariables.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -85,7 +100,5 @@ class DeleteMovieVariables { DeleteMovieVariables({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies.dart index 7e80bf8b4fb5..15227ec89c15 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies.dart @@ -1,15 +1,27 @@ part of movies; -class ListMovies { - String name = "ListMovies"; - ListMovies({required this.dataConnect}); +class ListMoviesVariablesBuilder { + FirebaseDataConnect dataConnect; + ListMoviesVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => ListMoviesData.fromJson(jsonDecode(json) as Map); - QueryRef ref() { + QueryRef build() { return dataConnect.query( - this.name, dataDeserializer, emptySerializer, null); + "ListMovies", dataDeserializer, emptySerializer, null); + } +} + +class ListMovies { + String name = "ListMovies"; + ListMovies({required this.dataConnect}); + ListMoviesVariablesBuilder ref() { + return ListMoviesVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -22,12 +34,18 @@ class ListMoviesMovies { List directed_by; + double? rating; + + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesMovies.fromJson(Map json) : id = nativeFromJson(json['id']), title = nativeFromJson(json['title']), directed_by = (json['directed_by'] as List) .map((e) => ListMoviesMoviesDirectedBy.fromJson(e)) - .toList() {} + .toList() { + rating = + json['rating'] == null ? null : nativeFromJson(json['rating']); + } Map toJson() { Map json = {}; @@ -38,6 +56,10 @@ class ListMoviesMovies { json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); + if (rating != null) { + json['rating'] = nativeToJson(rating); + } + return json; } @@ -45,14 +67,14 @@ class ListMoviesMovies { required this.id, required this.title, required this.directed_by, - }) { - // TODO: Only show this if there are optional fields. - } + this.rating, + }); } class ListMoviesMoviesDirectedBy { String name; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesMoviesDirectedBy.fromJson(Map json) : name = nativeFromJson(json['name']) {} @@ -66,14 +88,13 @@ class ListMoviesMoviesDirectedBy { ListMoviesMoviesDirectedBy({ required this.name, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class ListMoviesData { List movies; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesData.fromJson(Map json) : movies = (json['movies'] as List) .map((e) => ListMoviesMovies.fromJson(e)) @@ -89,7 +110,5 @@ class ListMoviesData { ListMoviesData({ required this.movies, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies_by_partial_title.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies_by_partial_title.dart index a2bb639cb598..768647356638 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies_by_partial_title.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_movies_by_partial_title.dart @@ -1,23 +1,40 @@ part of movies; -class ListMoviesByPartialTitle { - String name = "ListMoviesByPartialTitle"; - ListMoviesByPartialTitle({required this.dataConnect}); +class ListMoviesByPartialTitleVariablesBuilder { + String input; + + FirebaseDataConnect dataConnect; + ListMoviesByPartialTitleVariablesBuilder( + this.dataConnect, { + required String this.input, + }); Deserializer dataDeserializer = (String json) => ListMoviesByPartialTitleData.fromJson( jsonDecode(json) as Map); Serializer varsSerializer = (ListMoviesByPartialTitleVariables vars) => jsonEncode(vars.toJson()); QueryRef - ref({ - required String input, - }) { + build() { ListMoviesByPartialTitleVariables vars = ListMoviesByPartialTitleVariables( input: input, ); - return dataConnect.query(this.name, dataDeserializer, varsSerializer, vars); + return dataConnect.query( + "ListMoviesByPartialTitle", dataDeserializer, varsSerializer, vars); + } +} + +class ListMoviesByPartialTitle { + String name = "ListMoviesByPartialTitle"; + ListMoviesByPartialTitle({required this.dataConnect}); + ListMoviesByPartialTitleVariablesBuilder ref({ + required String input, + }) { + return ListMoviesByPartialTitleVariablesBuilder( + dataConnect, + input: input, + ); } FirebaseDataConnect dataConnect; @@ -32,6 +49,7 @@ class ListMoviesByPartialTitleMovies { double? rating; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesByPartialTitleMovies.fromJson(Map json) : id = nativeFromJson(json['id']), title = nativeFromJson(json['title']), @@ -61,14 +79,13 @@ class ListMoviesByPartialTitleMovies { required this.title, required this.genre, this.rating, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class ListMoviesByPartialTitleData { List movies; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesByPartialTitleData.fromJson(Map json) : movies = (json['movies'] as List) .map((e) => ListMoviesByPartialTitleMovies.fromJson(e)) @@ -84,14 +101,13 @@ class ListMoviesByPartialTitleData { ListMoviesByPartialTitleData({ required this.movies, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class ListMoviesByPartialTitleVariables { String input; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListMoviesByPartialTitleVariables.fromJson(Map json) : input = nativeFromJson(json['input']) {} @@ -105,7 +121,5 @@ class ListMoviesByPartialTitleVariables { ListMoviesByPartialTitleVariables({ required this.input, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_persons.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_persons.dart index 3e8c215e275c..85c7a33a124c 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_persons.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_persons.dart @@ -1,15 +1,27 @@ part of movies; -class ListPersons { - String name = "ListPersons"; - ListPersons({required this.dataConnect}); +class ListPersonsVariablesBuilder { + FirebaseDataConnect dataConnect; + ListPersonsVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => ListPersonsData.fromJson(jsonDecode(json) as Map); - QueryRef ref() { + QueryRef build() { return dataConnect.query( - this.name, dataDeserializer, emptySerializer, null); + "ListPersons", dataDeserializer, emptySerializer, null); + } +} + +class ListPersons { + String name = "ListPersons"; + ListPersons({required this.dataConnect}); + ListPersonsVariablesBuilder ref() { + return ListPersonsVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -20,6 +32,7 @@ class ListPersonsPeople { String name; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListPersonsPeople.fromJson(Map json) : id = nativeFromJson(json['id']), name = nativeFromJson(json['name']) {} @@ -37,14 +50,13 @@ class ListPersonsPeople { ListPersonsPeople({ required this.id, required this.name, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class ListPersonsData { List people; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListPersonsData.fromJson(Map json) : people = (json['people'] as List) .map((e) => ListPersonsPeople.fromJson(e)) @@ -60,7 +72,5 @@ class ListPersonsData { ListPersonsData({ required this.people, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_thing.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_thing.dart index 3fc1e36ac41c..d5439fba8c13 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_thing.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_thing.dart @@ -1,21 +1,38 @@ part of movies; -class ListThing { - String name = "ListThing"; - ListThing({required this.dataConnect}); +class ListThingVariablesBuilder { + AnyValue? data; + + FirebaseDataConnect dataConnect; + ListThingVariablesBuilder( + this.dataConnect, { + AnyValue? this.data, + }); Deserializer dataDeserializer = (String json) => ListThingData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (ListThingVariables vars) => jsonEncode(vars.toJson()); - QueryRef ref({ - dynamic? data, - }) { + QueryRef build() { ListThingVariables vars = ListThingVariables( - data: AnyValue(data), + data: data, ); - return dataConnect.query(this.name, dataDeserializer, varsSerializer, vars); + return dataConnect.query( + "ListThing", dataDeserializer, varsSerializer, vars); + } +} + +class ListThing { + String name = "ListThing"; + ListThing({required this.dataConnect}); + ListThingVariablesBuilder ref({ + dynamic? data, + }) { + return ListThingVariablesBuilder( + dataConnect, + data: data, + ); } FirebaseDataConnect dataConnect; @@ -24,6 +41,7 @@ class ListThing { class ListThingThings { AnyValue title; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListThingThings.fromJson(Map json) : title = AnyValue.fromJson(json['title']) {} @@ -37,14 +55,13 @@ class ListThingThings { ListThingThings({ required this.title, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class ListThingData { List things; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListThingData.fromJson(Map json) : things = (json['things'] as List) .map((e) => ListThingThings.fromJson(e)) @@ -60,14 +77,13 @@ class ListThingData { ListThingData({ required this.things, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class ListThingVariables { AnyValue? data; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListThingVariables.fromJson(Map json) { data = json['data'] == null ? null : AnyValue.fromJson(json['data']); } @@ -84,7 +100,5 @@ class ListThingVariables { ListThingVariables({ this.data, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_timestamps.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_timestamps.dart index b7a167a4973e..3ad8465bee61 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_timestamps.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/list_timestamps.dart @@ -1,15 +1,27 @@ part of movies; -class ListTimestamps { - String name = "ListTimestamps"; - ListTimestamps({required this.dataConnect}); +class ListTimestampsVariablesBuilder { + FirebaseDataConnect dataConnect; + ListTimestampsVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => ListTimestampsData.fromJson(jsonDecode(json) as Map); - QueryRef ref() { + QueryRef build() { return dataConnect.query( - this.name, dataDeserializer, emptySerializer, null); + "ListTimestamps", dataDeserializer, emptySerializer, null); + } +} + +class ListTimestamps { + String name = "ListTimestamps"; + ListTimestamps({required this.dataConnect}); + ListTimestampsVariablesBuilder ref() { + return ListTimestampsVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -20,6 +32,7 @@ class ListTimestampsTimestampHolders { DateTime? date; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListTimestampsTimestampHolders.fromJson(Map json) : timestamp = Timestamp.fromJson(json['timestamp']) { date = json['date'] == null ? null : nativeFromJson(json['date']); @@ -40,14 +53,13 @@ class ListTimestampsTimestampHolders { ListTimestampsTimestampHolders({ required this.timestamp, this.date, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class ListTimestampsData { List timestampHolders; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ListTimestampsData.fromJson(Map json) : timestampHolders = (json['timestampHolders'] as List) .map((e) => ListTimestampsTimestampHolders.fromJson(e)) @@ -63,7 +75,5 @@ class ListTimestampsData { ListTimestampsData({ required this.timestampHolders, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/movies.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/movies.dart index 2ddd9a5ce9a3..c85f61434f19 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/movies.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/movies.dart @@ -3,14 +3,6 @@ library movies; import 'package:firebase_data_connect/firebase_data_connect.dart'; import 'dart:convert'; -part 'list_movies.dart'; - -part 'list_movies_by_partial_title.dart'; - -part 'list_persons.dart'; - -part 'list_thing.dart'; - part 'add_person.dart'; part 'add_director_to_movie.dart'; @@ -29,25 +21,17 @@ part 'thing.dart'; part 'seed_data.dart'; -part 'list_timestamps.dart'; +part 'list_movies.dart'; -class MoviesConnector { - ListMovies get listMovies { - return ListMovies(dataConnect: dataConnect); - } +part 'list_movies_by_partial_title.dart'; - ListMoviesByPartialTitle get listMoviesByPartialTitle { - return ListMoviesByPartialTitle(dataConnect: dataConnect); - } +part 'list_persons.dart'; - ListPersons get listPersons { - return ListPersons(dataConnect: dataConnect); - } +part 'list_thing.dart'; - ListThing get listThing { - return ListThing(dataConnect: dataConnect); - } +part 'list_timestamps.dart'; +class MoviesConnector { AddPerson get addPerson { return AddPerson(dataConnect: dataConnect); } @@ -84,6 +68,22 @@ class MoviesConnector { return SeedData(dataConnect: dataConnect); } + ListMovies get listMovies { + return ListMovies(dataConnect: dataConnect); + } + + ListMoviesByPartialTitle get listMoviesByPartialTitle { + return ListMoviesByPartialTitle(dataConnect: dataConnect); + } + + ListPersons get listPersons { + return ListPersons(dataConnect: dataConnect); + } + + ListThing get listThing { + return ListThing(dataConnect: dataConnect); + } + ListTimestamps get listTimestamps { return ListTimestamps(dataConnect: dataConnect); } @@ -97,8 +97,9 @@ class MoviesConnector { MoviesConnector({required this.dataConnect}); static MoviesConnector get instance { return MoviesConnector( - dataConnect: - FirebaseDataConnect.instanceFor(connectorConfig: connectorConfig)); + dataConnect: FirebaseDataConnect.instanceFor( + connectorConfig: connectorConfig, + sdkType: CallerSDKType.generated)); } FirebaseDataConnect dataConnect; diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_data.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_data.dart index acb7ceb55da1..a8febef0e604 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_data.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_data.dart @@ -1,15 +1,27 @@ part of movies; -class SeedData { - String name = "seedData"; - SeedData({required this.dataConnect}); +class SeedDataVariablesBuilder { + FirebaseDataConnect dataConnect; + SeedDataVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => SeedDataData.fromJson(jsonDecode(json) as Map); - MutationRef ref() { + MutationRef build() { return dataConnect.mutation( - this.name, dataDeserializer, emptySerializer, null); + "seedData", dataDeserializer, emptySerializer, null); + } +} + +class SeedData { + String name = "seedData"; + SeedData({required this.dataConnect}); + SeedDataVariablesBuilder ref() { + return SeedDataVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -18,6 +30,7 @@ class SeedData { class SeedDataTheMatrix { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. SeedDataTheMatrix.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -31,14 +44,13 @@ class SeedDataTheMatrix { SeedDataTheMatrix({ required this.id, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class SeedDataData { SeedDataTheMatrix the_matrix; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. SeedDataData.fromJson(Map json) : the_matrix = SeedDataTheMatrix.fromJson(json['the_matrix']) {} @@ -52,7 +64,5 @@ class SeedDataData { SeedDataData({ required this.the_matrix, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_movies.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_movies.dart index 45a39edc6297..52465d236d6c 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_movies.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/seed_movies.dart @@ -1,15 +1,27 @@ part of movies; -class SeedMovies { - String name = "seedMovies"; - SeedMovies({required this.dataConnect}); +class SeedMoviesVariablesBuilder { + FirebaseDataConnect dataConnect; + SeedMoviesVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => SeedMoviesData.fromJson(jsonDecode(json) as Map); - MutationRef ref() { + MutationRef build() { return dataConnect.mutation( - this.name, dataDeserializer, emptySerializer, null); + "seedMovies", dataDeserializer, emptySerializer, null); + } +} + +class SeedMovies { + String name = "seedMovies"; + SeedMovies({required this.dataConnect}); + SeedMoviesVariablesBuilder ref() { + return SeedMoviesVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -18,6 +30,7 @@ class SeedMovies { class SeedMoviesTheMatrix { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. SeedMoviesTheMatrix.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -31,14 +44,13 @@ class SeedMoviesTheMatrix { SeedMoviesTheMatrix({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class SeedMoviesJurassicPark { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. SeedMoviesJurassicPark.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -52,9 +64,7 @@ class SeedMoviesJurassicPark { SeedMoviesJurassicPark({ required this.id, - }) { - // TODO: Only show this if there are optional fields. - } + }); } class SeedMoviesData { @@ -62,6 +72,7 @@ class SeedMoviesData { SeedMoviesJurassicPark jurassic_park; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. SeedMoviesData.fromJson(Map json) : the_matrix = SeedMoviesTheMatrix.fromJson(json['the_matrix']), jurassic_park = @@ -80,7 +91,5 @@ class SeedMoviesData { SeedMoviesData({ required this.the_matrix, required this.jurassic_park, - }) { - // TODO: Only show this if there are optional fields. - } + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/thing.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/thing.dart index 979d8b23049e..a9baaa19394a 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/thing.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/thing.dart @@ -1,22 +1,39 @@ part of movies; -class Thing { - String name = "thing"; - Thing({required this.dataConnect}); +class ThingVariablesBuilder { + Optional _title = + Optional.optional(AnyValue.fromJson, defaultSerializer); + FirebaseDataConnect dataConnect; + ThingVariablesBuilder title(AnyValue t) { + this._title.value = t; + return this; + } + + ThingVariablesBuilder( + this.dataConnect, + ); Deserializer dataDeserializer = (String json) => ThingData.fromJson(jsonDecode(json) as Map); Serializer varsSerializer = (ThingVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - dynamic title, - }) { + MutationRef build() { ThingVariables vars = ThingVariables( - title: AnyValue(title), + title: _title, ); return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); + "thing", dataDeserializer, varsSerializer, vars); + } +} + +class Thing { + String name = "thing"; + Thing({required this.dataConnect}); + ThingVariablesBuilder ref() { + return ThingVariablesBuilder( + dataConnect, + ); } FirebaseDataConnect dataConnect; @@ -25,6 +42,7 @@ class Thing { class ThingThingInsert { String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ThingThingInsert.fromJson(Map json) : id = nativeFromJson(json['id']) {} @@ -38,14 +56,13 @@ class ThingThingInsert { ThingThingInsert({ required this.id, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class ThingData { ThingThingInsert thing_insert; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ThingData.fromJson(Map json) : thing_insert = ThingThingInsert.fromJson(json['thing_insert']) {} @@ -59,42 +76,29 @@ class ThingData { ThingData({ required this.thing_insert, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class ThingVariables { - Optional _title = - Optional.optional(AnyValue.fromJson, defaultSerializer); - - set title(AnyValue t) { - this._title.value = t; - } - - AnyValue get title => this._title.value!; + late Optional title; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. ThingVariables.fromJson(Map json) { - _title.value = + title.value = json['title'] == null ? null : AnyValue.fromJson(json['title']); } Map toJson() { Map json = {}; - if (_title.state == OptionalState.set) { - json['title'] = _title.toJson(); + if (title.state == OptionalState.set) { + json['title'] = title.toJson(); } return json; } ThingVariables({ - AnyValue? title, - }) { - // TODO(mtewani): Only show this if there are optional fields. - - this._title = Optional.optional(AnyValue.fromJson, defaultSerializer); - this._title.value = title; - } + required this.title, + }); } diff --git a/packages/firebase_data_connect/firebase_data_connect/example/lib/main.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/main.dart index 1faa49a538cf..2fb2d87c64f4 100644 --- a/packages/firebase_data_connect/firebase_data_connect/example/lib/main.dart +++ b/packages/firebase_data_connect/firebase_data_connect/example/lib/main.dart @@ -101,7 +101,7 @@ class _DataConnectWidgetState extends State { double _rating = 0; Future triggerReload() async { - QueryRef ref = MoviesConnector.instance.listMovies.ref(); + QueryRef ref = MoviesConnector.instance.listMovies.ref().build(); ref.execute(); } @@ -110,7 +110,7 @@ class _DataConnectWidgetState extends State { super.initState(); QueryRef ref = - MoviesConnector.instance.listMovies.ref(); + MoviesConnector.instance.listMovies.ref().build(); ref.subscribe().listen((event) { setState(() { @@ -185,12 +185,14 @@ class _DataConnectWidgetState extends State { return; } - MutationRef ref = MoviesConnector.instance.createMovie.ref( - title: title, - releaseYear: _releaseYearDate.year, - genre: genre, - rating: _rating, - ); + MutationRef ref = MoviesConnector.instance.createMovie + .ref( + title: title, + releaseYear: _releaseYearDate.year, + genre: genre, + rating: _rating, + ) + .build(); try { await ref.execute(); triggerReload(); diff --git a/packages/firebase_data_connect/firebase_data_connect/lib/src/optional.dart b/packages/firebase_data_connect/firebase_data_connect/lib/src/optional.dart index 400be831cfb2..9d69a4040849 100644 --- a/packages/firebase_data_connect/firebase_data_connect/lib/src/optional.dart +++ b/packages/firebase_data_connect/firebase_data_connect/lib/src/optional.dart @@ -76,13 +76,18 @@ dynamic nativeToJson(T type) { throw UnimplementedError('This type is unimplemented: ${type.runtimeType}'); } -T nativeFromJson(String json) { - if (T == bool) return (json.toLowerCase() == 'true') as T; - if (T == int) return int.parse(json) as T; - if (T == double) return double.parse(json) as T; - if (T == num) return num.parse(json) as T; - if (T == String) return json as T; - if (T == DateTime) return DateTime.parse(json) as T; - +T nativeFromJson(dynamic input) { + if ((input is bool && T == bool) || + (input is int && T == int) || + (input is double && T == double) || + (input is num && input == num)) { + return input; + } else if (input is String) { + if (T == DateTime) { + return DateTime.parse(input) as T; + } else if (T == String) { + return input as T; + } + } throw UnimplementedError('This type is unimplemented: ${T.runtimeType}'); } diff --git a/packages/firebase_data_connect/firebase_data_connect/test/src/optional_test.dart b/packages/firebase_data_connect/firebase_data_connect/test/src/optional_test.dart index 62cd4e02450b..d4aa599c2b43 100644 --- a/packages/firebase_data_connect/firebase_data_connect/test/src/optional_test.dart +++ b/packages/firebase_data_connect/firebase_data_connect/test/src/optional_test.dart @@ -74,10 +74,14 @@ void main() { }); test('nativeFromJson correctly deserializes primitive types', () { - expect(nativeFromJson('42'), equals(42)); - expect(nativeFromJson('true'), equals(true)); + expect(nativeFromJson('42'), equals('42')); + expect(nativeFromJson(true), equals(true)); expect(nativeFromJson('Test'), equals('Test')); }); + test('nativeFromJson correctly deserializes DateTime strings', () { + expect(nativeFromJson('2024-01-01'), + equals(DateTime.parse('2024-01-01'))); + }); test('nativeToJson throws UnimplementedError for unsupported types', () { expect(() => nativeToJson(Object()), throwsUnimplementedError);