Skip to content

Commit 51fd6de

Browse files
authored
fix: addressing missing key for unidirectional @hasmany on JS (#507)
* fix: addressing missing key for unidirectional hasmany, currently hardcoded only to test the approach works * fix: implement methods to determine if implicit key is needed * updating impl after some exploratory testing * chore: adding additional tests, responding to PR feedback * chore: responding to PR feedback, updating GSI name scheme to use parent model name * fix: update gsi field name to use parent model field
1 parent 82b6625 commit 51fd6de

15 files changed

+1686
-262
lines changed

packages/appsync-modelgen-plugin/src/__tests__/utils/process-has-many.test.ts

Lines changed: 523 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,78 @@ export declare const Comment: (new (init: ModelInit<Comment>) => Comment) & {
146146
}"
147147
`;
148148
149+
exports[`Javascript visitor with connected models of custom pk hasMany/belongsTo relation should generate correct declaration for hasMany uni-connection model with custom index 1`] = `
150+
"import { ModelInit, MutableModel, __modelMeta__, CompositeIdentifier } from \\"@aws-amplify/datastore\\";
151+
// @ts-ignore
152+
import { LazyLoading, LazyLoadingDisabled, AsyncCollection } from \\"@aws-amplify/datastore\\";
153+
154+
155+
156+
157+
158+
type EagerPost = {
159+
readonly [__modelMeta__]: {
160+
identifier: CompositeIdentifier<Post, ['id', 'title']>;
161+
readOnlyFields: 'createdAt' | 'updatedAt';
162+
};
163+
readonly id: string;
164+
readonly title: string;
165+
readonly comments?: (Comment | null)[] | null;
166+
readonly createdAt?: string | null;
167+
readonly updatedAt?: string | null;
168+
}
169+
170+
type LazyPost = {
171+
readonly [__modelMeta__]: {
172+
identifier: CompositeIdentifier<Post, ['id', 'title']>;
173+
readOnlyFields: 'createdAt' | 'updatedAt';
174+
};
175+
readonly id: string;
176+
readonly title: string;
177+
readonly comments: AsyncCollection<Comment>;
178+
readonly createdAt?: string | null;
179+
readonly updatedAt?: string | null;
180+
}
181+
182+
export declare type Post = LazyLoading extends LazyLoadingDisabled ? EagerPost : LazyPost
183+
184+
export declare const Post: (new (init: ModelInit<Post>) => Post) & {
185+
copyOf(source: Post, mutator: (draft: MutableModel<Post>) => MutableModel<Post> | void): Post;
186+
}
187+
188+
type EagerComment = {
189+
readonly [__modelMeta__]: {
190+
identifier: CompositeIdentifier<Comment, ['id', 'content']>;
191+
readOnlyFields: 'createdAt' | 'updatedAt';
192+
};
193+
readonly id: string;
194+
readonly content: string;
195+
readonly thePostId?: string | null;
196+
readonly thePostTitle?: string | null;
197+
readonly createdAt?: string | null;
198+
readonly updatedAt?: string | null;
199+
}
200+
201+
type LazyComment = {
202+
readonly [__modelMeta__]: {
203+
identifier: CompositeIdentifier<Comment, ['id', 'content']>;
204+
readOnlyFields: 'createdAt' | 'updatedAt';
205+
};
206+
readonly id: string;
207+
readonly content: string;
208+
readonly thePostId?: string | null;
209+
readonly thePostTitle?: string | null;
210+
readonly createdAt?: string | null;
211+
readonly updatedAt?: string | null;
212+
}
213+
214+
export declare type Comment = LazyLoading extends LazyLoadingDisabled ? EagerComment : LazyComment
215+
216+
export declare const Comment: (new (init: ModelInit<Comment>) => Comment) & {
217+
copyOf(source: Comment, mutator: (draft: MutableModel<Comment>) => MutableModel<Comment> | void): Comment;
218+
}"
219+
`;
220+
149221
exports[`Javascript visitor with connected models of custom pk hasOne/belongsTo relation should generate correct declaration when custom pk support is enabled 1`] = `
150222
"import { ModelInit, MutableModel, __modelMeta__, CompositeIdentifier } from \\"@aws-amplify/datastore\\";
151223
// @ts-ignore

0 commit comments

Comments
 (0)