Skip to content

Commit 5b7f190

Browse files
committed
fix(amplify-codegen): swift - add has-many targetNames for CPK use case
1 parent cf7f167 commit 5b7f190

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ extension Post {
7373
model.fields(
7474
.field(post.id, is: .required, ofType: .string),
7575
.field(post.title, is: .required, ofType: .string),
76-
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.postCommentsId),
76+
.hasMany(post.comments, is: .optional, ofType: Comment.self, associatedWith: Comment.keys.postCommentsId, targetNames: [\\"postCommentsId\\",\\"postCommentsTitle\\"]),
7777
.field(post.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime),
7878
.field(post.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime)
7979
)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,9 +615,12 @@ export class AppSyncSwiftVisitor<
615615
// connected field
616616
if (connectionInfo) {
617617
if (connectionInfo.kind === CodeGenConnectionType.HAS_MANY) {
618+
const targetNameAttrStr = this.isCustomPKEnabled()
619+
? `, targetNames: [${connectionInfo.associatedWithFields.map(target => `"${this.getFieldName(target)}"`).join(',')}]`
620+
: '';
618621
return `.hasMany(${name}, is: ${isRequired}, ofType: ${typeName}, associatedWith: ${this.getModelName(
619622
connectionInfo.connectedModel,
620-
)}.keys.${this.getFieldName(connectionInfo.associatedWith)})`;
623+
)}.keys.${this.getFieldName(connectionInfo.associatedWith)}${targetNameAttrStr})`;
621624
}
622625
if (connectionInfo.kind === CodeGenConnectionType.HAS_ONE) {
623626
const targetNameAttrStr = this.isCustomPKEnabled()

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@
143143
"@turf/boolean-clockwise" "6.5.0"
144144
camelcase-keys "6.2.2"
145145

146+
"@aws-amplify/graphql-schema-test-library@^1.1.18":
147+
version "1.1.24"
148+
resolved "https://registry.yarnpkg.com/@aws-amplify/graphql-schema-test-library/-/graphql-schema-test-library-1.1.24.tgz#6e615ea09f3fb61c35f6f3a6380aad6b6e06e90f"
149+
integrity sha512-Ah6vBGe/L3qIlhnrGmVAfL3PRMRB+/mZJCJz01FEheLQI+jzKPHLcqF8uR3J3Pzuj/YTWMlL5xxYhdVOrz6pDQ==
150+
146151
"@aws-amplify/graphql-transformer-core@^0.17.11":
147152
version "0.17.12"
148153
resolved "https://registry.npmjs.org/@aws-amplify/graphql-transformer-core/-/graphql-transformer-core-0.17.12.tgz#b965a07a8d23df2cf349366f39656a7ed2908154"

0 commit comments

Comments
 (0)