From 50924a394e29d422130fdd9c06242b6e7740d81b Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Wed, 16 Feb 2022 09:33:09 -0800 Subject: [PATCH 1/4] Convert CRLF to LF --- .../lib/src/types/models/model_schema.dart | 200 +++++++++--------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/packages/amplify_core/lib/src/types/models/model_schema.dart b/packages/amplify_core/lib/src/types/models/model_schema.dart index bcd10ef107..196c7ad1e7 100644 --- a/packages/amplify_core/lib/src/types/models/model_schema.dart +++ b/packages/amplify_core/lib/src/types/models/model_schema.dart @@ -1,100 +1,100 @@ -/* - * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -library model_schema; - -import 'dart:convert'; - -import 'package:collection/collection.dart'; - -import 'auth_rule.dart'; -import 'model_field.dart'; - -class ModelSchema { - final String name; - final String? pluralName; //opt - final List? authRules; //opt - final Map? fields; - - const ModelSchema({ - required this.name, - this.pluralName, - this.authRules, - this.fields, - }); - - ModelSchema copyWith( - {String? name, - String? pluralName, - List? authRules, - Map? fields}) { - return ModelSchema( - name: name ?? this.name, - pluralName: pluralName ?? this.pluralName, - authRules: authRules ?? this.authRules, - fields: fields ?? this.fields); - } - - Map toMap() { - final map = { - 'name': name, - 'pluralName': pluralName, - 'authRules': authRules?.map((x) => x.toMap()).toList(), - 'fields': fields?.map((key, value) => MapEntry('$key', value.toMap())), - }; - return Map.from(map) - ..removeWhere((k, dynamic v) => v == null); - } - - factory ModelSchema.fromMap(Map map) { - return ModelSchema( - name: map['name'], - pluralName: map['pluralName'], - authRules: List.from( - map['authRules']?.map((dynamic x) => AuthRule.fromMap(x))), - fields: Map.from(map['fields']), - ); - } - - String toJson() => json.encode(toMap()); - - factory ModelSchema.fromJson(String source) => - ModelSchema.fromMap(json.decode(source)); - - @override - String toString() { - return 'ModelSchema(name: $name, pluralName: $pluralName, authRules: $authRules, fields: $fields)'; - } - - @override - bool operator ==(Object o) { - if (identical(this, o)) return true; - final collectionEquals = const DeepCollectionEquality().equals; - - return o is ModelSchema && - o.name == name && - o.pluralName == pluralName && - collectionEquals(o.authRules, authRules) && - collectionEquals(o.fields, fields); - } - - @override - int get hashCode { - return name.hashCode ^ - pluralName.hashCode ^ - authRules.hashCode ^ - fields.hashCode; - } -} +/* + * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +library model_schema; + +import 'dart:convert'; + +import 'package:collection/collection.dart'; + +import 'auth_rule.dart'; +import 'model_field.dart'; + +class ModelSchema { + final String name; + final String? pluralName; //opt + final List? authRules; //opt + final Map? fields; + + const ModelSchema({ + required this.name, + this.pluralName, + this.authRules, + this.fields, + }); + + ModelSchema copyWith( + {String? name, + String? pluralName, + List? authRules, + Map? fields}) { + return ModelSchema( + name: name ?? this.name, + pluralName: pluralName ?? this.pluralName, + authRules: authRules ?? this.authRules, + fields: fields ?? this.fields); + } + + Map toMap() { + final map = { + 'name': name, + 'pluralName': pluralName, + 'authRules': authRules?.map((x) => x.toMap()).toList(), + 'fields': fields?.map((key, value) => MapEntry('$key', value.toMap())), + }; + return Map.from(map) + ..removeWhere((k, dynamic v) => v == null); + } + + factory ModelSchema.fromMap(Map map) { + return ModelSchema( + name: map['name'], + pluralName: map['pluralName'], + authRules: List.from( + map['authRules']?.map((dynamic x) => AuthRule.fromMap(x))), + fields: Map.from(map['fields']), + ); + } + + String toJson() => json.encode(toMap()); + + factory ModelSchema.fromJson(String source) => + ModelSchema.fromMap(json.decode(source)); + + @override + String toString() { + return 'ModelSchema(name: $name, pluralName: $pluralName, authRules: $authRules, fields: $fields)'; + } + + @override + bool operator ==(Object o) { + if (identical(this, o)) return true; + final collectionEquals = const DeepCollectionEquality().equals; + + return o is ModelSchema && + o.name == name && + o.pluralName == pluralName && + collectionEquals(o.authRules, authRules) && + collectionEquals(o.fields, fields); + } + + @override + int get hashCode { + return name.hashCode ^ + pluralName.hashCode ^ + authRules.hashCode ^ + fields.hashCode; + } +} From 5c8c80d9ae4b58aada2fa72992ac3d613c781e36 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Wed, 16 Feb 2022 09:39:36 -0800 Subject: [PATCH 2/4] feat(datastore): implement ModelIndex --- packages/amplify_core/lib/amplify_core.dart | 1 + .../lib/src/types/models/model_index.dart | 89 +++++++++++++++++++ .../lib/src/types/models/model_schema.dart | 23 +++-- .../types/models/model_schema_definition.dart | 3 + .../lib/src/publicTypes.dart | 1 + 5 files changed, 110 insertions(+), 7 deletions(-) create mode 100644 packages/amplify_core/lib/src/types/models/model_index.dart diff --git a/packages/amplify_core/lib/amplify_core.dart b/packages/amplify_core/lib/amplify_core.dart index 1d331dd97a..8aa6691223 100644 --- a/packages/amplify_core/lib/amplify_core.dart +++ b/packages/amplify_core/lib/amplify_core.dart @@ -33,6 +33,7 @@ export 'src/types/models/model_association.dart'; export 'src/types/models/model_field.dart'; export 'src/types/models/model_field_definition.dart'; export 'src/types/models/model_field_type.dart'; +export 'src/types/models/model_index.dart'; export 'src/types/models/model_provider.dart'; export 'src/types/models/model_schema.dart'; export 'src/types/models/model_schema_definition.dart'; diff --git a/packages/amplify_core/lib/src/types/models/model_index.dart b/packages/amplify_core/lib/src/types/models/model_index.dart new file mode 100644 index 0000000000..b1e2da0e08 --- /dev/null +++ b/packages/amplify_core/lib/src/types/models/model_index.dart @@ -0,0 +1,89 @@ +/* + * Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +import 'dart:convert'; + +import 'package:amplify_core/amplify_core.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; + +/// Describe an index that is created by `@primaryKey` or `@index` directive, +/// and is listed in [ModelSchemaDefinition.indexes]. +@immutable +class ModelIndex { + /// Index name that is defined by the name parameter of `@index` directive in + /// a model schema. [name] will always be null when the index is representing + /// `@primaryKey` directive. + final String? name; + + /// An array of field names. The first field is always the field that is + /// annotated by` @primaryKey` or `@index` directive, and the remaining + /// fields are the fields specified by `sortKeyFields` parameter of + /// `@primaryKey` or `@index` directive. + final List fields; + + /// Constructor + const ModelIndex({ + required this.fields, + this.name, + }); + + /// Make a copy of an existing [ModelIndex] instance. + ModelIndex copyWith({ + List? fields, + String? name, + }) => + ModelIndex(fields: fields ?? this.fields, name: name ?? this.name); + + /// Generate a [Map] that represents [ModelIndex]. + Map toMap() { + final map = { + 'name': name, + 'fields': fields, + }; + + return map; + } + + /// Create an instance of [ModelIndex] from a [Map]. + factory ModelIndex.fromMap(Map map) => + ModelIndex(fields: map['fields'], name: map['name']); + + /// Create an instance of [ModelIndex] from a json + factory ModelIndex.fromJson(String source) => + ModelIndex.fromMap(jsonDecode(source)); + + /// Generate a json string that represents [ModelIndex] + String toJson() => jsonEncode(toMap()); + + @override + String toString() => 'ModelIndex(name: $name, fields: $fields)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + final listEquals = const DeepCollectionEquality().equals; + + return other is ModelIndex && + name == other.name && + listEquals(fields, other.fields); + } + + @override + int get hashCode => name.hashCode ^ fields.hashCode; +} diff --git a/packages/amplify_core/lib/src/types/models/model_schema.dart b/packages/amplify_core/lib/src/types/models/model_schema.dart index 196c7ad1e7..c3de047ef1 100644 --- a/packages/amplify_core/lib/src/types/models/model_schema.dart +++ b/packages/amplify_core/lib/src/types/models/model_schema.dart @@ -21,18 +21,21 @@ import 'package:collection/collection.dart'; import 'auth_rule.dart'; import 'model_field.dart'; +import 'model_index.dart'; class ModelSchema { final String name; final String? pluralName; //opt final List? authRules; //opt final Map? fields; + final List? indexes; const ModelSchema({ required this.name, this.pluralName, this.authRules, this.fields, + this.indexes, }); ModelSchema copyWith( @@ -41,10 +44,12 @@ class ModelSchema { List? authRules, Map? fields}) { return ModelSchema( - name: name ?? this.name, - pluralName: pluralName ?? this.pluralName, - authRules: authRules ?? this.authRules, - fields: fields ?? this.fields); + name: name ?? this.name, + pluralName: pluralName ?? this.pluralName, + authRules: authRules ?? this.authRules, + fields: fields ?? this.fields, + indexes: indexes ?? this.indexes, + ); } Map toMap() { @@ -53,6 +58,7 @@ class ModelSchema { 'pluralName': pluralName, 'authRules': authRules?.map((x) => x.toMap()).toList(), 'fields': fields?.map((key, value) => MapEntry('$key', value.toMap())), + 'indexes': indexes?.map((value) => value.toMap()).toList(), }; return Map.from(map) ..removeWhere((k, dynamic v) => v == null); @@ -65,6 +71,7 @@ class ModelSchema { authRules: List.from( map['authRules']?.map((dynamic x) => AuthRule.fromMap(x))), fields: Map.from(map['fields']), + indexes: List.from(map['indexes']), ); } @@ -75,7 +82,7 @@ class ModelSchema { @override String toString() { - return 'ModelSchema(name: $name, pluralName: $pluralName, authRules: $authRules, fields: $fields)'; + return 'ModelSchema(name: $name, pluralName: $pluralName, authRules: $authRules, fields: $fields, indexes: $indexes)'; } @override @@ -87,7 +94,8 @@ class ModelSchema { o.name == name && o.pluralName == pluralName && collectionEquals(o.authRules, authRules) && - collectionEquals(o.fields, fields); + collectionEquals(o.fields, fields) && + collectionEquals(o.indexes, indexes); } @override @@ -95,6 +103,7 @@ class ModelSchema { return name.hashCode ^ pluralName.hashCode ^ authRules.hashCode ^ - fields.hashCode; + fields.hashCode ^ + indexes.hashCode; } } diff --git a/packages/amplify_core/lib/src/types/models/model_schema_definition.dart b/packages/amplify_core/lib/src/types/models/model_schema_definition.dart index 85eb072503..dc0e32f94a 100644 --- a/packages/amplify_core/lib/src/types/models/model_schema_definition.dart +++ b/packages/amplify_core/lib/src/types/models/model_schema_definition.dart @@ -16,12 +16,14 @@ import 'auth_rule.dart'; import 'model_field.dart'; import 'model_field_definition.dart'; +import 'model_index.dart'; import 'model_schema.dart'; class ModelSchemaDefinition { late String name; String? pluralName; List? authRules; + List? indexes; late Map fields; ModelSchemaDefinition() { @@ -38,6 +40,7 @@ class ModelSchemaDefinition { pluralName: pluralName, authRules: authRules, fields: fields, + indexes: indexes, ); } } diff --git a/packages/amplify_datastore_plugin_interface/lib/src/publicTypes.dart b/packages/amplify_datastore_plugin_interface/lib/src/publicTypes.dart index 5c94c5fe0d..c6fb675b6e 100644 --- a/packages/amplify_datastore_plugin_interface/lib/src/publicTypes.dart +++ b/packages/amplify_datastore_plugin_interface/lib/src/publicTypes.dart @@ -17,6 +17,7 @@ export 'package:amplify_core/src/types/models/model.dart'; export 'package:amplify_core/src/types/models/model_field.dart'; export 'package:amplify_core/src/types/models/model_field_definition.dart'; export 'package:amplify_core/src/types/models/model_field_type.dart'; +export 'package:amplify_core/src/types/models/model_index.dart'; export 'package:amplify_core/src/types/models/model_provider.dart'; export 'package:amplify_core/src/types/models/model_schema.dart'; export 'package:amplify_core/src/types/models/model_schema_definition.dart'; From b183d5dd77bda8eee9bf0cef2e6dec1326ba9ad8 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Wed, 16 Feb 2022 10:05:22 -0800 Subject: [PATCH 3/4] chore(datastore): update tests to cover model indexes --- .../test/amplify_modelschema_test.dart | 88 +++++++++++-- .../test/amplify_modelschema_to_map_test.dart | 19 +++ .../test/testData/Address.dart | 18 ++- .../test/testData/Blog.dart | 25 ++-- .../test/testData/Comment.dart | 23 ++-- .../test/testData/Contact.dart | 23 ++-- .../test/testData/ModelProvider.dart | 15 ++- .../test/testData/Person.dart | 121 ++++-------------- .../test/testData/Phone.dart | 14 +- .../test/testData/Post.dart | 29 +++-- .../test/testData/PostAuthComplex.dart | 15 ++- .../test/testData/testData_schema.graphql | 20 +-- 12 files changed, 232 insertions(+), 178 deletions(-) diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart index 50112b0683..a863311853 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_test.dart @@ -28,9 +28,9 @@ void main() { test('Blog codegen model generates modelschema with proper fields', () async { /* type Blog @model { - id: ID! + id: ID! @primaryKey name: String! - posts: [Post] @connection(keyName: "byBlog", fields: ["id"]) + posts: [Post] @hasMany(indexName: "byBlog", fields: ["id"]) } */ @@ -70,13 +70,33 @@ void main() { associatedType: Post.BLOG.fieldType!.ofModelName))); }); + test('Blog codegen model generates modelschema with proper indexes', + () async { + /* + type Blog @model { + id: ID! @primaryKey + name: String! + posts: [Post] @hasMany(indexName: "byBlog", fields: ["id"]) + } + */ + + ModelSchema blogSchema = Blog.schema; + + expect(blogSchema.name, "Blog"); + expect(blogSchema.pluralName, "Blogs"); + + expect(blogSchema.indexes!, [ + ModelIndex(fields: ["id"]) + ]); + }); + test('Comment codegen model generates modelschema with proper fields', () async { /* - type Comment @model @key(name: "byPost", fields: ["postID", "content"]) { + type Comment @model { id: ID! - postID: ID! - post: Post @connection(fields: ["postID"]) + postID: ID! @index(name: "byPost", sortKeyFields: ["content"]) + post: Post @belongsTo(fields: ["postID"]) content: String! } */ @@ -115,14 +135,38 @@ void main() { isArray: false)); }); + test('Comment codegen model generates modelschema with proper indexes', + () async { + /* + type Comment @model { + id: ID! + postID: ID! @index(name: "byPost", sortKeyFields: ["content"]) + post: Post @belongsTo(fields: ["postID"]) + content: String! + } + */ + + ModelSchema commentSchema = Comment.schema; + + expect(commentSchema.name, "Comment"); + expect(commentSchema.pluralName, "Comments"); + + expect(commentSchema.indexes!, [ + ModelIndex(name: "byPost", fields: ["postID", "content"]) + ]); + }); + test('Post codegen model generates modelschema with proper fields', () async { /* - type Post @model @key(name: "byBlog", fields: ["blogID"]) { + type Post @model { id: ID! title: String! - blogID: ID! - blog: Blog @connection(fields: ["blogID"]) - comments: [Comment] @connection(keyName: "byPost", fields: ["id"]) + rating: Int! + created: AWSDateTime + likeCount: Int + blogID: ID! @index(name: "byBlog") + blog: Blog @belongsTo(fields: ["blogID"]) + comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"]) } */ @@ -160,6 +204,31 @@ void main() { targetName: "blogID"))); }); + test('Post codegen model generates modelschema with proper indexes', + () async { + /* + type Post @model { + id: ID! + title: String! + rating: Int! + created: AWSDateTime + likeCount: Int + blogID: ID! @index(name: "byBlog") + blog: Blog @belongsTo(fields: ["blogID"]) + comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"]) + } + */ + + ModelSchema postSchema = Post.schema; + + expect(postSchema.name, "Post"); + expect(postSchema.pluralName, "Posts"); + + expect(postSchema.indexes!, [ + ModelIndex(name: "byBlog", fields: ["blogID"]) + ]); + }); + test('PostAuthComplex codegen model generates modelschema with proper fields', () async { /* @@ -185,6 +254,7 @@ void main() { authStrategy: AuthStrategy.OWNER, ownerField: "owner", identityClaim: "cognito:username", + provider: AuthRuleProvider.USERPOOLS, operations: [ ModelOperation.CREATE, ModelOperation.UPDATE, diff --git a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart index 7f03c3f595..b70c20cee0 100644 --- a/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart +++ b/packages/amplify_datastore_plugin_interface/test/amplify_modelschema_to_map_test.dart @@ -26,6 +26,12 @@ void main() { expect(map, { 'name': "Blog", 'pluralName': "Blogs", + 'indexes': [ + { + 'name': null, + 'fields': ['id'] + } + ], 'fields': { 'id': { 'name': "id", @@ -79,6 +85,12 @@ void main() { expect(map, { 'name': 'Comment', 'pluralName': 'Comments', + 'indexes': [ + { + 'name': 'byPost', + 'fields': ['postID', 'content'] + } + ], 'fields': { 'id': { 'name': 'id', @@ -131,6 +143,12 @@ void main() { expect(map, { 'name': 'Post', 'pluralName': 'Posts', + 'indexes': [ + { + 'name': 'byBlog', + 'fields': ['blogID'] + } + ], 'fields': { 'id': { 'name': 'id', @@ -222,6 +240,7 @@ void main() { 'authStrategy': 'OWNER', 'ownerField': 'owner', 'identityClaim': 'cognito:username', + 'provider': 'USERPOOLS', 'operations': ['CREATE', 'UPDATE', 'DELETE', 'READ'] } ], diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Address.dart b/packages/amplify_datastore_plugin_interface/test/testData/Address.dart index adbc9d186b..2af6102c60 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Address.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Address.dart @@ -13,12 +13,16 @@ * permissions and limitations under the License. */ -// ignore_for_file: public_member_api_docs +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Address type in your schema. */ +/// This is an auto generated class representing the Address type in your schema. @immutable class Address { final String? _line1; @@ -31,7 +35,7 @@ class Address { try { return _line1!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -48,7 +52,7 @@ class Address { try { return _city!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -61,7 +65,7 @@ class Address { try { return _state!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -74,7 +78,7 @@ class Address { try { return _postalCode!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -129,7 +133,7 @@ class Address { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Address {"); buffer.write("line1=" + "$_line1" + ", "); diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart b/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart index b4460fd998..1a7d67bef1 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Blog.dart @@ -13,18 +13,21 @@ * permissions and limitations under the License. */ -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; +import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Blog type in your schema. */ +/// This is an auto generated class representing the Blog type in your schema. @immutable class Blog extends Model { - static const classType = const _BlogModelType(); + static const classType = _BlogModelType(); final String id; final String? _name; final List? _posts; @@ -43,7 +46,7 @@ class Blog extends Model { try { return _name!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -96,7 +99,7 @@ class Blog extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Blog {"); buffer.write("id=" + "$id" + ", "); @@ -123,7 +126,7 @@ class Blog extends Model { ? (json['posts'] as List) .where((e) => e?['serializedData'] != null) .map((e) => Post.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _createdAt = json['createdAt'] != null @@ -152,6 +155,10 @@ class Blog extends Model { modelSchemaDefinition.name = "Blog"; modelSchemaDefinition.pluralName = "Blogs"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: ["id"], name: null) + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart b/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart index 09592f8c7e..639dacdbfd 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Comment.dart @@ -13,17 +13,20 @@ * permissions and limitations under the License. */ -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:flutter/foundation.dart'; +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; +import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Comment type in your schema. */ +/// This is an auto generated class representing the Comment type in your schema. @immutable class Comment extends Model { - static const classType = const _CommentModelType(); + static const classType = _CommentModelType(); final String id; final Post? _post; final String? _content; @@ -46,7 +49,7 @@ class Comment extends Model { try { return _content!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -93,7 +96,7 @@ class Comment extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Comment {"); buffer.write("id=" + "$id" + ", "); @@ -120,7 +123,7 @@ class Comment extends Model { : id = json['id'], _post = json['post']?['serializedData'] != null ? Post.fromJson( - new Map.from(json['post']['serializedData'])) + Map.from(json['post']['serializedData'])) : null, _content = json['content'], _createdAt = json['createdAt'] != null @@ -149,6 +152,10 @@ class Comment extends Model { modelSchemaDefinition.name = "Comment"; modelSchemaDefinition.pluralName = "Comments"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: ["postID", "content"], name: "byPost") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo( diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart b/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart index e55bb5de93..dff9c20247 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Contact.dart @@ -13,15 +13,18 @@ * permissions and limitations under the License. */ -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; +import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Contact type in your schema. */ +/// This is an auto generated class representing the Contact type in your schema. @immutable class Contact { final String? _email; @@ -32,7 +35,7 @@ class Contact { try { return _email!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -45,7 +48,7 @@ class Contact { try { return _phone!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -94,7 +97,7 @@ class Contact { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Contact {"); buffer.write("email=" + "$_email" + ", "); @@ -119,13 +122,13 @@ class Contact { : _email = json['email'], _phone = json['phone']?['serializedData'] != null ? Phone.fromJson( - new Map.from(json['phone']['serializedData'])) + Map.from(json['phone']['serializedData'])) : null, _mailingAddresses = json['mailingAddresses'] is List ? (json['mailingAddresses'] as List) .where((e) => e != null) .map((e) => Address.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null; diff --git a/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart b/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart index 0039214f48..f87a8dfbac 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/ModelProvider.dart @@ -13,18 +13,21 @@ * permissions and limitations under the License. */ -// ignore_for_file: public_member_api_docs +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code -import 'Address.dart'; +import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'Blog.dart'; import 'Comment.dart'; +import 'Post.dart'; +import 'PostAuthComplex.dart'; +import 'Address.dart'; import 'Contact.dart'; import 'Person.dart'; import 'Phone.dart'; -import 'Post.dart'; -import 'PostAuthComplex.dart'; export 'Address.dart'; export 'Blog.dart'; @@ -37,7 +40,7 @@ export 'PostAuthComplex.dart'; class ModelProvider implements ModelProviderInterface { @override - String version = "836a1f8cc4a4adc493165acc7168289e"; + String version = "17ca7e949658b1d89af21147c8fb3455"; @override List modelSchemas = [ Blog.schema, diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Person.dart b/packages/amplify_datastore_plugin_interface/test/testData/Person.dart index 74badaf7fe..fd2d6eb0e5 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Person.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Person.dart @@ -13,37 +13,29 @@ * permissions and limitations under the License. */ -// ignore_for_file: public_member_api_docs +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Person type in your schema. */ +/// This is an auto generated class representing the Person type in your schema. @immutable -class Person extends Model { - static const classType = const _PersonModelType(); - final String id; +class Person { final String? _name; final List
? _propertiesAddresses; final Contact? _contact; - final TemporalDateTime? _createdAt; - final TemporalDateTime? _updatedAt; - - @override - getInstanceType() => classType; - - @override - String getId() { - return id; - } String get name { try { return _name!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -60,7 +52,7 @@ class Person extends Model { try { return _contact!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -69,34 +61,16 @@ class Person extends Model { } } - TemporalDateTime? get createdAt { - return _createdAt; - } - - TemporalDateTime? get updatedAt { - return _updatedAt; - } - - const Person._internal( - {required this.id, - required name, - propertiesAddresses, - required contact, - createdAt, - updatedAt}) + const Person._internal({required name, propertiesAddresses, required contact}) : _name = name, _propertiesAddresses = propertiesAddresses, - _contact = contact, - _createdAt = createdAt, - _updatedAt = updatedAt; + _contact = contact; factory Person( - {String? id, - required String name, + {required String name, List
? propertiesAddresses, required Contact contact}) { return Person._internal( - id: id == null ? UUID.getUUID() : id, name: name, propertiesAddresses: propertiesAddresses != null ? List
.unmodifiable(propertiesAddresses) @@ -112,7 +86,6 @@ class Person extends Model { bool operator ==(Object other) { if (identical(other, this)) return true; return other is Person && - id == other.id && _name == other._name && DeepCollectionEquality() .equals(_propertiesAddresses, other._propertiesAddresses) && @@ -124,85 +97,58 @@ class Person extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Person {"); - buffer.write("id=" + "$id" + ", "); buffer.write("name=" + "$_name" + ", "); buffer.write("propertiesAddresses=" + (_propertiesAddresses != null ? _propertiesAddresses!.toString() : "null") + ", "); - buffer.write( - "contact=" + (_contact != null ? _contact!.toString() : "null") + ", "); - buffer.write("createdAt=" + - (_createdAt != null ? _createdAt!.format() : "null") + - ", "); - buffer.write( - "updatedAt=" + (_updatedAt != null ? _updatedAt!.format() : "null")); + buffer + .write("contact=" + (_contact != null ? _contact!.toString() : "null")); buffer.write("}"); return buffer.toString(); } Person copyWith( - {String? id, - String? name, - List
? propertiesAddresses, - Contact? contact}) { + {String? name, List
? propertiesAddresses, Contact? contact}) { return Person._internal( - id: id ?? this.id, name: name ?? this.name, propertiesAddresses: propertiesAddresses ?? this.propertiesAddresses, contact: contact ?? this.contact); } Person.fromJson(Map json) - : id = json['id'], - _name = json['name'], + : _name = json['name'], _propertiesAddresses = json['propertiesAddresses'] is List ? (json['propertiesAddresses'] as List) .where((e) => e != null) .map((e) => Address.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _contact = json['contact']?['serializedData'] != null - ? Contact.fromJson(new Map.from( - json['contact']['serializedData'])) - : null, - _createdAt = json['createdAt'] != null - ? TemporalDateTime.fromString(json['createdAt']) - : null, - _updatedAt = json['updatedAt'] != null - ? TemporalDateTime.fromString(json['updatedAt']) + ? Contact.fromJson( + Map.from(json['contact']['serializedData'])) : null; Map toJson() => { - 'id': id, 'name': _name, 'propertiesAddresses': _propertiesAddresses?.map((Address? e) => e?.toJson()).toList(), - 'contact': _contact?.toJson(), - 'createdAt': _createdAt?.format(), - 'updatedAt': _updatedAt?.format() + 'contact': _contact?.toJson() }; - static final QueryField ID = QueryField(fieldName: "person.id"); - static final QueryField NAME = QueryField(fieldName: "name"); - static final QueryField PROPERTIESADDRESSES = - QueryField(fieldName: "propertiesAddresses"); - static final QueryField CONTACT = QueryField(fieldName: "contact"); static var schema = Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) { modelSchemaDefinition.name = "Person"; modelSchemaDefinition.pluralName = "People"; - modelSchemaDefinition.addField(ModelFieldDefinition.id()); - - modelSchemaDefinition.addField(ModelFieldDefinition.field( - key: Person.NAME, + modelSchemaDefinition.addField(ModelFieldDefinition.customTypeField( + fieldName: 'name', isRequired: true, ofType: ModelFieldType(ModelFieldTypeEnum.string))); @@ -218,26 +164,5 @@ class Person extends Model { isRequired: true, ofType: ModelFieldType(ModelFieldTypeEnum.embedded, ofCustomTypeName: 'Contact'))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'createdAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); - - modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField( - fieldName: 'updatedAt', - isRequired: false, - isReadOnly: true, - ofType: ModelFieldType(ModelFieldTypeEnum.dateTime))); }); } - -class _PersonModelType extends ModelType { - const _PersonModelType(); - - @override - Person fromJson(Map jsonData) { - return Person.fromJson(jsonData); - } -} diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart b/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart index 2b80e2a80e..e966ca66e0 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Phone.dart @@ -13,12 +13,16 @@ * permissions and limitations under the License. */ -// ignore_for_file: public_member_api_docs +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Phone type in your schema. */ +/// This is an auto generated class representing the Phone type in your schema. @immutable class Phone { final String? _country; @@ -28,7 +32,7 @@ class Phone { try { return _country!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -41,7 +45,7 @@ class Phone { try { return _number!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -75,7 +79,7 @@ class Phone { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Phone {"); buffer.write("country=" + "$_country" + ", "); diff --git a/packages/amplify_datastore_plugin_interface/test/testData/Post.dart b/packages/amplify_datastore_plugin_interface/test/testData/Post.dart index 3ca5c324e4..453cd206d9 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/Post.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/Post.dart @@ -13,18 +13,21 @@ * permissions and limitations under the License. */ -import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; -import 'package:collection/collection.dart'; -import 'package:flutter/foundation.dart'; +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis -// ignore_for_file: public_member_api_docs +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'ModelProvider.dart'; +import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the Post type in your schema. */ +/// This is an auto generated class representing the Post type in your schema. @immutable class Post extends Model { - static const classType = const _PostModelType(); + static const classType = _PostModelType(); final String id; final String? _title; final int? _rating; @@ -47,7 +50,7 @@ class Post extends Model { try { return _title!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -60,7 +63,7 @@ class Post extends Model { try { return _rating!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -153,7 +156,7 @@ class Post extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("Post {"); buffer.write("id=" + "$id" + ", "); @@ -204,13 +207,13 @@ class Post extends Model { _likeCount = (json['likeCount'] as num?)?.toInt(), _blog = json['blog']?['serializedData'] != null ? Blog.fromJson( - new Map.from(json['blog']['serializedData'])) + Map.from(json['blog']['serializedData'])) : null, _comments = json['comments'] is List ? (json['comments'] as List) .where((e) => e?['serializedData'] != null) .map((e) => Comment.fromJson( - new Map.from(e['serializedData']))) + Map.from(e['serializedData']))) .toList() : null, _createdAt = json['createdAt'] != null @@ -250,6 +253,10 @@ class Post extends Model { modelSchemaDefinition.name = "Post"; modelSchemaDefinition.pluralName = "Posts"; + modelSchemaDefinition.indexes = [ + ModelIndex(fields: ["blogID"], name: "byBlog") + ]; + modelSchemaDefinition.addField(ModelFieldDefinition.id()); modelSchemaDefinition.addField(ModelFieldDefinition.field( diff --git a/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart b/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart index 51d41060a5..1bf4dd1c2f 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart +++ b/packages/amplify_datastore_plugin_interface/test/testData/PostAuthComplex.dart @@ -13,15 +13,19 @@ * permissions and limitations under the License. */ -// ignore_for_file: public_member_api_docs +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, file_names, unnecessary_new, prefer_if_null_operators, prefer_const_constructors, slash_for_doc_comments, annotate_overrides, non_constant_identifier_names, unnecessary_string_interpolations, prefer_adjacent_string_concatenation, unnecessary_const, dead_code import 'package:amplify_datastore_plugin_interface/amplify_datastore_plugin_interface.dart'; import 'package:flutter/foundation.dart'; -/** This is an auto generated class representing the PostAuthComplex type in your schema. */ +/// This is an auto generated class representing the PostAuthComplex type in your schema. @immutable class PostAuthComplex extends Model { - static const classType = const _PostAuthComplexModelType(); + static const classType = _PostAuthComplexModelType(); final String id; final String? _title; final String? _owner; @@ -40,7 +44,7 @@ class PostAuthComplex extends Model { try { return _title!; } catch (e) { - throw new DataStoreException( + throw DataStoreException( DataStoreExceptionMessages .codeGenRequiredFieldForceCastExceptionMessage, recoverySuggestion: DataStoreExceptionMessages @@ -91,7 +95,7 @@ class PostAuthComplex extends Model { @override String toString() { - var buffer = new StringBuffer(); + var buffer = StringBuffer(); buffer.write("PostAuthComplex {"); buffer.write("id=" + "$id" + ", "); @@ -146,6 +150,7 @@ class PostAuthComplex extends Model { authStrategy: AuthStrategy.OWNER, ownerField: "owner", identityClaim: "cognito:username", + provider: AuthRuleProvider.USERPOOLS, operations: [ ModelOperation.CREATE, ModelOperation.UPDATE, diff --git a/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql b/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql index afe5b0e49d..67ed6171a9 100644 --- a/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql +++ b/packages/amplify_datastore_plugin_interface/test/testData/testData_schema.graphql @@ -1,19 +1,19 @@ # This schema can be used to regenerate the test models that are in this folder type Blog @model { - id: ID! + id: ID! @primaryKey name: String! - posts: [Post] @connection(keyName: "byBlog", fields: ["id"]) + posts: [Post] @hasMany(indexName: "byBlog", fields: ["id"]) } -type Post @model @key(name: "byBlog", fields: ["blogID"]) { +type Post @model { id: ID! title: String! rating: Int! created: AWSDateTime likeCount: Int - blogID: ID! - blog: Blog @connection(fields: ["blogID"]) - comments: [Comment] @connection(keyName: "byPost", fields: ["id"]) + blogID: ID! @index(name: "byBlog") + blog: Blog @belongsTo(fields: ["blogID"]) + comments: [Comment] @hasMany(indexName: "byPost", fields: ["id"]) } type PostAuthComplex @@ -28,10 +28,10 @@ type PostAuthComplex owner: String } -type Comment @model @key(name: "byPost", fields: ["postID", "content"]) { +type Comment @model { id: ID! - postID: ID! - post: Post @connection(fields: ["postID"]) + postID: ID! @index(name: "byPost", sortKeyFields: ["content"]) + post: Post @belongsTo(fields: ["postID"]) content: String! } @@ -58,4 +58,4 @@ type Contact { email: String! phone: Phone! mailingAddresses: [Address] -} \ No newline at end of file +} From 743ade3025a2381ded5b8c9997eb17b838e95b8f Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Wed, 2 Mar 2022 12:23:23 -0800 Subject: [PATCH 4/4] Improve doc --- packages/amplify_core/lib/src/types/models/model_index.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/amplify_core/lib/src/types/models/model_index.dart b/packages/amplify_core/lib/src/types/models/model_index.dart index b1e2da0e08..b3200b2c8e 100644 --- a/packages/amplify_core/lib/src/types/models/model_index.dart +++ b/packages/amplify_core/lib/src/types/models/model_index.dart @@ -19,8 +19,10 @@ import 'package:amplify_core/amplify_core.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; -/// Describe an index that is created by `@primaryKey` or `@index` directive, +/// {@template model_index} +/// Describes an index that is created by `@primaryKey` or `@index` directive, /// and is listed in [ModelSchemaDefinition.indexes]. +/// {@endtemplate} @immutable class ModelIndex { /// Index name that is defined by the name parameter of `@index` directive in @@ -34,7 +36,7 @@ class ModelIndex { /// `@primaryKey` or `@index` directive. final List fields; - /// Constructor + /// {@macro model_index} const ModelIndex({ required this.fields, this.name,