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)); } }); });