From 0faadc4e0f3329eced3fe44ed1a528db925dbdd7 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 25 Sep 2024 08:23:56 +0100 Subject: [PATCH 1/8] Fixed issue where native types weren't being parsed correctly --- .../example/dataconnect/connector/queries.gql | 1 + .../lib/generated/add_director_to_movie.dart | 308 +++++++++++++---- .../example/lib/generated/add_person.dart | 188 ++++++++--- .../example/lib/generated/create_movie.dart | 314 ++++++++++++++---- .../example/lib/generated/delete_movie.dart | 188 ++++++++--- .../example/lib/generated/list_movies.dart | 46 ++- .../list_movies_by_partial_title.dart | 278 +++++++++++++--- .../example/lib/generated/list_persons.dart | 166 +++++++-- .../example/lib/generated/movies.dart | 44 +-- .../lib/src/optional.dart | 27 +- 10 files changed, 1204 insertions(+), 356 deletions(-) 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 25787ca9aa33..66a40d3e52fb 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/lib/generated/add_director_to_movie.dart b/packages/firebase_data_connect/firebase_data_connect/example/lib/generated/add_director_to_movie.dart index e06fa1ff70e4..25ac722421e9 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,131 +1,303 @@ part of movies; + + + + + + + class AddDirectorToMovie { String name = "addDirectorToMovie"; AddDirectorToMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - AddDirectorToMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = - (AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - AddDirectorToMovieVariablesPersonId? personId, - String? movieId, - }) { - AddDirectorToMovieVariables vars = AddDirectorToMovieVariables( - personId: personId, - movieId: movieId, - ); - - return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); - } + Deserializer dataDeserializer = (String json) => AddDirectorToMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = (AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref( + {AddDirectorToMovieVariablesPersonId? personId,String? movieId,}) { + AddDirectorToMovieVariables vars=AddDirectorToMovieVariables(personId: personId,movieId: movieId,); + return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + } FirebaseDataConnect dataConnect; } -class AddDirectorToMovieDirectedByInsert { - late String directedbyId; - late String movieId; + - AddDirectorToMovieDirectedByInsert.fromJson(Map json) - : directedbyId = json['directedbyId'], - movieId = json['movieId'] {} - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; - - json['directedbyId'] = directedbyId; +class AddDirectorToMovieDirectedByInsert { + + + + + String directedbyId; + + + + + + + String movieId; + + + + + AddDirectorToMovieDirectedByInsert.fromJson(Map json): + directedbyId = + + nativeFromJson(json['directedbyId']) + + + , + + movieId = + + nativeFromJson(json['movieId']) + + + + { + + + + + + } - json['movieId'] = movieId; + Map toJson() { + Map json = {}; + + + json['directedbyId'] = + + nativeToJson(directedbyId) + +; + + + + json['movieId'] = + + nativeToJson(movieId) + +; + + return json; } AddDirectorToMovieDirectedByInsert({ + required this.directedbyId, + required this.movieId, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + + + } } + + + + + class AddDirectorToMovieData { - late AddDirectorToMovieDirectedByInsert directedBy_insert; + + + + + AddDirectorToMovieDirectedByInsert directedBy_insert; + + + + + AddDirectorToMovieData.fromJson(Map json): + directedBy_insert = + + AddDirectorToMovieDirectedByInsert.fromJson(json['directedBy_insert']) + + + + { + + + + } - AddDirectorToMovieData.fromJson(Map json) - : directedBy_insert = AddDirectorToMovieDirectedByInsert.fromJson( - json['directedBy_insert']) {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['directedBy_insert'] = directedBy_insert.toJson(); - + + + json['directedBy_insert'] = + + directedBy_insert.toJson() + +; + + return json; } AddDirectorToMovieData({ + required this.directedBy_insert, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class AddDirectorToMovieVariablesPersonId { - late String id; + + + + + String id; + + + + + AddDirectorToMovieVariablesPersonId.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + + { + + + + } - AddDirectorToMovieVariablesPersonId.fromJson(Map json) - : id = json['id'] {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['id'] = id; - + + + json['id'] = + + nativeToJson(id) + +; + + return json; } AddDirectorToMovieVariablesPersonId({ + required this.id, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } -class AddDirectorToMovieVariables { - late AddDirectorToMovieVariablesPersonId? personId; - late String? movieId; - AddDirectorToMovieVariables.fromJson(Map json) - : personId = - AddDirectorToMovieVariablesPersonId.fromJson(json['personId']), - movieId = json['movieId'] {} + - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; - if (personId != null) { - json['personId'] = personId!.toJson(); +class AddDirectorToMovieVariables { + + + + + AddDirectorToMovieVariablesPersonId? personId; + + + + + + + String? movieId; + + + + + AddDirectorToMovieVariables.fromJson(Map json) { + + + personId = json['personId'] == null ? null : + + AddDirectorToMovieVariablesPersonId.fromJson(json['personId']) + +; + + + + movieId = json['movieId'] == null ? null : + + nativeFromJson(json['movieId']) + +; + + } - if (movieId != null) { - json['movieId'] = movieId; - } + Map toJson() { + Map json = {}; + + + if (personId != null) { + json['personId'] = + + personId!.toJson() + +; + } + + + + if (movieId != null) { + json['movieId'] = + + nativeToJson(movieId) + +; + } + + return json; } AddDirectorToMovieVariables({ - this.personId, - this.movieId, - }) { - // TODO: Only show this if there are optional fields. + + this.personId, + + this.movieId, + + }) { // TODO(mtewani): 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 b83a1950ee3c..1753579f7e3f 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,90 +1,192 @@ part of movies; + + + + + + + class AddPerson { String name = "addPerson"; AddPerson({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - AddPersonData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = - (AddPersonVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - String? name, - }) { - AddPersonVariables vars = AddPersonVariables( - name: name, - ); - - return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); - } + Deserializer dataDeserializer = (String json) => AddPersonData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = (AddPersonVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref( + {String? name,}) { + AddPersonVariables vars=AddPersonVariables(name: name,); + return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + } FirebaseDataConnect dataConnect; } + + + + class AddPersonPersonInsert { - late String id; + + + + + String id; + + + + + AddPersonPersonInsert.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + + { + + + + } - AddPersonPersonInsert.fromJson(Map json) : id = json['id'] {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['id'] = id; - + + + json['id'] = + + nativeToJson(id) + +; + + return json; } AddPersonPersonInsert({ + required this.id, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class AddPersonData { - late AddPersonPersonInsert person_insert; + + + + + AddPersonPersonInsert person_insert; + + + + + AddPersonData.fromJson(Map json): + person_insert = + + AddPersonPersonInsert.fromJson(json['person_insert']) + + + + { + + + + } - AddPersonData.fromJson(Map json) - : person_insert = AddPersonPersonInsert.fromJson(json['person_insert']) {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['person_insert'] = person_insert.toJson(); - + + + json['person_insert'] = + + person_insert.toJson() + +; + + return json; } AddPersonData({ + required this.person_insert, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } -class AddPersonVariables { - late String? name; - AddPersonVariables.fromJson(Map json) - : name = json['name'] {} - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + - if (name != null) { - json['name'] = name; +class AddPersonVariables { + + + + + String? name; + + + + + AddPersonVariables.fromJson(Map json) { + + + name = json['name'] == null ? null : + + nativeFromJson(json['name']) + +; + + } + + Map toJson() { + Map json = {}; + + + if (name != null) { + json['name'] = + + nativeToJson(name) + +; + } + + return json; } AddPersonVariables({ - this.name, - }) { - // TODO: Only show this if there are optional fields. + + this.name, + + }) { // TODO(mtewani): 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 b09e4697c19b..722641e91785 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,125 +1,305 @@ part of movies; + + + + + + + class CreateMovie { String name = "createMovie"; CreateMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - CreateMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = - (CreateMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - required String title, - required int releaseYear, - required String genre, - double? rating, - String? description, - }) { - CreateMovieVariables vars = CreateMovieVariables( - title: title, - releaseYear: releaseYear, - genre: genre, - rating: rating, - description: description, - ); - - return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); - } + Deserializer dataDeserializer = (String json) => CreateMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = (CreateMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref( + {required String title,required int releaseYear,required String genre,double? rating,String? description,}) { + CreateMovieVariables vars=CreateMovieVariables(title: title,releaseYear: releaseYear,genre: genre,rating: rating,description: description,); + return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + } FirebaseDataConnect dataConnect; } + + + + class CreateMovieMovieInsert { - late String id; + + + + + String id; - CreateMovieMovieInsert.fromJson(Map json) - : id = json['id'] {} + + + + CreateMovieMovieInsert.fromJson(Map json): + id = + + nativeFromJson(json['id']) + - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + { + + + + } - json['id'] = id; + Map toJson() { + Map json = {}; + + + json['id'] = + + nativeToJson(id) + +; + + return json; } CreateMovieMovieInsert({ + required this.id, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class CreateMovieData { - late CreateMovieMovieInsert movie_insert; + + + + + CreateMovieMovieInsert movie_insert; - CreateMovieData.fromJson(Map json) - : movie_insert = CreateMovieMovieInsert.fromJson(json['movie_insert']) {} + + + + CreateMovieData.fromJson(Map json): + movie_insert = + + CreateMovieMovieInsert.fromJson(json['movie_insert']) + - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + { + + + + } - json['movie_insert'] = movie_insert.toJson(); + Map toJson() { + Map json = {}; + + + json['movie_insert'] = + + movie_insert.toJson() + +; + + return json; } CreateMovieData({ + required this.movie_insert, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } -class CreateMovieVariables { - late String title; - late int releaseYear; - late String genre; + - late double? rating; - late String? description; +class CreateMovieVariables { + + + + + String title; - CreateMovieVariables.fromJson(Map json) - : title = json['title'], - releaseYear = json['releaseYear'], - genre = json['genre'], - rating = json['rating'], - description = json['description'] {} + + + + + + int releaseYear; - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + + + + + String genre; - json['title'] = title; + + + + + + double? rating; - json['releaseYear'] = releaseYear; + + + + + + String? description; - json['genre'] = genre; + + + + CreateMovieVariables.fromJson(Map json): + title = + + nativeFromJson(json['title']) + - if (rating != null) { - json['rating'] = rating; - } + , + + releaseYear = + + nativeFromJson(json['releaseYear']) + + + , + + genre = + + nativeFromJson(json['genre']) + - if (description != null) { - json['description'] = description; + + { + + + + + + + + + rating = json['rating'] == null ? null : + + nativeFromJson(json['rating']) + +; + + + + description = json['description'] == null ? null : + + nativeFromJson(json['description']) + +; + + } + + Map toJson() { + Map json = {}; + + + json['title'] = + + nativeToJson(title) + +; + + + + json['releaseYear'] = + + nativeToJson(releaseYear) + +; + + + + json['genre'] = + + nativeToJson(genre) + +; + + + + if (rating != null) { + json['rating'] = + + nativeToJson(rating) + +; + } + + + + if (description != null) { + json['description'] = + + nativeToJson(description) + +; + } + + return json; } CreateMovieVariables({ + required this.title, + required this.releaseYear, + required this.genre, - this.rating, - this.description, - }) { - // TODO: Only show this if there are optional fields. + + this.rating, + + this.description, + + }) { // TODO(mtewani): 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 f4402c43601f..043087a17f57 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,90 +1,192 @@ part of movies; + + + + + + + class DeleteMovie { String name = "deleteMovie"; DeleteMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - DeleteMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = - (DeleteMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref({ - required String id, - }) { - DeleteMovieVariables vars = DeleteMovieVariables( - id: id, - ); - - return dataConnect.mutation( - this.name, dataDeserializer, varsSerializer, vars); - } + Deserializer dataDeserializer = (String json) => DeleteMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = (DeleteMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref( + {required String id,}) { + DeleteMovieVariables vars=DeleteMovieVariables(id: id,); + return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + } FirebaseDataConnect dataConnect; } + + + + class DeleteMovieMovieDelete { - late String id; + + + + + String id; + + + + + DeleteMovieMovieDelete.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + + { + + + + } - DeleteMovieMovieDelete.fromJson(Map json) - : id = json['id'] {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['id'] = id; - + + + json['id'] = + + nativeToJson(id) + +; + + return json; } DeleteMovieMovieDelete({ + required this.id, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } -class DeleteMovieData { - late DeleteMovieMovieDelete? movie_delete; - DeleteMovieData.fromJson(Map json) - : movie_delete = DeleteMovieMovieDelete.fromJson(json['movie_delete']) {} - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + - if (movie_delete != null) { - json['movie_delete'] = movie_delete!.toJson(); +class DeleteMovieData { + + + + + DeleteMovieMovieDelete? movie_delete; + + + + + DeleteMovieData.fromJson(Map json) { + + + movie_delete = json['movie_delete'] == null ? null : + + DeleteMovieMovieDelete.fromJson(json['movie_delete']) + +; + + } + + Map toJson() { + Map json = {}; + + + if (movie_delete != null) { + json['movie_delete'] = + + movie_delete!.toJson() + +; + } + + return json; } DeleteMovieData({ - this.movie_delete, - }) { - // TODO: Only show this if there are optional fields. + + this.movie_delete, + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class DeleteMovieVariables { - late String id; + + + + + String id; + + + + + DeleteMovieVariables.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + + { + + + + } - DeleteMovieVariables.fromJson(Map json) : id = json['id'] {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['id'] = id; - + + + json['id'] = + + nativeToJson(id) + +; + + return json; } DeleteMovieVariables({ + required this.id, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): 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 4ef58ec8e824..35196ff57477 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 @@ -16,29 +16,38 @@ class ListMovies { } class ListMoviesMovies { - late String id; + String id; - late String title; + String title; - late List directed_by; + List directed_by; + + double? rating; ListMoviesMovies.fromJson(Map json) - : id = json['id'], - title = json['title'], + : 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']); + print(rating); + } - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - json['id'] = id; + json['id'] = nativeToJson(id); - json['title'] = title; + json['title'] = nativeToJson(title); json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); + if (rating != null) { + json['rating'] = nativeToJson(rating); + } + return json; } @@ -46,22 +55,24 @@ class ListMoviesMovies { required this.id, required this.title, required this.directed_by, + this.rating, }) { - // TODO: Only show this if there are optional fields. + // TODO(mtewani): Only show this if there are optional fields. } } class ListMoviesMoviesDirectedBy { - late String name; + String name; ListMoviesMoviesDirectedBy.fromJson(Map json) - : name = json['name'] {} + : name = nativeFromJson(json['name']) { + print(name); + } - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - json['name'] = name; + json['name'] = nativeToJson(name); return json; } @@ -69,19 +80,18 @@ class ListMoviesMoviesDirectedBy { ListMoviesMoviesDirectedBy({ required this.name, }) { - // TODO: Only show this if there are optional fields. + // TODO(mtewani): Only show this if there are optional fields. } } class ListMoviesData { - late List movies; + List movies; ListMoviesData.fromJson(Map json) : movies = (json['movies'] as List) .map((e) => ListMoviesMovies.fromJson(e)) .toList() {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; @@ -93,6 +103,6 @@ class ListMoviesData { ListMoviesData({ required this.movies, }) { - // TODO: Only show this if there are optional fields. + // TODO(mtewani): 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 b1edfc158917..daf68127cd70 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,112 +1,282 @@ part of movies; + + + + + + + class ListMoviesByPartialTitle { String name = "ListMoviesByPartialTitle"; ListMoviesByPartialTitle({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - ListMoviesByPartialTitleData.fromJson( - jsonDecode(json) as Map); - Serializer varsSerializer = - (ListMoviesByPartialTitleVariables vars) => jsonEncode(vars.toJson()); - QueryRef - ref({ - required String input, - }) { - ListMoviesByPartialTitleVariables vars = ListMoviesByPartialTitleVariables( - input: input, - ); + Deserializer dataDeserializer = (String json) => ListMoviesByPartialTitleData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = (ListMoviesByPartialTitleVariables vars) => jsonEncode(vars.toJson()); + QueryRef ref( + {required String input,}) { + ListMoviesByPartialTitleVariables vars=ListMoviesByPartialTitleVariables(input: input,); return dataConnect.query(this.name, dataDeserializer, varsSerializer, vars); } - FirebaseDataConnect dataConnect; } -class ListMoviesByPartialTitleMovies { - late String id; - late String title; + - late String genre; - late double? rating; +class ListMoviesByPartialTitleMovies { + + + + + String id; - ListMoviesByPartialTitleMovies.fromJson(Map json) - : id = json['id'], - title = json['title'], - genre = json['genre'], - rating = json['rating'] {} + + + + + + String title; - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + + + + + String genre; + + + + + + + double? rating; - json['id'] = id; + + + + ListMoviesByPartialTitleMovies.fromJson(Map json): + id = + + nativeFromJson(json['id']) + - json['title'] = title; + , + + title = + + nativeFromJson(json['title']) + - json['genre'] = genre; + , + + genre = + + nativeFromJson(json['genre']) + - if (rating != null) { - json['rating'] = rating; + + { + + + + + + + + + rating = json['rating'] == null ? null : + + nativeFromJson(json['rating']) + +; + + } + + Map toJson() { + Map json = {}; + + + json['id'] = + + nativeToJson(id) + +; + + + + json['title'] = + + nativeToJson(title) + +; + + + + json['genre'] = + + nativeToJson(genre) + +; + + + + if (rating != null) { + json['rating'] = + + nativeToJson(rating) + +; + } + + return json; } ListMoviesByPartialTitleMovies({ + required this.id, + required this.title, + required this.genre, - this.rating, - }) { - // TODO: Only show this if there are optional fields. + + this.rating, + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + + + + + + + } } + + + + + class ListMoviesByPartialTitleData { - late List movies; + + + + + List movies; - ListMoviesByPartialTitleData.fromJson(Map json) - : movies = (json['movies'] as List) - .map((e) => ListMoviesByPartialTitleMovies.fromJson(e)) - .toList() {} + + + + ListMoviesByPartialTitleData.fromJson(Map json): + movies = + + + (json['movies'] as List) + .map((e) => ListMoviesByPartialTitleMovies.fromJson(e)) + .toList() + + - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + { + + + + } - json['movies'] = movies.map((e) => e.toJson()).toList(); + Map toJson() { + Map json = {}; + + + json['movies'] = + + + movies.map((e) => e.toJson()).toList() + + +; + + return json; } ListMoviesByPartialTitleData({ + required this.movies, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class ListMoviesByPartialTitleVariables { - late String input; + + + + + String input; - ListMoviesByPartialTitleVariables.fromJson(Map json) - : input = json['input'] {} + + + + ListMoviesByPartialTitleVariables.fromJson(Map json): + input = + + nativeFromJson(json['input']) + - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; + + { + + + + } - json['input'] = input; + Map toJson() { + Map json = {}; + + + json['input'] = + + nativeToJson(input) + +; + + return json; } ListMoviesByPartialTitleVariables({ + required this.input, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): 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 935750e1b509..accb43649f3f 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,68 +1,170 @@ part of movies; + + + + + + + class ListPersons { String name = "ListPersons"; ListPersons({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - ListPersonsData.fromJson(jsonDecode(json) as Map); - - QueryRef ref() { - return dataConnect.query( - this.name, dataDeserializer, emptySerializer, null); + Deserializer dataDeserializer = (String json) => ListPersonsData.fromJson(jsonDecode(json) as Map); + + QueryRef ref( + ) { + + return dataConnect.query(this.name, dataDeserializer, emptySerializer, null); } - FirebaseDataConnect dataConnect; } -class ListPersonsPeople { - late String id; - late String name; + - ListPersonsPeople.fromJson(Map json) - : id = json['id'], - name = json['name'] {} - // TODO: Fix up to create a map on the fly - Map toJson() { - Map json = {}; - - json['id'] = id; +class ListPersonsPeople { + + + + + String id; + + + + + + + String name; + + + + + ListPersonsPeople.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + , + + name = + + nativeFromJson(json['name']) + + + + { + + + + + + } - json['name'] = name; + Map toJson() { + Map json = {}; + + + json['id'] = + + nativeToJson(id) + +; + + + + json['name'] = + + nativeToJson(name) + +; + + return json; } ListPersonsPeople({ + required this.id, + required this.name, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + + + } } + + + + + class ListPersonsData { - late List people; + + + + + List people; + + + + + ListPersonsData.fromJson(Map json): + people = + + + (json['people'] as List) + .map((e) => ListPersonsPeople.fromJson(e)) + .toList() + + + + + { + + + + } - ListPersonsData.fromJson(Map json) - : people = (json['people'] as List) - .map((e) => ListPersonsPeople.fromJson(e)) - .toList() {} - // TODO: Fix up to create a map on the fly Map toJson() { Map json = {}; - - json['people'] = people.map((e) => e.toJson()).toList(); - + + + json['people'] = + + + people.map((e) => e.toJson()).toList() + + +; + + return json; } ListPersonsData({ + required this.people, - }) { - // TODO: Only show this if there are optional fields. + + }) { // TODO(mtewani): 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 b8bb12526357..99569baa6429 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 @@ -1,14 +1,7 @@ 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 'add_person.dart'; part 'add_director_to_movie.dart'; @@ -17,34 +10,44 @@ part 'create_movie.dart'; part 'delete_movie.dart'; -class MoviesConnector { - ListMovies get listMovies { - return ListMovies(dataConnect: dataConnect); - } +part 'list_movies.dart'; - ListMoviesByPartialTitle get listMoviesByPartialTitle { - return ListMoviesByPartialTitle(dataConnect: dataConnect); - } +part 'list_movies_by_partial_title.dart'; + +part 'list_persons.dart'; - ListPersons get listPersons { - return ListPersons(dataConnect: dataConnect); - } + +class MoviesConnector { + AddPerson get addPerson { return AddPerson(dataConnect: dataConnect); } - + AddDirectorToMovie get addDirectorToMovie { return AddDirectorToMovie(dataConnect: dataConnect); } - + CreateMovie get createMovie { return CreateMovie(dataConnect: dataConnect); } - + DeleteMovie get deleteMovie { return DeleteMovie(dataConnect: dataConnect); } + + ListMovies get listMovies { + return ListMovies(dataConnect: dataConnect); + } + + ListMoviesByPartialTitle get listMoviesByPartialTitle { + return ListMoviesByPartialTitle(dataConnect: dataConnect); + } + + ListPersons get listPersons { + return ListPersons(dataConnect: dataConnect); + } + static ConnectorConfig connectorConfig = ConnectorConfig( 'us-west2', @@ -61,3 +64,4 @@ class MoviesConnector { FirebaseDataConnect dataConnect; } + 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 ee054b97aa0e..f1756501aea4 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 @@ -65,22 +65,27 @@ class Optional { } } -String nativeToJson(T type) { - if (type is bool || type is int || type is double || type is num) { - return type.toString(); - } else if (type is String) { +dynamic nativeToJson(T type) { + if (type is bool || + type is int || + type is double || + type is num || + type is String) { return type; } else { 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; - +T nativeFromJson(dynamic input) { + if (input is bool || input is int || input is double || input is 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}'); } From 78f450353edf26c6bdfd04a5b309700b12a41f3a Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 25 Sep 2024 10:24:35 +0100 Subject: [PATCH 2/8] modified optional_test --- .../example/lib/generated/list_movies.dart | 283 ++++++++++++++---- .../test/src/optional_test.dart | 17 +- 2 files changed, 239 insertions(+), 61 deletions(-) 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 35196ff57477..cd6e94cd7419 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,108 +1,287 @@ part of movies; + + + + + + + class ListMovies { String name = "ListMovies"; ListMovies({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => - ListMoviesData.fromJson(jsonDecode(json) as Map); - - QueryRef ref() { - return dataConnect.query( - this.name, dataDeserializer, emptySerializer, null); + Deserializer dataDeserializer = (String json) => ListMoviesData.fromJson(jsonDecode(json) as Map); + + QueryRef ref( + ) { + + return dataConnect.query(this.name, dataDeserializer, emptySerializer, null); } - FirebaseDataConnect dataConnect; } -class ListMoviesMovies { - String id; - String title; + + - List directed_by; +class ListMoviesMovies { + + + + + String id; - double? rating; + + + + + + String title; - 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() { - rating = - json['rating'] == null ? null : nativeFromJson(json['rating']); - print(rating); - } + + + + + + List directed_by; - Map toJson() { - Map json = {}; + + + + + + double? rating; - json['id'] = nativeToJson(id); + + + + ListMoviesMovies.fromJson(Map json): + id = + + nativeFromJson(json['id']) + - json['title'] = nativeToJson(title); + , + + title = + + nativeFromJson(json['title']) + - json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); + , + + directed_by = + + + (json['directed_by'] as List) + .map((e) => ListMoviesMoviesDirectedBy.fromJson(e)) + .toList() + + - if (rating != null) { - json['rating'] = nativeToJson(rating); + + { + + + + + + + + + rating = json['rating'] == null ? null : + + nativeFromJson(json['rating']) + +; + + } + + Map toJson() { + Map json = {}; + + + json['id'] = + + nativeToJson(id) + +; + + + + json['title'] = + + nativeToJson(title) + +; + + + + json['directed_by'] = + + + directed_by.map((e) => e.toJson()).toList() + + +; + + + + if (rating != null) { + json['rating'] = + + nativeToJson(rating) + +; + } + + return json; } ListMoviesMovies({ + required this.id, + required this.title, + required this.directed_by, - this.rating, - }) { - // TODO(mtewani): Only show this if there are optional fields. + + this.rating, + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + + + + + + + } } + + + + + class ListMoviesMoviesDirectedBy { - String name; + + + + + String name; - ListMoviesMoviesDirectedBy.fromJson(Map json) - : name = nativeFromJson(json['name']) { - print(name); - } + + + + ListMoviesMoviesDirectedBy.fromJson(Map json): + name = + + nativeFromJson(json['name']) + - Map toJson() { - Map json = {}; + + { + + + + } - json['name'] = nativeToJson(name); + Map toJson() { + Map json = {}; + + + json['name'] = + + nativeToJson(name) + +; + + return json; } ListMoviesMoviesDirectedBy({ + required this.name, - }) { - // TODO(mtewani): Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + class ListMoviesData { - List movies; + + + + + List movies; - ListMoviesData.fromJson(Map json) - : movies = (json['movies'] as List) - .map((e) => ListMoviesMovies.fromJson(e)) - .toList() {} + + + + ListMoviesData.fromJson(Map json): + movies = + + + (json['movies'] as List) + .map((e) => ListMoviesMovies.fromJson(e)) + .toList() + + - Map toJson() { - Map json = {}; + + { + + + + } - json['movies'] = movies.map((e) => e.toJson()).toList(); + Map toJson() { + Map json = {}; + + + json['movies'] = + + + movies.map((e) => e.toJson()).toList() + + +; + + return json; } ListMoviesData({ + required this.movies, - }) { - // TODO(mtewani): Only show this if there are optional fields. + + }) { // TODO(mtewani): Only show this if there are optional fields. + + + } } + + + + + + + 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 47cdd1778ed8..12a22d44ed1c 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 @@ -68,24 +68,23 @@ void main() { }); test('nativeToJson correctly serializes primitive types', () { - expect(nativeToJson(42), equals('42')); - expect(nativeToJson(true), equals('true')); + expect(nativeToJson(42), equals(42)); + expect(nativeToJson(true), equals(true)); expect(nativeToJson('Test'), equals('Test')); }); 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(DateTime.now()), throwsUnimplementedError); }); - - test('nativeFromJson throws UnimplementedError for unsupported types', () { - expect(() => nativeFromJson('2024-01-01'), - throwsUnimplementedError); - }); }); } From 5cf1769c2585e09a3dd4c78eb91edad08aae4030 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 25 Sep 2024 11:45:25 +0100 Subject: [PATCH 3/8] Made types stricter --- .../firebase_data_connect/lib/src/optional.dart | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 f1756501aea4..2f6299d78447 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 @@ -78,7 +78,10 @@ dynamic nativeToJson(T type) { } T nativeFromJson(dynamic input) { - if (input is bool || input is int || input is double || input is num) { + 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) { From e83d7a4bebb6115c1de9115677278b84f5780c33 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Wed, 25 Sep 2024 15:41:41 +0100 Subject: [PATCH 4/8] Fixed formattign --- .../lib/generated/add_director_to_movie.dart | 309 ++++------------- .../example/lib/generated/add_person.dart | 187 +++-------- .../example/lib/generated/create_movie.dart | 314 ++++-------------- .../example/lib/generated/delete_movie.dart | 189 +++-------- .../example/lib/generated/list_movies.dart | 280 +++------------- .../list_movies_by_partial_title.dart | 277 +++------------ .../example/lib/generated/list_persons.dart | 164 ++------- .../example/lib/generated/movies.dart | 18 +- 8 files changed, 362 insertions(+), 1376 deletions(-) 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 25ac722421e9..db7ab2177f0a 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,303 +1,132 @@ part of movies; - - - - - - - class AddDirectorToMovie { String name = "addDirectorToMovie"; AddDirectorToMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => AddDirectorToMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = (AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref( - {AddDirectorToMovieVariablesPersonId? personId,String? movieId,}) { - AddDirectorToMovieVariables vars=AddDirectorToMovieVariables(personId: personId,movieId: movieId,); - - return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + Deserializer dataDeserializer = (String json) => + AddDirectorToMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = + (AddDirectorToMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref({ + AddDirectorToMovieVariablesPersonId? personId, + String? movieId, + }) { + AddDirectorToMovieVariables vars = AddDirectorToMovieVariables( + personId: personId, + movieId: movieId, + ); + + return dataConnect.mutation( + this.name, dataDeserializer, varsSerializer, vars); } + FirebaseDataConnect dataConnect; } - - - - class AddDirectorToMovieDirectedByInsert { - - - - - String directedbyId; - - - - - - - String movieId; - - - - - AddDirectorToMovieDirectedByInsert.fromJson(Map json): - directedbyId = - - nativeFromJson(json['directedbyId']) - - - , - - movieId = - - nativeFromJson(json['movieId']) - - - - { - - - - - - } + String directedbyId; + + String movieId; + AddDirectorToMovieDirectedByInsert.fromJson(Map json) + : directedbyId = nativeFromJson(json['directedbyId']), + movieId = nativeFromJson(json['movieId']) {} Map toJson() { Map json = {}; - - - json['directedbyId'] = - - nativeToJson(directedbyId) - -; - - - - json['movieId'] = - - nativeToJson(movieId) - -; - - + + json['directedbyId'] = nativeToJson(directedbyId); + + json['movieId'] = nativeToJson(movieId); + return json; } AddDirectorToMovieDirectedByInsert({ - required this.directedbyId, - required this.movieId, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class AddDirectorToMovieData { - - - - - AddDirectorToMovieDirectedByInsert directedBy_insert; - - - - - AddDirectorToMovieData.fromJson(Map json): - directedBy_insert = - - AddDirectorToMovieDirectedByInsert.fromJson(json['directedBy_insert']) - - - - { - - - - } + AddDirectorToMovieDirectedByInsert directedBy_insert; + AddDirectorToMovieData.fromJson(Map json) + : directedBy_insert = AddDirectorToMovieDirectedByInsert.fromJson( + json['directedBy_insert']) {} Map toJson() { Map json = {}; - - - json['directedBy_insert'] = - - directedBy_insert.toJson() - -; - - + + json['directedBy_insert'] = directedBy_insert.toJson(); + return json; } AddDirectorToMovieData({ - required this.directedBy_insert, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class AddDirectorToMovieVariablesPersonId { - - - - - String id; - - - - - AddDirectorToMovieVariablesPersonId.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - - { - - - - } + String id; + AddDirectorToMovieVariablesPersonId.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } AddDirectorToMovieVariablesPersonId({ - required this.id, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } +class AddDirectorToMovieVariables { + AddDirectorToMovieVariablesPersonId? personId; + String? movieId; - + AddDirectorToMovieVariables.fromJson(Map json) { + personId = json['personId'] == null + ? null + : AddDirectorToMovieVariablesPersonId.fromJson(json['personId']); + movieId = json['movieId'] == null + ? null + : nativeFromJson(json['movieId']); + } -class AddDirectorToMovieVariables { - - - - - AddDirectorToMovieVariablesPersonId? personId; - - - - - - - String? movieId; - - - - - AddDirectorToMovieVariables.fromJson(Map json) { - - - personId = json['personId'] == null ? null : - - AddDirectorToMovieVariablesPersonId.fromJson(json['personId']) - -; - - - - movieId = json['movieId'] == null ? null : - - nativeFromJson(json['movieId']) - -; - - + Map toJson() { + Map json = {}; + + if (personId != null) { + json['personId'] = personId!.toJson(); } + if (movieId != null) { + json['movieId'] = nativeToJson(movieId); + } - Map toJson() { - Map json = {}; - - - if (personId != null) { - json['personId'] = - - personId!.toJson() - -; - } - - - - if (movieId != null) { - json['movieId'] = - - nativeToJson(movieId) - -; - } - - return json; } AddDirectorToMovieVariables({ - - this.personId, - - this.movieId, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - + this.personId, + this.movieId, + }) { + // TODO(mtewani): 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 1753579f7e3f..dc16ba6e322f 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,192 +1,89 @@ part of movies; - - - - - - - class AddPerson { String name = "addPerson"; AddPerson({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => AddPersonData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = (AddPersonVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref( - {String? name,}) { - AddPersonVariables vars=AddPersonVariables(name: name,); - - return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + Deserializer dataDeserializer = (String json) => + AddPersonData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = + (AddPersonVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref({ + String? name, + }) { + AddPersonVariables vars = AddPersonVariables( + name: name, + ); + + return dataConnect.mutation( + this.name, dataDeserializer, varsSerializer, vars); } + FirebaseDataConnect dataConnect; } - - - - class AddPersonPersonInsert { - - - - - String id; - - - - - AddPersonPersonInsert.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - - { - - - - } + String id; + AddPersonPersonInsert.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } AddPersonPersonInsert({ - required this.id, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class AddPersonData { - - - - - AddPersonPersonInsert person_insert; - - - - - AddPersonData.fromJson(Map json): - person_insert = - - AddPersonPersonInsert.fromJson(json['person_insert']) - - - - { - - - - } + AddPersonPersonInsert person_insert; + AddPersonData.fromJson(Map json) + : person_insert = AddPersonPersonInsert.fromJson(json['person_insert']) {} Map toJson() { Map json = {}; - - - json['person_insert'] = - - person_insert.toJson() - -; - - + + json['person_insert'] = person_insert.toJson(); + return json; } AddPersonData({ - required this.person_insert, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class AddPersonVariables { - - - - - String? name; - - - - - AddPersonVariables.fromJson(Map json) { - - - name = json['name'] == null ? null : - - nativeFromJson(json['name']) - -; - - - } + String? name; + AddPersonVariables.fromJson(Map json) { + name = json['name'] == null ? null : nativeFromJson(json['name']); + } Map toJson() { Map json = {}; - - - if (name != null) { - json['name'] = - - nativeToJson(name) - -; - } - - + + if (name != null) { + json['name'] = nativeToJson(name); + } + return json; } AddPersonVariables({ - - this.name, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + this.name, + }) { + // TODO(mtewani): 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 722641e91785..eced35cf3d7a 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,305 +1,127 @@ part of movies; - - - - - - - class CreateMovie { String name = "createMovie"; CreateMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => CreateMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = (CreateMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref( - {required String title,required int releaseYear,required String genre,double? rating,String? description,}) { - CreateMovieVariables vars=CreateMovieVariables(title: title,releaseYear: releaseYear,genre: genre,rating: rating,description: description,); - - return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + Deserializer dataDeserializer = (String json) => + CreateMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = + (CreateMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref({ + required String title, + required int releaseYear, + required String genre, + double? rating, + String? description, + }) { + CreateMovieVariables vars = CreateMovieVariables( + title: title, + releaseYear: releaseYear, + genre: genre, + rating: rating, + description: description, + ); + + return dataConnect.mutation( + this.name, dataDeserializer, varsSerializer, vars); } + FirebaseDataConnect dataConnect; } - - - - class CreateMovieMovieInsert { - - - - - String id; - - - - - CreateMovieMovieInsert.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - - { - - - - } + String id; + CreateMovieMovieInsert.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } CreateMovieMovieInsert({ - required this.id, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class CreateMovieData { - - - - - CreateMovieMovieInsert movie_insert; - - - - - CreateMovieData.fromJson(Map json): - movie_insert = - - CreateMovieMovieInsert.fromJson(json['movie_insert']) - - - - { - - - - } + CreateMovieMovieInsert movie_insert; + CreateMovieData.fromJson(Map json) + : movie_insert = CreateMovieMovieInsert.fromJson(json['movie_insert']) {} Map toJson() { Map json = {}; - - - json['movie_insert'] = - - movie_insert.toJson() - -; - - + + json['movie_insert'] = movie_insert.toJson(); + return json; } CreateMovieData({ - required this.movie_insert, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } +class CreateMovieVariables { + String title; + int releaseYear; - - + String genre; -class CreateMovieVariables { - - - - - String title; + double? rating; - - - - - - int releaseYear; + String? description; - - - - - - String genre; + CreateMovieVariables.fromJson(Map json) + : title = nativeFromJson(json['title']), + releaseYear = nativeFromJson(json['releaseYear']), + genre = nativeFromJson(json['genre']) { + rating = + json['rating'] == null ? null : nativeFromJson(json['rating']); - - - - - - double? rating; + description = json['description'] == null + ? null + : nativeFromJson(json['description']); + } - - - - - - String? description; + Map toJson() { + Map json = {}; - - - - CreateMovieVariables.fromJson(Map json): - title = - - nativeFromJson(json['title']) - + json['title'] = nativeToJson(title); - , - - releaseYear = - - nativeFromJson(json['releaseYear']) - + json['releaseYear'] = nativeToJson(releaseYear); - , - - genre = - - nativeFromJson(json['genre']) - + json['genre'] = nativeToJson(genre); - - { - - - - - - - - - rating = json['rating'] == null ? null : - - nativeFromJson(json['rating']) - -; - - - - description = json['description'] == null ? null : - - nativeFromJson(json['description']) - -; - - + if (rating != null) { + json['rating'] = nativeToJson(rating); } + if (description != null) { + json['description'] = nativeToJson(description); + } - Map toJson() { - Map json = {}; - - - json['title'] = - - nativeToJson(title) - -; - - - - json['releaseYear'] = - - nativeToJson(releaseYear) - -; - - - - json['genre'] = - - nativeToJson(genre) - -; - - - - if (rating != null) { - json['rating'] = - - nativeToJson(rating) - -; - } - - - - if (description != null) { - json['description'] = - - nativeToJson(description) - -; - } - - return json; } CreateMovieVariables({ - required this.title, - required this.releaseYear, - required this.genre, - - this.rating, - - this.description, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - - - - - - - + this.rating, + this.description, + }) { + // TODO(mtewani): 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 043087a17f57..49f0bc7e09ae 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,192 +1,91 @@ part of movies; - - - - - - - class DeleteMovie { String name = "deleteMovie"; DeleteMovie({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => DeleteMovieData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = (DeleteMovieVariables vars) => jsonEncode(vars.toJson()); - MutationRef ref( - {required String id,}) { - DeleteMovieVariables vars=DeleteMovieVariables(id: id,); - - return dataConnect.mutation(this.name, dataDeserializer, varsSerializer, vars); + Deserializer dataDeserializer = (String json) => + DeleteMovieData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = + (DeleteMovieVariables vars) => jsonEncode(vars.toJson()); + MutationRef ref({ + required String id, + }) { + DeleteMovieVariables vars = DeleteMovieVariables( + id: id, + ); + + return dataConnect.mutation( + this.name, dataDeserializer, varsSerializer, vars); } + FirebaseDataConnect dataConnect; } - - - - class DeleteMovieMovieDelete { - - - - - String id; - - - - - DeleteMovieMovieDelete.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - - { - - - - } + String id; + DeleteMovieMovieDelete.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } DeleteMovieMovieDelete({ - required this.id, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class DeleteMovieData { - - - - - DeleteMovieMovieDelete? movie_delete; - - - - - DeleteMovieData.fromJson(Map json) { - - - movie_delete = json['movie_delete'] == null ? null : - - DeleteMovieMovieDelete.fromJson(json['movie_delete']) - -; - - - } + DeleteMovieMovieDelete? movie_delete; + DeleteMovieData.fromJson(Map json) { + movie_delete = json['movie_delete'] == null + ? null + : DeleteMovieMovieDelete.fromJson(json['movie_delete']); + } Map toJson() { Map json = {}; - - - if (movie_delete != null) { - json['movie_delete'] = - - movie_delete!.toJson() - -; - } - - + + if (movie_delete != null) { + json['movie_delete'] = movie_delete!.toJson(); + } + return json; } DeleteMovieData({ - - this.movie_delete, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + this.movie_delete, + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class DeleteMovieVariables { - - - - - String id; - - - - - DeleteMovieVariables.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - - { - - - - } + String id; + DeleteMovieVariables.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } DeleteMovieVariables({ - required this.id, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): 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 cd6e94cd7419..7140a4715b1d 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,287 +1,105 @@ part of movies; - - - - - - - class ListMovies { String name = "ListMovies"; ListMovies({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => ListMoviesData.fromJson(jsonDecode(json) as Map); - - QueryRef ref( - ) { - - return dataConnect.query(this.name, dataDeserializer, emptySerializer, null); + Deserializer dataDeserializer = (String json) => + ListMoviesData.fromJson(jsonDecode(json) as Map); + + QueryRef ref() { + return dataConnect.query( + this.name, dataDeserializer, emptySerializer, null); } + FirebaseDataConnect dataConnect; } +class ListMoviesMovies { + String id; - - + String title; -class ListMoviesMovies { - - - - - String id; + List directed_by; - - - - - - String title; + double? rating; - - - - - - List directed_by; + 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() { + rating = + json['rating'] == null ? null : nativeFromJson(json['rating']); + } - - - - - - double? rating; + Map toJson() { + Map json = {}; - - - - ListMoviesMovies.fromJson(Map json): - id = - - nativeFromJson(json['id']) - + json['id'] = nativeToJson(id); - , - - title = - - nativeFromJson(json['title']) - + json['title'] = nativeToJson(title); - , - - directed_by = - - - (json['directed_by'] as List) - .map((e) => ListMoviesMoviesDirectedBy.fromJson(e)) - .toList() - - + json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); - - { - - - - - - - - - rating = json['rating'] == null ? null : - - nativeFromJson(json['rating']) - -; - - + if (rating != null) { + json['rating'] = nativeToJson(rating); } - - Map toJson() { - Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - - - json['title'] = - - nativeToJson(title) - -; - - - - json['directed_by'] = - - - directed_by.map((e) => e.toJson()).toList() - - -; - - - - if (rating != null) { - json['rating'] = - - nativeToJson(rating) - -; - } - - return json; } ListMoviesMovies({ - required this.id, - required this.title, - required this.directed_by, - - this.rating, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - - - - - + this.rating, + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class ListMoviesMoviesDirectedBy { - - - - - String name; - - - - - ListMoviesMoviesDirectedBy.fromJson(Map json): - name = - - nativeFromJson(json['name']) - - - - { - - - - } + String name; + ListMoviesMoviesDirectedBy.fromJson(Map json) + : name = nativeFromJson(json['name']) {} Map toJson() { Map json = {}; - - - json['name'] = - - nativeToJson(name) - -; - - + + json['name'] = nativeToJson(name); + return json; } ListMoviesMoviesDirectedBy({ - required this.name, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class ListMoviesData { - - - - - List movies; - - - - - ListMoviesData.fromJson(Map json): - movies = - - - (json['movies'] as List) - .map((e) => ListMoviesMovies.fromJson(e)) - .toList() - - - - - { - - - - } + List movies; + ListMoviesData.fromJson(Map json) + : movies = (json['movies'] as List) + .map((e) => ListMoviesMovies.fromJson(e)) + .toList() {} Map toJson() { Map json = {}; - - - json['movies'] = - - - movies.map((e) => e.toJson()).toList() - - -; - - + + json['movies'] = movies.map((e) => e.toJson()).toList(); + return json; } ListMoviesData({ - required this.movies, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): 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 daf68127cd70..a8560a27f571 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,282 +1,111 @@ part of movies; - - - - - - - class ListMoviesByPartialTitle { String name = "ListMoviesByPartialTitle"; ListMoviesByPartialTitle({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => ListMoviesByPartialTitleData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = (ListMoviesByPartialTitleVariables vars) => jsonEncode(vars.toJson()); - QueryRef ref( - {required String input,}) { - ListMoviesByPartialTitleVariables vars=ListMoviesByPartialTitleVariables(input: input,); + Deserializer dataDeserializer = (String json) => + ListMoviesByPartialTitleData.fromJson( + jsonDecode(json) as Map); + Serializer varsSerializer = + (ListMoviesByPartialTitleVariables vars) => jsonEncode(vars.toJson()); + QueryRef + ref({ + required String input, + }) { + ListMoviesByPartialTitleVariables vars = ListMoviesByPartialTitleVariables( + input: input, + ); return dataConnect.query(this.name, dataDeserializer, varsSerializer, vars); } + FirebaseDataConnect dataConnect; } +class ListMoviesByPartialTitleMovies { + String id; - - + String title; -class ListMoviesByPartialTitleMovies { - - - - - String id; + String genre; - - - - - - String title; + double? rating; - - - - - - String genre; + ListMoviesByPartialTitleMovies.fromJson(Map json) + : id = nativeFromJson(json['id']), + title = nativeFromJson(json['title']), + genre = nativeFromJson(json['genre']) { + rating = + json['rating'] == null ? null : nativeFromJson(json['rating']); + } - - - - - - double? rating; + Map toJson() { + Map json = {}; - - - - ListMoviesByPartialTitleMovies.fromJson(Map json): - id = - - nativeFromJson(json['id']) - + json['id'] = nativeToJson(id); - , - - title = - - nativeFromJson(json['title']) - + json['title'] = nativeToJson(title); - , - - genre = - - nativeFromJson(json['genre']) - + json['genre'] = nativeToJson(genre); - - { - - - - - - - - - rating = json['rating'] == null ? null : - - nativeFromJson(json['rating']) - -; - - + if (rating != null) { + json['rating'] = nativeToJson(rating); } - - Map toJson() { - Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - - - json['title'] = - - nativeToJson(title) - -; - - - - json['genre'] = - - nativeToJson(genre) - -; - - - - if (rating != null) { - json['rating'] = - - nativeToJson(rating) - -; - } - - return json; } ListMoviesByPartialTitleMovies({ - required this.id, - required this.title, - required this.genre, - - this.rating, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - - - - - + this.rating, + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class ListMoviesByPartialTitleData { - - - - - List movies; - - - - - ListMoviesByPartialTitleData.fromJson(Map json): - movies = - - - (json['movies'] as List) - .map((e) => ListMoviesByPartialTitleMovies.fromJson(e)) - .toList() - - - - - { - - - - } + List movies; + ListMoviesByPartialTitleData.fromJson(Map json) + : movies = (json['movies'] as List) + .map((e) => ListMoviesByPartialTitleMovies.fromJson(e)) + .toList() {} Map toJson() { Map json = {}; - - - json['movies'] = - - - movies.map((e) => e.toJson()).toList() - - -; - - + + json['movies'] = movies.map((e) => e.toJson()).toList(); + return json; } ListMoviesByPartialTitleData({ - required this.movies, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class ListMoviesByPartialTitleVariables { - - - - - String input; - - - - - ListMoviesByPartialTitleVariables.fromJson(Map json): - input = - - nativeFromJson(json['input']) - - - - { - - - - } + String input; + ListMoviesByPartialTitleVariables.fromJson(Map json) + : input = nativeFromJson(json['input']) {} Map toJson() { Map json = {}; - - - json['input'] = - - nativeToJson(input) - -; - - + + json['input'] = nativeToJson(input); + return json; } ListMoviesByPartialTitleVariables({ - required this.input, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): 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 accb43649f3f..f8e055affa2c 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,170 +1,66 @@ part of movies; - - - - - - - class ListPersons { String name = "ListPersons"; ListPersons({required this.dataConnect}); - Deserializer dataDeserializer = (String json) => ListPersonsData.fromJson(jsonDecode(json) as Map); - - QueryRef ref( - ) { - - return dataConnect.query(this.name, dataDeserializer, emptySerializer, null); + Deserializer dataDeserializer = (String json) => + ListPersonsData.fromJson(jsonDecode(json) as Map); + + QueryRef ref() { + return dataConnect.query( + this.name, dataDeserializer, emptySerializer, null); } + FirebaseDataConnect dataConnect; } - - - - class ListPersonsPeople { - - - - - String id; - - - - - - - String name; - - - - - ListPersonsPeople.fromJson(Map json): - id = - - nativeFromJson(json['id']) - - - , - - name = - - nativeFromJson(json['name']) - - - - { - - - - - - } + String id; + String name; + + ListPersonsPeople.fromJson(Map json) + : id = nativeFromJson(json['id']), + name = nativeFromJson(json['name']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - - - json['name'] = - - nativeToJson(name) - -; - - + + json['id'] = nativeToJson(id); + + json['name'] = nativeToJson(name); + return json; } ListPersonsPeople({ - required this.id, - required this.name, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - - - + }) { + // TODO(mtewani): Only show this if there are optional fields. } } - - - - - class ListPersonsData { - - - - - List people; - - - - - ListPersonsData.fromJson(Map json): - people = - - - (json['people'] as List) - .map((e) => ListPersonsPeople.fromJson(e)) - .toList() - - - - - { - - - - } + List people; + ListPersonsData.fromJson(Map json) + : people = (json['people'] as List) + .map((e) => ListPersonsPeople.fromJson(e)) + .toList() {} Map toJson() { Map json = {}; - - - json['people'] = - - - people.map((e) => e.toJson()).toList() - - -; - - + + json['people'] = people.map((e) => e.toJson()).toList(); + return json; } ListPersonsData({ - required this.people, - - }) { // TODO(mtewani): Only show this if there are optional fields. - - - + }) { + // TODO(mtewani): 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 99569baa6429..9c0f15b0ac39 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 @@ -1,4 +1,5 @@ library movies; + import 'package:firebase_data_connect/firebase_data_connect.dart'; import 'dart:convert'; @@ -16,38 +17,34 @@ part 'list_movies_by_partial_title.dart'; part 'list_persons.dart'; - - class MoviesConnector { - AddPerson get addPerson { return AddPerson(dataConnect: dataConnect); } - + AddDirectorToMovie get addDirectorToMovie { return AddDirectorToMovie(dataConnect: dataConnect); } - + CreateMovie get createMovie { return CreateMovie(dataConnect: dataConnect); } - + DeleteMovie get deleteMovie { return DeleteMovie(dataConnect: dataConnect); } - + ListMovies get listMovies { return ListMovies(dataConnect: dataConnect); } - + ListMoviesByPartialTitle get listMoviesByPartialTitle { return ListMoviesByPartialTitle(dataConnect: dataConnect); } - + ListPersons get listPersons { return ListPersons(dataConnect: dataConnect); } - static ConnectorConfig connectorConfig = ConnectorConfig( 'us-west2', @@ -64,4 +61,3 @@ class MoviesConnector { FirebaseDataConnect dataConnect; } - From 5be312d08bb1e1126f1909bb299a36b72892c6a8 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 26 Sep 2024 13:48:42 +0100 Subject: [PATCH 5/8] Updated generated files to include builder from generated SDK --- .../integration_test/generation_e2e.dart | 8 +- .../example/integration_test/listen_e2e.dart | 6 +- .../example/integration_test/query_e2e.dart | 90 +++++--- .../lib/generated/add_date_and_timestamp.dart | 50 +++-- .../lib/generated/add_director_to_movie.dart | 53 +++-- .../example/lib/generated/add_person.dart | 44 ++-- .../example/lib/generated/add_timestamp.dart | 45 ++-- .../example/lib/generated/create_movie.dart | 61 ++++-- .../example/lib/generated/delete_movie.dart | 45 ++-- .../example/lib/generated/list_movies.dart | 49 ++--- .../list_movies_by_partial_title.dart | 46 ++-- .../example/lib/generated/list_persons.dart | 32 ++- .../example/lib/generated/list_thing.dart | 205 +++++++++++++----- .../lib/generated/list_timestamps.dart | 32 ++- .../example/lib/generated/movies.dart | 73 ++++--- .../example/lib/generated/seed_data.dart | 136 +++++++++--- .../example/lib/generated/seed_movies.dart | 37 ++-- .../example/lib/generated/thing.dart | 68 +++--- .../example/lib/main.dart | 18 +- 19 files changed, 724 insertions(+), 374 deletions(-) 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 26e9a05baaf8..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(mtewani): 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(mtewani): 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(mtewani): 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 db7ab2177f0a..573f3d4be8df 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,41 @@ 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, + ); } FirebaseDataConnect dataConnect; @@ -29,6 +46,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 +64,13 @@ class AddDirectorToMovieDirectedByInsert { AddDirectorToMovieDirectedByInsert({ required this.directedbyId, required this.movieId, - }) { - // TODO(mtewani): 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 +85,13 @@ class AddDirectorToMovieData { AddDirectorToMovieData({ required this.directedBy_insert, - }) { - // TODO(mtewani): 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 +105,7 @@ class AddDirectorToMovieVariablesPersonId { AddDirectorToMovieVariablesPersonId({ required this.id, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class AddDirectorToMovieVariables { @@ -99,6 +113,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 +141,5 @@ class AddDirectorToMovieVariables { AddDirectorToMovieVariables({ this.personId, this.movieId, - }) { - // TODO(mtewani): 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 dc16ba6e322f..276616609475 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,37 @@ 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, + ); } FirebaseDataConnect dataConnect; @@ -25,6 +40,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 +54,13 @@ class AddPersonPersonInsert { AddPersonPersonInsert({ required this.id, - }) { - // TODO(mtewani): 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 +74,13 @@ class AddPersonData { AddPersonData({ required this.person_insert, - }) { - // TODO(mtewani): 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 +97,5 @@ class AddPersonVariables { AddPersonVariables({ this.name, - }) { - // TODO(mtewani): 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 a852d95617de..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(mtewani): 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(mtewani): 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(mtewani): 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 eced35cf3d7a..896b5c4a7fa1 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,56 @@ 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 +59,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 +73,13 @@ class CreateMovieMovieInsert { CreateMovieMovieInsert({ required this.id, - }) { - // TODO(mtewani): 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 +93,7 @@ class CreateMovieData { CreateMovieData({ required this.movie_insert, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } class CreateMovieVariables { @@ -83,6 +107,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 +146,5 @@ class CreateMovieVariables { required this.genre, this.rating, this.description, - }) { - // TODO(mtewani): 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 49f0bc7e09ae..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(mtewani): 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(mtewani): 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(mtewani): 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 7140a4715b1d..3fa2d82547a2 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,17 +34,13 @@ 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() { - rating = - json['rating'] == null ? null : nativeFromJson(json['rating']); - } + .toList() {} Map toJson() { Map json = {}; @@ -43,10 +51,6 @@ class ListMoviesMovies { json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); - if (rating != null) { - json['rating'] = nativeToJson(rating); - } - return json; } @@ -54,15 +58,13 @@ class ListMoviesMovies { required this.id, required this.title, required this.directed_by, - this.rating, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + }); } 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']) {} @@ -76,14 +78,13 @@ class ListMoviesMoviesDirectedBy { ListMoviesMoviesDirectedBy({ required this.name, - }) { - // TODO(mtewani): 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)) @@ -99,7 +100,5 @@ class ListMoviesData { ListMoviesData({ required this.movies, - }) { - // TODO(mtewani): 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 a8560a27f571..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(mtewani): 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(mtewani): 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(mtewani): 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 f8e055affa2c..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(mtewani): 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(mtewani): 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..10b6ee917467 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,90 +1,197 @@ part of movies; + + + + + + + + +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 build() { + ListThingVariables vars=ListThingVariables(data: data,); + + return dataConnect.query("ListThing", dataDeserializer, varsSerializer, vars); + } +} class ListThing { String name = "ListThing"; ListThing({required this.dataConnect}); - - Deserializer dataDeserializer = (String json) => - ListThingData.fromJson(jsonDecode(json) as Map); - Serializer varsSerializer = - (ListThingVariables vars) => jsonEncode(vars.toJson()); - QueryRef ref({ - dynamic? data, - }) { - ListThingVariables vars = ListThingVariables( - data: AnyValue(data), - ); - - return dataConnect.query(this.name, dataDeserializer, varsSerializer, vars); + ListThingVariablesBuilder ref( + {dynamic? data,}) { + return ListThingVariablesBuilder(dataConnect, ); } - FirebaseDataConnect dataConnect; } + + + + class ListThingThings { - AnyValue title; + + + + + AnyValue title; + + + + // TODO(mtewani): Check what happens when an optional field is retrieved from json. + ListThingThings.fromJson(Map json): + title = + + AnyValue.fromJson(json['title']) + + + + { + + + + } - ListThingThings.fromJson(Map json) - : title = AnyValue.fromJson(json['title']) {} Map toJson() { Map json = {}; - - json['title'] = title.toJson(); - + + + json['title'] = + + title.toJson() + +; + + return json; } ListThingThings({ - required this.title, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + + required this.title, + + }); } + + + + + class ListThingData { - List things; + + + + + 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)) + .toList() + + + + + { + + + + } - ListThingData.fromJson(Map json) - : things = (json['things'] as List) - .map((e) => ListThingThings.fromJson(e)) - .toList() {} Map toJson() { Map json = {}; - - json['things'] = things.map((e) => e.toJson()).toList(); - + + + json['things'] = + + + things.map((e) => e.toJson()).toList() + + +; + + return json; } ListThingData({ - required this.things, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + + required this.things, + + }); } -class ListThingVariables { - AnyValue? data; - ListThingVariables.fromJson(Map json) { - data = json['data'] == null ? null : AnyValue.fromJson(json['data']); - } - Map toJson() { - Map json = {}; + + - if (data != null) { - json['data'] = data!.toJson(); +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']) + +; + + } + + Map toJson() { + Map json = {}; + + + if (data != null) { + json['data'] = + + data!.toJson() + +; + } + + return json; } ListThingVariables({ - this.data, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + + this.data, + + }); } + + + + + + + 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 66173aff1289..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(mtewani): 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(mtewani): 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..2a415c7991c6 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 @@ -1,16 +1,7 @@ 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,64 +20,76 @@ 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'; + +part 'list_timestamps.dart'; - ListThing get listThing { - return ListThing(dataConnect: dataConnect); - } + +class MoviesConnector { + AddPerson get addPerson { return AddPerson(dataConnect: dataConnect); } - + AddDirectorToMovie get addDirectorToMovie { return AddDirectorToMovie(dataConnect: dataConnect); } - + AddTimestamp get addTimestamp { return AddTimestamp(dataConnect: dataConnect); } - + AddDateAndTimestamp get addDateAndTimestamp { return AddDateAndTimestamp(dataConnect: dataConnect); } - + SeedMovies get seedMovies { return SeedMovies(dataConnect: dataConnect); } - + CreateMovie get createMovie { return CreateMovie(dataConnect: dataConnect); } - + DeleteMovie get deleteMovie { return DeleteMovie(dataConnect: dataConnect); } - + Thing get thing { return Thing(dataConnect: dataConnect); } - + SeedData get seedData { 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); } + static ConnectorConfig connectorConfig = ConnectorConfig( 'us-west2', @@ -97,9 +100,11 @@ 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..56a38c2633e4 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,58 +1,138 @@ part of movies; + + + + + + + + +class SeedDataVariablesBuilder { + + + FirebaseDataConnect dataConnect; + + SeedDataVariablesBuilder(this.dataConnect, ); + Deserializer dataDeserializer = (String json) => SeedDataData.fromJson(jsonDecode(json) as Map); + + MutationRef build() { + + return dataConnect.mutation("seedData", dataDeserializer, emptySerializer, null); + } +} class SeedData { String name = "seedData"; SeedData({required this.dataConnect}); - - Deserializer dataDeserializer = (String json) => - SeedDataData.fromJson(jsonDecode(json) as Map); - - MutationRef ref() { - return dataConnect.mutation( - this.name, dataDeserializer, emptySerializer, null); + SeedDataVariablesBuilder ref( + ) { + return SeedDataVariablesBuilder(dataConnect, ); } - FirebaseDataConnect dataConnect; } + + + + class SeedDataTheMatrix { - String id; + + + + + String id; + + + + // TODO(mtewani): Check what happens when an optional field is retrieved from json. + SeedDataTheMatrix.fromJson(Map json): + id = + + nativeFromJson(json['id']) + + + + { + + + + } - SeedDataTheMatrix.fromJson(Map json) - : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - json['id'] = nativeToJson(id); - + + + json['id'] = + + nativeToJson(id) + +; + + return json; } SeedDataTheMatrix({ - required this.id, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + + required this.id, + + }); } + + + + + class SeedDataData { - SeedDataTheMatrix the_matrix; + + + + + 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']) + + + + { + + + + } - SeedDataData.fromJson(Map json) - : the_matrix = SeedDataTheMatrix.fromJson(json['the_matrix']) {} Map toJson() { Map json = {}; - - json['the_matrix'] = the_matrix.toJson(); - + + + json['the_matrix'] = + + the_matrix.toJson() + +; + + return json; } SeedDataData({ - required this.the_matrix, - }) { - // TODO(mtewani): Only show this if there are optional fields. - } + + required this.the_matrix, + + }); } + + + + + + + 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 0f01ac6f417e..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(mtewani): 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(mtewani): 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(mtewani): 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(); From a3d176e7e537f0332a135c539630dbfad8e23b44 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 26 Sep 2024 13:50:23 +0100 Subject: [PATCH 6/8] Formatting --- .../example/lib/generated/list_movies.dart | 12 +- .../example/lib/generated/movies.dart | 32 ++--- .../example/lib/generated/seed_data.dart | 132 ++++-------------- 3 files changed, 56 insertions(+), 120 deletions(-) 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 3fa2d82547a2..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 @@ -34,13 +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 = {}; @@ -51,6 +56,10 @@ class ListMoviesMovies { json['directed_by'] = directed_by.map((e) => e.toJson()).toList(); + if (rating != null) { + json['rating'] = nativeToJson(rating); + } + return json; } @@ -58,6 +67,7 @@ class ListMoviesMovies { required this.id, required this.title, required this.directed_by, + this.rating, }); } 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 2a415c7991c6..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 @@ -1,4 +1,5 @@ library movies; + import 'package:firebase_data_connect/firebase_data_connect.dart'; import 'dart:convert'; @@ -30,66 +31,62 @@ part 'list_thing.dart'; part 'list_timestamps.dart'; - - class MoviesConnector { - AddPerson get addPerson { return AddPerson(dataConnect: dataConnect); } - + AddDirectorToMovie get addDirectorToMovie { return AddDirectorToMovie(dataConnect: dataConnect); } - + AddTimestamp get addTimestamp { return AddTimestamp(dataConnect: dataConnect); } - + AddDateAndTimestamp get addDateAndTimestamp { return AddDateAndTimestamp(dataConnect: dataConnect); } - + SeedMovies get seedMovies { return SeedMovies(dataConnect: dataConnect); } - + CreateMovie get createMovie { return CreateMovie(dataConnect: dataConnect); } - + DeleteMovie get deleteMovie { return DeleteMovie(dataConnect: dataConnect); } - + Thing get thing { return Thing(dataConnect: dataConnect); } - + SeedData get seedData { 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); } - static ConnectorConfig connectorConfig = ConnectorConfig( 'us-west2', @@ -107,4 +104,3 @@ class MoviesConnector { 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 56a38c2633e4..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,138 +1,68 @@ part of movies; - - - - - - - - class SeedDataVariablesBuilder { - - FirebaseDataConnect dataConnect; - - SeedDataVariablesBuilder(this.dataConnect, ); - Deserializer dataDeserializer = (String json) => SeedDataData.fromJson(jsonDecode(json) as Map); - + + SeedDataVariablesBuilder( + this.dataConnect, + ); + Deserializer dataDeserializer = (String json) => + SeedDataData.fromJson(jsonDecode(json) as Map); + MutationRef build() { - - return dataConnect.mutation("seedData", dataDeserializer, emptySerializer, null); + return dataConnect.mutation( + "seedData", dataDeserializer, emptySerializer, null); } } + class SeedData { String name = "seedData"; SeedData({required this.dataConnect}); - SeedDataVariablesBuilder ref( - ) { - return SeedDataVariablesBuilder(dataConnect, ); + SeedDataVariablesBuilder ref() { + return SeedDataVariablesBuilder( + dataConnect, + ); } + FirebaseDataConnect dataConnect; } - - - - 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']) - - - - { - - - - } + String id; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. + SeedDataTheMatrix.fromJson(Map json) + : id = nativeFromJson(json['id']) {} Map toJson() { Map json = {}; - - - json['id'] = - - nativeToJson(id) - -; - - + + json['id'] = nativeToJson(id); + return json; } SeedDataTheMatrix({ - - required this.id, - + required this.id, }); } - - - - - 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']) - - - - { - - - - } + 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']) {} Map toJson() { Map json = {}; - - - json['the_matrix'] = - - the_matrix.toJson() - -; - - + + json['the_matrix'] = the_matrix.toJson(); + return json; } SeedDataData({ - - required this.the_matrix, - + required this.the_matrix, }); } - - - - - - - From c881b981a1628bf4af391e0731375ca436f15ba4 Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 26 Sep 2024 13:56:40 +0100 Subject: [PATCH 7/8] Trigger Build From bff63a53c7712ba02fed7b441e340d863d8e25db Mon Sep 17 00:00:00 2001 From: Maneesh Tewani Date: Thu, 26 Sep 2024 15:08:43 +0100 Subject: [PATCH 8/8] Fixed --- .../lib/generated/add_director_to_movie.dart | 2 + .../example/lib/generated/add_person.dart | 1 + .../example/lib/generated/create_movie.dart | 2 + .../example/lib/generated/list_thing.dart | 197 +++++------------- 4 files changed, 57 insertions(+), 145 deletions(-) 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 573f3d4be8df..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 @@ -35,6 +35,8 @@ class AddDirectorToMovie { }) { return AddDirectorToMovieVariablesBuilder( dataConnect, + personId: personId, + movieId: movieId, ); } 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 276616609475..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 @@ -31,6 +31,7 @@ class AddPerson { }) { return AddPersonVariablesBuilder( dataConnect, + name: name, ); } 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 896b5c4a7fa1..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 @@ -50,6 +50,8 @@ class CreateMovie { title: title, releaseYear: releaseYear, genre: genre, + rating: rating, + description: description, ); } 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 10b6ee917467..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,197 +1,104 @@ part of movies; - - - - - - - - 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()); + + ListThingVariablesBuilder( + this.dataConnect, { + AnyValue? this.data, + }); + Deserializer dataDeserializer = (String json) => + ListThingData.fromJson(jsonDecode(json) as Map); + Serializer varsSerializer = + (ListThingVariables vars) => jsonEncode(vars.toJson()); QueryRef build() { - ListThingVariables vars=ListThingVariables(data: data,); + ListThingVariables vars = ListThingVariables( + data: data, + ); - return dataConnect.query("ListThing", 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, ); + ListThingVariablesBuilder ref({ + dynamic? data, + }) { + return ListThingVariablesBuilder( + dataConnect, + data: data, + ); } + FirebaseDataConnect dataConnect; } - - - - 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']) - - - - { - - - - } + AnyValue title; + // TODO(mtewani): Check what happens when an optional field is retrieved from json. + ListThingThings.fromJson(Map json) + : title = AnyValue.fromJson(json['title']) {} Map toJson() { Map json = {}; - - - json['title'] = - - title.toJson() - -; - - + + json['title'] = title.toJson(); + return json; } ListThingThings({ - - required this.title, - + required this.title, }); } - - - - - 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)) - .toList() - - - - - { - - - - } + 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)) + .toList() {} Map toJson() { Map json = {}; - - - json['things'] = - - - things.map((e) => e.toJson()).toList() - - -; - - + + json['things'] = things.map((e) => e.toJson()).toList(); + return json; } ListThingData({ - - required this.things, - + required this.things, }); } - - - - - 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']) - -; - - - } + 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']); + } Map toJson() { Map json = {}; - - - if (data != null) { - json['data'] = - - data!.toJson() - -; - } - - + + if (data != null) { + json['data'] = data!.toJson(); + } + return json; } ListThingVariables({ - - this.data, - + this.data, }); } - - - - - - -