From 1d95cb47dd4ea833cfa15d4be30f749832fad90d Mon Sep 17 00:00:00 2001 From: Tejas Khanolkar Date: Mon, 16 Dec 2024 16:59:16 -0800 Subject: [PATCH] fix --- .../appsync-modelgen-plugin/src/visitors/appsync-visitor.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index b1470e59..0c821ccd 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -1184,7 +1184,11 @@ export class AppSyncModelVisitor< connectionInfo.targetName !== 'id' ) { // Need to remove the field that is targetName - connectionInfo.targetNames.forEach(targetName => removeFieldFromModel(model, targetName)); + // Don't remove the field if it is a primary key field + const primaryKeyFieldNames = getModelPrimaryKeyComponentFields(model).map(field => field.name); + connectionInfo.targetNames + .filter(targetName => !primaryKeyFieldNames.includes(targetName)) + .forEach(targetName => removeFieldFromModel(model, targetName)); } }); });