Skip to content

Commit d36323d

Browse files
committed
fix(appsync-modelgen-plugin): revert #326
1 parent fc4bc27 commit d36323d

File tree

5 files changed

+90
-39
lines changed

5 files changed

+90
-39
lines changed

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

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ class Project extends Model {
630630
key: Project.TEAM,
631631
isRequired: false,
632632
ofModelName: (Team).toString(),
633-
associatedKey: Team.PROJECT
633+
associatedKey: Team.ID
634634
));
635635

636636
modelSchemaDefinition.addField(ModelFieldDefinition.field(
@@ -936,7 +936,7 @@ class Project2 extends Model {
936936
key: Project2.TEAM,
937937
isRequired: false,
938938
ofModelName: (Team2).toString(),
939-
associatedKey: Team2.PROJECT
939+
associatedKey: Team2.ID
940940
));
941941

942942
modelSchemaDefinition.addField(ModelFieldDefinition.field(
@@ -1536,7 +1536,7 @@ class Post extends Model {
15361536
key: Post.COMMENTS,
15371537
isRequired: false,
15381538
ofModelName: (Comment).toString(),
1539-
associatedKey: Comment.ID
1539+
associatedKey: Comment.POSTCOMMENTSID
15401540
));
15411541
});
15421542
}
@@ -1583,6 +1583,7 @@ class Comment extends Model {
15831583
static const classType = const _CommentModelType();
15841584
final String id;
15851585
final String? _content;
1586+
final String? _postCommentsId;
15861587

15871588
@override
15881589
getInstanceType() => classType;
@@ -1600,12 +1601,17 @@ class Comment extends Model {
16001601
}
16011602
}
16021603

1603-
const Comment._internal({required this.id, required content}): _content = content;
1604+
String? get postCommentsId {
1605+
return _postCommentsId;
1606+
}
16041607

1605-
factory Comment({String? id, required String content}) {
1608+
const Comment._internal({required this.id, required content, postCommentsId}): _content = content, _postCommentsId = postCommentsId;
1609+
1610+
factory Comment({String? id, required String content, String? postCommentsId}) {
16061611
return Comment._internal(
16071612
id: id == null ? UUID.getUUID() : id,
1608-
content: content);
1613+
content: content,
1614+
postCommentsId: postCommentsId);
16091615
}
16101616

16111617
bool equals(Object other) {
@@ -1617,7 +1623,8 @@ class Comment extends Model {
16171623
if (identical(other, this)) return true;
16181624
return other is Comment &&
16191625
id == other.id &&
1620-
_content == other._content;
1626+
_content == other._content &&
1627+
_postCommentsId == other._postCommentsId;
16211628
}
16221629

16231630
@override
@@ -1629,28 +1636,32 @@ class Comment extends Model {
16291636

16301637
buffer.write(\\"Comment {\\");
16311638
buffer.write(\\"id=\\" + \\"$id\\" + \\", \\");
1632-
buffer.write(\\"content=\\" + \\"$_content\\");
1639+
buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\");
1640+
buffer.write(\\"postCommentsId=\\" + \\"$_postCommentsId\\");
16331641
buffer.write(\\"}\\");
16341642

16351643
return buffer.toString();
16361644
}
16371645

1638-
Comment copyWith({String? id, String? content}) {
1646+
Comment copyWith({String? id, String? content, String? postCommentsId}) {
16391647
return Comment(
16401648
id: id ?? this.id,
1641-
content: content ?? this.content);
1649+
content: content ?? this.content,
1650+
postCommentsId: postCommentsId ?? this.postCommentsId);
16421651
}
16431652

16441653
Comment.fromJson(Map<String, dynamic> json)
16451654
: id = json['id'],
1646-
_content = json['content'];
1655+
_content = json['content'],
1656+
_postCommentsId = json['postCommentsId'];
16471657

16481658
Map<String, dynamic> toJson() => {
1649-
'id': id, 'content': _content
1659+
'id': id, 'content': _content, 'postCommentsId': _postCommentsId
16501660
};
16511661

16521662
static final QueryField ID = QueryField(fieldName: \\"comment.id\\");
16531663
static final QueryField CONTENT = QueryField(fieldName: \\"content\\");
1664+
static final QueryField POSTCOMMENTSID = QueryField(fieldName: \\"postCommentsId\\");
16541665
static var schema = Model.defineSchema(define: (ModelSchemaDefinition modelSchemaDefinition) {
16551666
modelSchemaDefinition.name = \\"Comment\\";
16561667
modelSchemaDefinition.pluralName = \\"Comments\\";
@@ -1662,6 +1673,12 @@ class Comment extends Model {
16621673
isRequired: true,
16631674
ofType: ModelFieldType(ModelFieldTypeEnum.string)
16641675
));
1676+
1677+
modelSchemaDefinition.addField(ModelFieldDefinition.field(
1678+
key: Comment.POSTCOMMENTSID,
1679+
isRequired: false,
1680+
ofType: ModelFieldType(ModelFieldTypeEnum.string)
1681+
));
16651682
});
16661683
}
16671684

packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-java-visitor.test.ts.snap

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class Blog7V2 implements Model {
2828
public static final QueryField NAME = field(\\"Blog7V2\\", \\"name\\");
2929
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
3030
private final @ModelField(targetType=\\"String\\", isRequired = true) String name;
31-
private final @ModelField(targetType=\\"Post7V2\\") @HasMany(associatedWith = \\"blog\\", type = Post7V2.class) List<Post7V2> posts = null;
31+
private final @ModelField(targetType=\\"Post7V2\\") @HasMany(associatedWith = \\"blog7V2PostsId\\", type = Post7V2.class) List<Post7V2> posts = null;
3232
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
3333
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
3434
public String getId() {
@@ -205,7 +205,7 @@ public final class Post7V2 implements Model {
205205
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
206206
private final @ModelField(targetType=\\"String\\", isRequired = true) String title;
207207
private final @ModelField(targetType=\\"Blog7V2\\") @BelongsTo(targetName = \\"blog7V2PostsId\\", type = Blog7V2.class) Blog7V2 blog;
208-
private final @ModelField(targetType=\\"Comment7V2\\") @HasMany(associatedWith = \\"post\\", type = Comment7V2.class) List<Comment7V2> comments = null;
208+
private final @ModelField(targetType=\\"Comment7V2\\") @HasMany(associatedWith = \\"post7V2CommentsId\\", type = Comment7V2.class) List<Comment7V2> comments = null;
209209
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
210210
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
211211
public String getId() {
@@ -616,7 +616,7 @@ public final class Project implements Model {
616616
public static final QueryField PROJECT_TEAM_ID = field(\\"Project\\", \\"projectTeamId\\");
617617
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
618618
private final @ModelField(targetType=\\"String\\") String name;
619-
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null;
619+
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"id\\", type = Team.class) Team team = null;
620620
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
621621
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
622622
private final @ModelField(targetType=\\"ID\\") String projectTeamId;
@@ -1008,7 +1008,7 @@ public final class Project2 implements Model {
10081008
public static final QueryField PROJECT2_TEAM_ID = field(\\"Project2\\", \\"project2TeamId\\");
10091009
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
10101010
private final @ModelField(targetType=\\"String\\") String name;
1011-
private final @ModelField(targetType=\\"Team2\\") @HasOne(associatedWith = \\"project\\", type = Team2.class) Team2 team = null;
1011+
private final @ModelField(targetType=\\"Team2\\") @HasOne(associatedWith = \\"id\\", type = Team2.class) Team2 team = null;
10121012
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
10131013
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
10141014
private final @ModelField(targetType=\\"ID\\") String project2TeamId;
@@ -1770,7 +1770,7 @@ public final class Post implements Model {
17701770
public static final QueryField TITLE = field(\\"Post\\", \\"title\\");
17711771
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
17721772
private final @ModelField(targetType=\\"String\\", isRequired = true) String title;
1773-
private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"id\\", type = Comment.class) List<Comment> comments = null;
1773+
private final @ModelField(targetType=\\"Comment\\") @HasMany(associatedWith = \\"postCommentsId\\", type = Comment.class) List<Comment> comments = null;
17741774
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
17751775
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
17761776
public String getId() {
@@ -1941,10 +1941,12 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field;
19411941
public final class Comment implements Model {
19421942
public static final QueryField ID = field(\\"Comment\\", \\"id\\");
19431943
public static final QueryField CONTENT = field(\\"Comment\\", \\"content\\");
1944+
public static final QueryField POST_COMMENTS_ID = field(\\"Comment\\", \\"postCommentsId\\");
19441945
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
19451946
private final @ModelField(targetType=\\"String\\", isRequired = true) String content;
19461947
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
19471948
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
1949+
private final @ModelField(targetType=\\"ID\\") String postCommentsId;
19481950
public String getId() {
19491951
return id;
19501952
}
@@ -1961,9 +1963,14 @@ public final class Comment implements Model {
19611963
return updatedAt;
19621964
}
19631965
1964-
private Comment(String id, String content) {
1966+
public String getPostCommentsId() {
1967+
return postCommentsId;
1968+
}
1969+
1970+
private Comment(String id, String content, String postCommentsId) {
19651971
this.id = id;
19661972
this.content = content;
1973+
this.postCommentsId = postCommentsId;
19671974
}
19681975
19691976
@Override
@@ -1977,7 +1984,8 @@ public final class Comment implements Model {
19771984
return ObjectsCompat.equals(getId(), comment.getId()) &&
19781985
ObjectsCompat.equals(getContent(), comment.getContent()) &&
19791986
ObjectsCompat.equals(getCreatedAt(), comment.getCreatedAt()) &&
1980-
ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt());
1987+
ObjectsCompat.equals(getUpdatedAt(), comment.getUpdatedAt()) &&
1988+
ObjectsCompat.equals(getPostCommentsId(), comment.getPostCommentsId());
19811989
}
19821990
}
19831991
@@ -1988,6 +1996,7 @@ public final class Comment implements Model {
19881996
.append(getContent())
19891997
.append(getCreatedAt())
19901998
.append(getUpdatedAt())
1999+
.append(getPostCommentsId())
19912000
.toString()
19922001
.hashCode();
19932002
}
@@ -1999,7 +2008,8 @@ public final class Comment implements Model {
19992008
.append(\\"id=\\" + String.valueOf(getId()) + \\", \\")
20002009
.append(\\"content=\\" + String.valueOf(getContent()) + \\", \\")
20012010
.append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\")
2002-
.append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()))
2011+
.append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\")
2012+
.append(\\"postCommentsId=\\" + String.valueOf(getPostCommentsId()))
20032013
.append(\\"}\\")
20042014
.toString();
20052015
}
@@ -2019,13 +2029,15 @@ public final class Comment implements Model {
20192029
public static Comment justId(String id) {
20202030
return new Comment(
20212031
id,
2032+
null,
20222033
null
20232034
);
20242035
}
20252036
20262037
public CopyOfBuilder copyOfBuilder() {
20272038
return new CopyOfBuilder(id,
2028-
content);
2039+
content,
2040+
postCommentsId);
20292041
}
20302042
public interface ContentStep {
20312043
BuildStep content(String content);
@@ -2035,19 +2047,22 @@ public final class Comment implements Model {
20352047
public interface BuildStep {
20362048
Comment build();
20372049
BuildStep id(String id);
2050+
BuildStep postCommentsId(String postCommentsId);
20382051
}
20392052
20402053
20412054
public static class Builder implements ContentStep, BuildStep {
20422055
private String id;
20432056
private String content;
2057+
private String postCommentsId;
20442058
@Override
20452059
public Comment build() {
20462060
String id = this.id != null ? this.id : UUID.randomUUID().toString();
20472061
20482062
return new Comment(
20492063
id,
2050-
content);
2064+
content,
2065+
postCommentsId);
20512066
}
20522067
20532068
@Override
@@ -2057,6 +2072,12 @@ public final class Comment implements Model {
20572072
return this;
20582073
}
20592074
2075+
@Override
2076+
public BuildStep postCommentsId(String postCommentsId) {
2077+
this.postCommentsId = postCommentsId;
2078+
return this;
2079+
}
2080+
20602081
/**
20612082
* @param id id
20622083
* @return Current Builder instance, for fluent method chaining
@@ -2069,15 +2090,21 @@ public final class Comment implements Model {
20692090
20702091
20712092
public final class CopyOfBuilder extends Builder {
2072-
private CopyOfBuilder(String id, String content) {
2093+
private CopyOfBuilder(String id, String content, String postCommentsId) {
20732094
super.id(id);
2074-
super.content(content);
2095+
super.content(content)
2096+
.postCommentsId(postCommentsId);
20752097
}
20762098
20772099
@Override
20782100
public CopyOfBuilder content(String content) {
20792101
return (CopyOfBuilder) super.content(content);
20802102
}
2103+
2104+
@Override
2105+
public CopyOfBuilder postCommentsId(String postCommentsId) {
2106+
return (CopyOfBuilder) super.postCommentsId(postCommentsId);
2107+
}
20812108
}
20822109
20832110
}
@@ -4210,7 +4237,7 @@ public final class Project implements Model {
42104237
public static final QueryField PROJECT_TEAM_ID = field(\\"Project\\", \\"projectTeamId\\");
42114238
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
42124239
private final @ModelField(targetType=\\"String\\") String name;
4213-
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null;
4240+
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"id\\", type = Team.class) Team team = null;
42144241
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
42154242
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
42164243
private final @ModelField(targetType=\\"ID\\") String projectTeamId;
@@ -4602,7 +4629,7 @@ public final class Project implements Model {
46024629
public static final QueryField PROJECT_TEAM_ID = field(\\"Project\\", \\"projectTeamId\\");
46034630
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
46044631
private final @ModelField(targetType=\\"String\\") String name;
4605-
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"project\\", type = Team.class) Team team = null;
4632+
private final @ModelField(targetType=\\"Team\\") @HasOne(associatedWith = \\"id\\", type = Team.class) Team team = null;
46064633
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
46074634
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
46084635
private final @ModelField(targetType=\\"ID\\") String projectTeamId;
@@ -4993,7 +5020,7 @@ public final class CookingBlog implements Model {
49935020
public static final QueryField NAME = field(\\"CookingBlog\\", \\"name\\");
49945021
private final @ModelField(targetType=\\"ID\\", isRequired = true) String id;
49955022
private final @ModelField(targetType=\\"String\\", isRequired = true) String name;
4996-
private final @ModelField(targetType=\\"RecipePost\\") @HasMany(associatedWith = \\"blog\\", type = RecipePost.class) List<RecipePost> posts = null;
5023+
private final @ModelField(targetType=\\"RecipePost\\") @HasMany(associatedWith = \\"cookingBlogPostsId\\", type = RecipePost.class) List<RecipePost> posts = null;
49975024
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt;
49985025
private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt;
49995026
public String getId() {

packages/appsync-modelgen-plugin/src/__tests__/visitors/gqlv2-regression-tests/__snapshots__/appsync-javascript-visitor.test.ts.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ export declare class Post {
693693
export declare class Comment {
694694
readonly id: string;
695695
readonly content: string;
696+
readonly postCommentsId?: string;
696697
constructor(init: ModelInit<Comment>);
697698
static copyOf(source: Comment, mutator: (draft: MutableModel<Comment>) => MutableModel<Comment> | void): Comment;
698699
}
@@ -749,6 +750,7 @@ export declare class Post {
749750
export declare class Comment {
750751
readonly id: string;
751752
readonly content: string;
753+
readonly postCommentsId?: string;
752754
constructor(init: ModelInit<Comment>);
753755
static copyOf(source: Comment, mutator: (draft: MutableModel<Comment>) => MutableModel<Comment> | void): Comment;
754756
}
@@ -805,6 +807,7 @@ export declare class Post {
805807
export declare class Comment {
806808
readonly id: string;
807809
readonly content: string;
810+
readonly postCommentsId?: string;
808811
constructor(init: ModelInit<Comment>);
809812
static copyOf(source: Comment, mutator: (draft: MutableModel<Comment>) => MutableModel<Comment> | void): Comment;
810813
}
@@ -861,6 +864,7 @@ export declare class Post {
861864
export declare class Comment {
862865
readonly id: string;
863866
readonly content: string;
867+
readonly postCommentsId?: string;
864868
constructor(init: ModelInit<Comment>);
865869
static copyOf(source: Comment, mutator: (draft: MutableModel<Comment>) => MutableModel<Comment> | void): Comment;
866870
}

0 commit comments

Comments
 (0)