Skip to content

Commit 6bf2156

Browse files
committed
fix(appsync-modelgen-plugin): revert not removing the additional fields in join for many-to-many
1 parent cb476b0 commit 6bf2156

File tree

3 files changed

+15
-55
lines changed

3 files changed

+15
-55
lines changed

packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-dart-visitor.test.ts.snap

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,6 @@ class _TagModelType extends ModelType<Tag> {
12791279
class PostTags extends Model {
12801280
static const classType = const _PostTagsModelType();
12811281
final String id;
1282-
final String postID;
1283-
final String tagID;
12841282
final Post post;
12851283
final Tag tag;
12861284

@@ -1293,24 +1291,11 @@ class PostTags extends Model {
12931291
}
12941292

12951293
const PostTags._internal(
1296-
{@required this.id,
1297-
@required this.postID,
1298-
@required this.tagID,
1299-
@required this.post,
1300-
@required this.tag});
1294+
{@required this.id, @required this.post, @required this.tag});
13011295

1302-
factory PostTags(
1303-
{String id,
1304-
@required String postID,
1305-
@required String tagID,
1306-
@required Post post,
1307-
@required Tag tag}) {
1296+
factory PostTags({String id, @required Post post, @required Tag tag}) {
13081297
return PostTags._internal(
1309-
id: id == null ? UUID.getUUID() : id,
1310-
postID: postID,
1311-
tagID: tagID,
1312-
post: post,
1313-
tag: tag);
1298+
id: id == null ? UUID.getUUID() : id, post: post, tag: tag);
13141299
}
13151300

13161301
bool equals(Object other) {
@@ -1322,8 +1307,6 @@ class PostTags extends Model {
13221307
if (identical(other, this)) return true;
13231308
return other is PostTags &&
13241309
id == other.id &&
1325-
postID == other.postID &&
1326-
tagID == other.tagID &&
13271310
post == other.post &&
13281311
tag == other.tag;
13291312
}
@@ -1337,47 +1320,31 @@ class PostTags extends Model {
13371320

13381321
buffer.write(\\"PostTags {\\");
13391322
buffer.write(\\"id=\\" + \\"$id\\" + \\", \\");
1340-
buffer.write(\\"postID=\\" + \\"$postID\\" + \\", \\");
1341-
buffer.write(\\"tagID=\\" + \\"$tagID\\" + \\", \\");
13421323
buffer.write(\\"post=\\" + (post != null ? post.toString() : \\"null\\") + \\", \\");
13431324
buffer.write(\\"tag=\\" + (tag != null ? tag.toString() : \\"null\\"));
13441325
buffer.write(\\"}\\");
13451326

13461327
return buffer.toString();
13471328
}
13481329

1349-
PostTags copyWith(
1350-
{String id, String postID, String tagID, Post post, Tag tag}) {
1330+
PostTags copyWith({String id, Post post, Tag tag}) {
13511331
return PostTags(
1352-
id: id ?? this.id,
1353-
postID: postID ?? this.postID,
1354-
tagID: tagID ?? this.tagID,
1355-
post: post ?? this.post,
1356-
tag: tag ?? this.tag);
1332+
id: id ?? this.id, post: post ?? this.post, tag: tag ?? this.tag);
13571333
}
13581334

13591335
PostTags.fromJson(Map<String, dynamic> json)
13601336
: id = json['id'],
1361-
postID = json['postID'],
1362-
tagID = json['tagID'],
13631337
post = json['post'] != null
13641338
? Post.fromJson(new Map<String, dynamic>.from(json['post']))
13651339
: null,
13661340
tag = json['tag'] != null
13671341
? Tag.fromJson(new Map<String, dynamic>.from(json['tag']))
13681342
: null;
13691343

1370-
Map<String, dynamic> toJson() => {
1371-
'id': id,
1372-
'postID': postID,
1373-
'tagID': tagID,
1374-
'post': post?.toJson(),
1375-
'tag': tag?.toJson()
1376-
};
1344+
Map<String, dynamic> toJson() =>
1345+
{'id': id, 'post': post?.toJson(), 'tag': tag?.toJson()};
13771346

13781347
static final QueryField ID = QueryField(fieldName: \\"postTags.id\\");
1379-
static final QueryField POSTID = QueryField(fieldName: \\"postID\\");
1380-
static final QueryField TAGID = QueryField(fieldName: \\"tagID\\");
13811348
static final QueryField POST = QueryField(
13821349
fieldName: \\"post\\",
13831350
fieldType: ModelFieldType(ModelFieldTypeEnum.model,
@@ -1393,16 +1360,6 @@ class PostTags extends Model {
13931360

13941361
modelSchemaDefinition.addField(ModelFieldDefinition.id());
13951362

1396-
modelSchemaDefinition.addField(ModelFieldDefinition.field(
1397-
key: PostTags.POSTID,
1398-
isRequired: true,
1399-
ofType: ModelFieldType(ModelFieldTypeEnum.string)));
1400-
1401-
modelSchemaDefinition.addField(ModelFieldDefinition.field(
1402-
key: PostTags.TAGID,
1403-
isRequired: true,
1404-
ofType: ModelFieldType(ModelFieldTypeEnum.string)));
1405-
14061363
modelSchemaDefinition.addField(ModelFieldDefinition.belongsTo(
14071364
key: PostTags.POST,
14081365
isRequired: true,

packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-visitor.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,10 @@ describe('AppSyncModelVisitor', () => {
853853
expect(visitor.models.Human.fields[2].directives[0].arguments.fields[0]).toEqual('governmentID');
854854
expect(visitor.models.Human.fields[2].directives[0].arguments.indexName).toEqual('byHuman');
855855
expect(visitor.models.PetFriend).toBeDefined();
856-
expect(visitor.models.PetFriend.fields.length).toEqual(7);
857-
expect(visitor.models.PetFriend.fields[4].directives[0].name).toEqual('belongsTo');
858-
expect(visitor.models.PetFriend.fields[4].directives[0].arguments.fields.length).toEqual(1);
859-
expect(visitor.models.PetFriend.fields[4].directives[0].arguments.fields[0]).toEqual('animalID');
856+
expect(visitor.models.PetFriend.fields.length).toEqual(5);
857+
expect(visitor.models.PetFriend.fields[2].directives[0].name).toEqual('belongsTo');
858+
expect(visitor.models.PetFriend.fields[2].directives[0].arguments.fields.length).toEqual(1);
859+
expect(visitor.models.PetFriend.fields[2].directives[0].arguments.fields[0]).toEqual('animalID');
860860
expect(visitor.models.Animal.fields.length).toEqual(5);
861861
expect(visitor.models.Animal.fields[2].type).toEqual('PetFriend');
862862
expect(visitor.models.Animal.fields[2].directives.length).toEqual(1);
@@ -876,7 +876,7 @@ describe('AppSyncModelVisitor', () => {
876876
expect(visitor.models.ModelA.fields[1].directives[0].arguments.indexName).toEqual('byModelA');
877877

878878
expect(visitor.models.Models).toBeDefined();
879-
expect(visitor.models.Models.fields.length).toEqual(7);
879+
expect(visitor.models.Models.fields.length).toEqual(5);
880880

881881
const modelA = visitor.models.Models.fields.find(f => f.name === 'modelA');
882882
expect(modelA).toBeDefined();

packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@ export class AppSyncModelVisitor<
693693
isList: false,
694694
isNullable: field.isNullable,
695695
});
696+
} else if (connectionInfo.targetName !== 'id') {
697+
// Need to remove the field that is targetName
698+
removeFieldFromModel(model, connectionInfo.targetName);
696699
}
697700
field.connectionInfo = connectionInfo;
698701
}

0 commit comments

Comments
 (0)