Skip to content

Commit

Permalink
fix(api): model helpers use targetNames in schemas with CPK enabled (#…
Browse files Browse the repository at this point in the history
…2559)

* fix(api): model helpers can use targetNames in schemas with CPK enabled

* address some comments
  • Loading branch information
Travis Sheppard authored and dnys1 committed Jan 12, 2023
1 parent 1d06d0c commit c63e52f
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ void main() {
'isReadOnly': false,
'association': {
'associationType': 'BelongsTo',
// TODO(Jordan-Nelson): Remove `targetName` when API category has been
// updated to support CPK changes.
'targetName': 'postID',
'targetNames': ['postID'],
'associatedType': 'Post'
},
Expand Down Expand Up @@ -214,9 +211,6 @@ void main() {
'isReadOnly': false,
'association': {
'associationType': 'BelongsTo',
// TODO(Jordan-Nelson): Remove `targetName` when API category has been
// updated to support CPK changes.
'targetName': 'blogID',
'targetNames': ['blogID'],
'associatedType': 'Blog'
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify_test/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ analyzer:
errors:
public_member_api_docs: ignore
exclude:
- lib/test_models/*
- lib/test_models/**
10 changes: 7 additions & 3 deletions packages/amplify_test/lib/test_models/Blog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ class Blog extends Model {
static final QueryField FILES = QueryField(fieldName: "files");
static final QueryField POSTS = QueryField(
fieldName: "posts",
fieldType: ModelFieldType(ModelFieldTypeEnum.model,
ofModelName: (Post).toString()));
fieldType: ModelFieldType(ModelFieldTypeEnum.model, ofModelName: 'Post'));
static var schema =
Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) {
modelSchemaDefinition.name = "Blog";
Expand Down Expand Up @@ -262,7 +261,7 @@ class Blog extends Model {
modelSchemaDefinition.addField(ModelFieldDefinition.hasMany(
key: Blog.POSTS,
isRequired: false,
ofModelName: (Post).toString(),
ofModelName: 'Post',
associatedKey: Post.BLOG));

modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField(
Expand All @@ -280,6 +279,11 @@ class _BlogModelType extends ModelType<Blog> {
Blog fromJson(Map<String, dynamic> jsonData) {
return Blog.fromJson(jsonData);
}

@override
String modelName() {
return 'Blog';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
15 changes: 8 additions & 7 deletions packages/amplify_test/lib/test_models/Comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ class Comment extends Model {
static final QueryField ID = QueryField(fieldName: "id");
static final QueryField POST = QueryField(
fieldName: "post",
fieldType: ModelFieldType(ModelFieldTypeEnum.model,
ofModelName: (Post).toString()));
fieldType: ModelFieldType(ModelFieldTypeEnum.model, ofModelName: 'Post'));
static final QueryField CONTENT = QueryField(fieldName: "content");
static var schema =
Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) {
Expand All @@ -173,11 +172,8 @@ class Comment extends Model {
modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo(
key: Comment.POST,
isRequired: false,
// TODO(Jordan-Nelson): Remove `targetName` when API category has been
// updated to support CPK changes. This was added manually.
targetName: "postID",
targetNames: ["postID"],
ofModelName: (Post).toString()));
targetNames: ['postID'],
ofModelName: 'Post'));

modelSchemaDefinition.addField(ModelFieldDefinition.field(
key: Comment.CONTENT,
Expand Down Expand Up @@ -205,6 +201,11 @@ class _CommentModelType extends ModelType<Comment> {
Comment fromJson(Map<String, dynamic> jsonData) {
return Comment.fromJson(jsonData);
}

@override
String modelName() {
return 'Comment';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify_test/lib/test_models/Inventory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ class _InventoryModelType extends ModelType<Inventory> {
Inventory fromJson(Map<String, dynamic> jsonData) {
return Inventory.fromJson(jsonData);
}

@override
String modelName() {
return 'Inventory';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify_test/lib/test_models/Person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ class _PersonModelType extends ModelType<Person> {
Person fromJson(Map<String, dynamic> jsonData) {
return Person.fromJson(jsonData);
}

@override
String modelName() {
return 'Person';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
21 changes: 11 additions & 10 deletions packages/amplify_test/lib/test_models/Post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,11 @@ class Post extends Model {
static final QueryField LIKECOUNT = QueryField(fieldName: "likeCount");
static final QueryField BLOG = QueryField(
fieldName: "blog",
fieldType: ModelFieldType(ModelFieldTypeEnum.model,
ofModelName: (Blog).toString()));
fieldType: ModelFieldType(ModelFieldTypeEnum.model, ofModelName: 'Blog'));
static final QueryField COMMENTS = QueryField(
fieldName: "comments",
fieldType: ModelFieldType(ModelFieldTypeEnum.model,
ofModelName: (Comment).toString()));
fieldType:
ModelFieldType(ModelFieldTypeEnum.model, ofModelName: 'Comment'));
static var schema =
Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) {
modelSchemaDefinition.name = "Post";
Expand Down Expand Up @@ -320,16 +319,13 @@ class Post extends Model {
modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo(
key: Post.BLOG,
isRequired: false,
// TODO(Jordan-Nelson): Remove `targetName` when API category has been
// updated to support CPK changes. This was added manually.
targetName: "blogID",
targetNames: ["blogID"],
ofModelName: (Blog).toString()));
targetNames: ['blogID'],
ofModelName: 'Blog'));

modelSchemaDefinition.addField(ModelFieldDefinition.hasMany(
key: Post.COMMENTS,
isRequired: false,
ofModelName: (Comment).toString(),
ofModelName: 'Comment',
associatedKey: Comment.POST));

modelSchemaDefinition.addField(ModelFieldDefinition.nonQueryField(
Expand All @@ -353,6 +349,11 @@ class _PostModelType extends ModelType<Post> {
Post fromJson(Map<String, dynamic> jsonData) {
return Post.fromJson(jsonData);
}

@override
String modelName() {
return 'Post';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify_test/lib/test_models/PostWithAuthRules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ class _PostWithAuthRulesModelType extends ModelType<PostWithAuthRules> {
PostWithAuthRules fromJson(Map<String, dynamic> jsonData) {
return PostWithAuthRules.fromJson(jsonData);
}

@override
String modelName() {
return 'PostWithAuthRules';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify_test/lib/test_models/Product.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ class _ProductModelType extends ModelType<Product> {
Product fromJson(Map<String, dynamic> jsonData) {
return Product.fromJson(jsonData);
}

@override
String modelName() {
return 'Product';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ class _StringListTypeModelModelType extends ModelType<StringListTypeModel> {
StringListTypeModel fromJson(Map<String, dynamic> jsonData) {
return StringListTypeModel.fromJson(jsonData);
}

@override
String modelName() {
return 'StringListTypeModel';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
5 changes: 5 additions & 0 deletions packages/amplify_test/lib/test_models/Warehouse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ class _WarehouseModelType extends ModelType<Warehouse> {
Warehouse fromJson(Map<String, dynamic> jsonData) {
return Warehouse.fromJson(jsonData);
}

@override
String modelName() {
return 'Warehouse';
}
}

/// This is an auto generated class representing the model identifier
Expand Down
Loading

0 comments on commit c63e52f

Please sign in to comment.