From 9a8d0481fed582ecab4a8dabe4ac68cc5a08154d Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Fri, 26 Apr 2024 07:59:01 -0600 Subject: [PATCH 1/2] feat: use a different associated field for references on native (#818) --- .../appsync-dart-visitor.test.ts.snap | 600 +++------------ .../appsync-java-visitor.test.ts.snap | 706 +++--------------- .../appsync-swift-visitor.test.ts.snap | 268 +------ .../src/utils/process-belongs-to.ts | 7 +- .../src/utils/process-connections-v2.ts | 14 +- .../src/utils/process-connections.ts | 2 + .../src/utils/process-has-many.ts | 12 +- .../src/utils/process-has-one.ts | 14 +- .../src/visitors/appsync-dart-visitor.ts | 18 +- .../src/visitors/appsync-java-visitor.ts | 12 +- .../src/visitors/appsync-swift-visitor.ts | 30 +- .../src/visitors/appsync-visitor.ts | 3 +- 12 files changed, 288 insertions(+), 1398 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-dart-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-dart-visitor.test.ts.snap index f18110ea8..7b587d93a 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-dart-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-dart-visitor.test.ts.snap @@ -11742,8 +11742,6 @@ class Foo extends amplify_core.Model { final Bar? _bar2; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; - final String? _fooBar1Id; - final String? _fooBar2Id; @override getInstanceType() => classType; @@ -11774,23 +11772,13 @@ class Foo extends amplify_core.Model { return _updatedAt; } - String? get fooBar1Id { - return _fooBar1Id; - } - - String? get fooBar2Id { - return _fooBar2Id; - } - - const Foo._internal({required this.id, bar1, bar2, createdAt, updatedAt, fooBar1Id, fooBar2Id}): _bar1 = bar1, _bar2 = bar2, _createdAt = createdAt, _updatedAt = updatedAt, _fooBar1Id = fooBar1Id, _fooBar2Id = fooBar2Id; + const Foo._internal({required this.id, bar1, bar2, createdAt, updatedAt}): _bar1 = bar1, _bar2 = bar2, _createdAt = createdAt, _updatedAt = updatedAt; - factory Foo({String? id, Bar? bar1, Bar? bar2, String? fooBar1Id, String? fooBar2Id}) { + factory Foo({String? id, Bar? bar1, Bar? bar2}) { return Foo._internal( id: id == null ? amplify_core.UUID.getUUID() : id, bar1: bar1, - bar2: bar2, - fooBar1Id: fooBar1Id, - fooBar2Id: fooBar2Id); + bar2: bar2); } bool equals(Object other) { @@ -11803,9 +11791,7 @@ class Foo extends amplify_core.Model { return other is Foo && id == other.id && _bar1 == other._bar1 && - _bar2 == other._bar2 && - _fooBar1Id == other._fooBar1Id && - _fooBar2Id == other._fooBar2Id; + _bar2 == other._bar2; } @override @@ -11818,35 +11804,27 @@ class Foo extends amplify_core.Model { buffer.write(\\"Foo {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"fooBar1Id=\\" + \\"$_fooBar1Id\\" + \\", \\"); - buffer.write(\\"fooBar2Id=\\" + \\"$_fooBar2Id\\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); buffer.write(\\"}\\"); return buffer.toString(); } - Foo copyWith({Bar? bar1, Bar? bar2, String? fooBar1Id, String? fooBar2Id}) { + Foo copyWith({Bar? bar1, Bar? bar2}) { return Foo._internal( id: id, bar1: bar1 ?? this.bar1, - bar2: bar2 ?? this.bar2, - fooBar1Id: fooBar1Id ?? this.fooBar1Id, - fooBar2Id: fooBar2Id ?? this.fooBar2Id); + bar2: bar2 ?? this.bar2); } Foo copyWithModelFieldValues({ ModelFieldValue? bar1, - ModelFieldValue? bar2, - ModelFieldValue? fooBar1Id, - ModelFieldValue? fooBar2Id + ModelFieldValue? bar2 }) { return Foo._internal( id: id, bar1: bar1 == null ? this.bar1 : bar1.value, - bar2: bar2 == null ? this.bar2 : bar2.value, - fooBar1Id: fooBar1Id == null ? this.fooBar1Id : fooBar1Id.value, - fooBar2Id: fooBar2Id == null ? this.fooBar2Id : fooBar2Id.value + bar2: bar2 == null ? this.bar2 : bar2.value ); } @@ -11863,12 +11841,10 @@ class Foo extends amplify_core.Model { : Bar.fromJson(new Map.from(json['bar2'])) : null, _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, - _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null, - _fooBar1Id = json['fooBar1Id'], - _fooBar2Id = json['fooBar2Id']; + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'bar1': _bar1?.toJson(), 'bar2': _bar2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format(), 'fooBar1Id': _fooBar1Id, 'fooBar2Id': _fooBar2Id + 'id': id, 'bar1': _bar1?.toJson(), 'bar2': _bar2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { @@ -11876,9 +11852,7 @@ class Foo extends amplify_core.Model { 'bar1': _bar1, 'bar2': _bar2, 'createdAt': _createdAt, - 'updatedAt': _updatedAt, - 'fooBar1Id': _fooBar1Id, - 'fooBar2Id': _fooBar2Id + 'updatedAt': _updatedAt }; static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); @@ -11889,8 +11863,6 @@ class Foo extends amplify_core.Model { static final BAR2 = amplify_core.QueryField( fieldName: \\"bar2\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Bar')); - static final FOOBAR1ID = amplify_core.QueryField(fieldName: \\"fooBar1Id\\"); - static final FOOBAR2ID = amplify_core.QueryField(fieldName: \\"fooBar2Id\\"); static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { modelSchemaDefinition.name = \\"Foo\\"; modelSchemaDefinition.pluralName = \\"Foos\\"; @@ -11908,7 +11880,7 @@ class Foo extends amplify_core.Model { key: Foo.BAR2, isRequired: false, ofModelName: 'Bar', - associatedKey: Bar.FOO1 + associatedKey: Bar.FOO2 )); modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( @@ -11924,18 +11896,6 @@ class Foo extends amplify_core.Model { isReadOnly: true, ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Foo.FOOBAR1ID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Foo.FOOBAR2ID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); }); } @@ -12027,8 +11987,6 @@ import 'package:amplify_core/amplify_core.dart' as amplify_core; class Bar extends amplify_core.Model { static const classType = const _BarModelType(); final String id; - final String? _bar1Id; - final String? _bar2Id; final Foo? _foo1; final Foo? _foo2; final amplify_core.TemporalDateTime? _createdAt; @@ -12047,14 +12005,6 @@ class Bar extends amplify_core.Model { ); } - String? get bar1Id { - return _bar1Id; - } - - String? get bar2Id { - return _bar2Id; - } - Foo? get foo1 { return _foo1; } @@ -12071,13 +12021,11 @@ class Bar extends amplify_core.Model { return _updatedAt; } - const Bar._internal({required this.id, bar1Id, bar2Id, foo1, foo2, createdAt, updatedAt}): _bar1Id = bar1Id, _bar2Id = bar2Id, _foo1 = foo1, _foo2 = foo2, _createdAt = createdAt, _updatedAt = updatedAt; + const Bar._internal({required this.id, foo1, foo2, createdAt, updatedAt}): _foo1 = foo1, _foo2 = foo2, _createdAt = createdAt, _updatedAt = updatedAt; - factory Bar({String? id, String? bar1Id, String? bar2Id, Foo? foo1, Foo? foo2}) { + factory Bar({String? id, Foo? foo1, Foo? foo2}) { return Bar._internal( id: id == null ? amplify_core.UUID.getUUID() : id, - bar1Id: bar1Id, - bar2Id: bar2Id, foo1: foo1, foo2: foo2); } @@ -12091,8 +12039,6 @@ class Bar extends amplify_core.Model { if (identical(other, this)) return true; return other is Bar && id == other.id && - _bar1Id == other._bar1Id && - _bar2Id == other._bar2Id && _foo1 == other._foo1 && _foo2 == other._foo2; } @@ -12106,8 +12052,6 @@ class Bar extends amplify_core.Model { buffer.write(\\"Bar {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); - buffer.write(\\"bar1Id=\\" + \\"$_bar1Id\\" + \\", \\"); - buffer.write(\\"bar2Id=\\" + \\"$_bar2Id\\" + \\", \\"); buffer.write(\\"foo1=\\" + (_foo1 != null ? _foo1!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"foo2=\\" + (_foo2 != null ? _foo2!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); @@ -12117,25 +12061,19 @@ class Bar extends amplify_core.Model { return buffer.toString(); } - Bar copyWith({String? bar1Id, String? bar2Id, Foo? foo1, Foo? foo2}) { + Bar copyWith({Foo? foo1, Foo? foo2}) { return Bar._internal( id: id, - bar1Id: bar1Id ?? this.bar1Id, - bar2Id: bar2Id ?? this.bar2Id, foo1: foo1 ?? this.foo1, foo2: foo2 ?? this.foo2); } Bar copyWithModelFieldValues({ - ModelFieldValue? bar1Id, - ModelFieldValue? bar2Id, ModelFieldValue? foo1, ModelFieldValue? foo2 }) { return Bar._internal( id: id, - bar1Id: bar1Id == null ? this.bar1Id : bar1Id.value, - bar2Id: bar2Id == null ? this.bar2Id : bar2Id.value, foo1: foo1 == null ? this.foo1 : foo1.value, foo2: foo2 == null ? this.foo2 : foo2.value ); @@ -12143,8 +12081,6 @@ class Bar extends amplify_core.Model { Bar.fromJson(Map json) : id = json['id'], - _bar1Id = json['bar1Id'], - _bar2Id = json['bar2Id'], _foo1 = json['foo1'] != null ? json['foo1']['serializedData'] != null ? Foo.fromJson(new Map.from(json['foo1']['serializedData'])) @@ -12159,13 +12095,11 @@ class Bar extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'bar1Id': _bar1Id, 'bar2Id': _bar2Id, 'foo1': _foo1?.toJson(), 'foo2': _foo2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'foo1': _foo1?.toJson(), 'foo2': _foo2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, - 'bar1Id': _bar1Id, - 'bar2Id': _bar2Id, 'foo1': _foo1, 'foo2': _foo2, 'createdAt': _createdAt, @@ -12174,8 +12108,6 @@ class Bar extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); - static final BAR1ID = amplify_core.QueryField(fieldName: \\"bar1Id\\"); - static final BAR2ID = amplify_core.QueryField(fieldName: \\"bar2Id\\"); static final FOO1 = amplify_core.QueryField( fieldName: \\"foo1\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Foo')); @@ -12188,29 +12120,17 @@ class Bar extends amplify_core.Model { modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Bar.BAR1ID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Bar.BAR2ID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: Bar.FOO1, isRequired: false, - targetNames: ['barFoo1Id'], + targetNames: ['bar1Id'], ofModelName: 'Foo' )); modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: Bar.FOO2, isRequired: false, - targetNames: ['barFoo2Id'], + targetNames: ['bar2Id'], ofModelName: 'Foo' )); @@ -12672,9 +12592,6 @@ class Related extends amplify_core.Model { static const classType = const _RelatedModelType(); final String id; final String? _content; - final String? _primaryTenantId; - final String? _primaryInstanceId; - final String? _primaryRecordId; final Primary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -12696,45 +12613,6 @@ class Related extends amplify_core.Model { return _content; } - String get primaryTenantId { - try { - return _primaryTenantId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - - String get primaryInstanceId { - try { - return _primaryInstanceId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - - String get primaryRecordId { - try { - return _primaryRecordId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - Primary? get primary { return _primary; } @@ -12747,15 +12625,12 @@ class Related extends amplify_core.Model { return _updatedAt; } - const Related._internal({required this.id, content, required primaryTenantId, required primaryInstanceId, required primaryRecordId, primary, createdAt, updatedAt}): _content = content, _primaryTenantId = primaryTenantId, _primaryInstanceId = primaryInstanceId, _primaryRecordId = primaryRecordId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const Related._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory Related({String? id, String? content, required String primaryTenantId, required String primaryInstanceId, required String primaryRecordId, Primary? primary}) { + factory Related({String? id, String? content, Primary? primary}) { return Related._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, - primaryTenantId: primaryTenantId, - primaryInstanceId: primaryInstanceId, - primaryRecordId: primaryRecordId, primary: primary); } @@ -12769,9 +12644,6 @@ class Related extends amplify_core.Model { return other is Related && id == other.id && _content == other._content && - _primaryTenantId == other._primaryTenantId && - _primaryInstanceId == other._primaryInstanceId && - _primaryRecordId == other._primaryRecordId && _primary == other._primary; } @@ -12785,9 +12657,6 @@ class Related extends amplify_core.Model { buffer.write(\\"Related {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); - buffer.write(\\"primaryTenantId=\\" + \\"$_primaryTenantId\\" + \\", \\"); - buffer.write(\\"primaryInstanceId=\\" + \\"$_primaryInstanceId\\" + \\", \\"); - buffer.write(\\"primaryRecordId=\\" + \\"$_primaryRecordId\\" + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -12796,29 +12665,20 @@ class Related extends amplify_core.Model { return buffer.toString(); } - Related copyWith({String? content, String? primaryTenantId, String? primaryInstanceId, String? primaryRecordId, Primary? primary}) { + Related copyWith({String? content, Primary? primary}) { return Related._internal( id: id, content: content ?? this.content, - primaryTenantId: primaryTenantId ?? this.primaryTenantId, - primaryInstanceId: primaryInstanceId ?? this.primaryInstanceId, - primaryRecordId: primaryRecordId ?? this.primaryRecordId, primary: primary ?? this.primary); } Related copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? primaryTenantId, - ModelFieldValue? primaryInstanceId, - ModelFieldValue? primaryRecordId, ModelFieldValue? primary }) { return Related._internal( id: id, content: content == null ? this.content : content.value, - primaryTenantId: primaryTenantId == null ? this.primaryTenantId : primaryTenantId.value, - primaryInstanceId: primaryInstanceId == null ? this.primaryInstanceId : primaryInstanceId.value, - primaryRecordId: primaryRecordId == null ? this.primaryRecordId : primaryRecordId.value, primary: primary == null ? this.primary : primary.value ); } @@ -12826,9 +12686,6 @@ class Related extends amplify_core.Model { Related.fromJson(Map json) : id = json['id'], _content = json['content'], - _primaryTenantId = json['primaryTenantId'], - _primaryInstanceId = json['primaryInstanceId'], - _primaryRecordId = json['primaryRecordId'], _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -12838,15 +12695,12 @@ class Related extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primaryTenantId': _primaryTenantId, 'primaryInstanceId': _primaryInstanceId, 'primaryRecordId': _primaryRecordId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, - 'primaryTenantId': _primaryTenantId, - 'primaryInstanceId': _primaryInstanceId, - 'primaryRecordId': _primaryRecordId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -12855,9 +12709,6 @@ class Related extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); - static final PRIMARYTENANTID = amplify_core.QueryField(fieldName: \\"primaryTenantId\\"); - static final PRIMARYINSTANCEID = amplify_core.QueryField(fieldName: \\"primaryInstanceId\\"); - static final PRIMARYRECORDID = amplify_core.QueryField(fieldName: \\"primaryRecordId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); @@ -12873,28 +12724,10 @@ class Related extends amplify_core.Model { ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYTENANTID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYINSTANCEID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYRECORDID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: Related.PRIMARY, isRequired: false, - targetNames: ['primaryRelatedTenantId', 'primaryRelatedInstanceId', 'primaryRelatedRecordId'], + targetNames: ['primaryTenantId', 'primaryInstanceId', 'primaryRecordId'], ofModelName: 'Primary' )); @@ -13008,7 +12841,6 @@ class Primary extends amplify_core.Model { final Related? _related; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; - final String? _primaryRelatedId; @override getInstanceType() => classType; @@ -13089,20 +12921,15 @@ class Primary extends amplify_core.Model { return _updatedAt; } - String? get primaryRelatedId { - return _primaryRelatedId; - } - - const Primary._internal({required tenantId, required instanceId, required recordId, content, related, createdAt, updatedAt, primaryRelatedId}): _tenantId = tenantId, _instanceId = instanceId, _recordId = recordId, _content = content, _related = related, _createdAt = createdAt, _updatedAt = updatedAt, _primaryRelatedId = primaryRelatedId; + const Primary._internal({required tenantId, required instanceId, required recordId, content, related, createdAt, updatedAt}): _tenantId = tenantId, _instanceId = instanceId, _recordId = recordId, _content = content, _related = related, _createdAt = createdAt, _updatedAt = updatedAt; - factory Primary({required String tenantId, required String instanceId, required String recordId, String? content, Related? related, String? primaryRelatedId}) { + factory Primary({required String tenantId, required String instanceId, required String recordId, String? content, Related? related}) { return Primary._internal( tenantId: tenantId, instanceId: instanceId, recordId: recordId, content: content, - related: related, - primaryRelatedId: primaryRelatedId); + related: related); } bool equals(Object other) { @@ -13117,8 +12944,7 @@ class Primary extends amplify_core.Model { _instanceId == other._instanceId && _recordId == other._recordId && _content == other._content && - _related == other._related && - _primaryRelatedId == other._primaryRelatedId; + _related == other._related; } @override @@ -13134,35 +12960,31 @@ class Primary extends amplify_core.Model { buffer.write(\\"recordId=\\" + \\"$_recordId\\" + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"primaryRelatedId=\\" + \\"$_primaryRelatedId\\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); buffer.write(\\"}\\"); return buffer.toString(); } - Primary copyWith({String? content, Related? related, String? primaryRelatedId}) { + Primary copyWith({String? content, Related? related}) { return Primary._internal( tenantId: tenantId, instanceId: instanceId, recordId: recordId, content: content ?? this.content, - related: related ?? this.related, - primaryRelatedId: primaryRelatedId ?? this.primaryRelatedId); + related: related ?? this.related); } Primary copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? related, - ModelFieldValue? primaryRelatedId + ModelFieldValue? related }) { return Primary._internal( tenantId: tenantId, instanceId: instanceId, recordId: recordId, content: content == null ? this.content : content.value, - related: related == null ? this.related : related.value, - primaryRelatedId: primaryRelatedId == null ? this.primaryRelatedId : primaryRelatedId.value + related: related == null ? this.related : related.value ); } @@ -13177,11 +12999,10 @@ class Primary extends amplify_core.Model { : Related.fromJson(new Map.from(json['related'])) : null, _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, - _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null, - _primaryRelatedId = json['primaryRelatedId']; + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'tenantId': _tenantId, 'instanceId': _instanceId, 'recordId': _recordId, 'content': _content, 'related': _related?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format(), 'primaryRelatedId': _primaryRelatedId + 'tenantId': _tenantId, 'instanceId': _instanceId, 'recordId': _recordId, 'content': _content, 'related': _related?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { @@ -13191,8 +13012,7 @@ class Primary extends amplify_core.Model { 'content': _content, 'related': _related, 'createdAt': _createdAt, - 'updatedAt': _updatedAt, - 'primaryRelatedId': _primaryRelatedId + 'updatedAt': _updatedAt }; static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); @@ -13203,7 +13023,6 @@ class Primary extends amplify_core.Model { static final RELATED = amplify_core.QueryField( fieldName: \\"related\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Related')); - static final PRIMARYRELATEDID = amplify_core.QueryField(fieldName: \\"primaryRelatedId\\"); static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { modelSchemaDefinition.name = \\"Primary\\"; modelSchemaDefinition.pluralName = \\"Primaries\\"; @@ -13256,12 +13075,6 @@ class Primary extends amplify_core.Model { isReadOnly: true, ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Primary.PRIMARYRELATEDID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); }); } @@ -13367,9 +13180,6 @@ class Related extends amplify_core.Model { static const classType = const _RelatedModelType(); final String id; final String? _content; - final String? _primaryTenantId; - final String? _primaryInstanceId; - final String? _primaryRecordId; final Primary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -13391,45 +13201,6 @@ class Related extends amplify_core.Model { return _content; } - String get primaryTenantId { - try { - return _primaryTenantId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - - String get primaryInstanceId { - try { - return _primaryInstanceId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - - String get primaryRecordId { - try { - return _primaryRecordId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - Primary? get primary { return _primary; } @@ -13442,15 +13213,12 @@ class Related extends amplify_core.Model { return _updatedAt; } - const Related._internal({required this.id, content, required primaryTenantId, required primaryInstanceId, required primaryRecordId, primary, createdAt, updatedAt}): _content = content, _primaryTenantId = primaryTenantId, _primaryInstanceId = primaryInstanceId, _primaryRecordId = primaryRecordId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const Related._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory Related({String? id, String? content, required String primaryTenantId, required String primaryInstanceId, required String primaryRecordId, Primary? primary}) { + factory Related({String? id, String? content, Primary? primary}) { return Related._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, - primaryTenantId: primaryTenantId, - primaryInstanceId: primaryInstanceId, - primaryRecordId: primaryRecordId, primary: primary); } @@ -13464,9 +13232,6 @@ class Related extends amplify_core.Model { return other is Related && id == other.id && _content == other._content && - _primaryTenantId == other._primaryTenantId && - _primaryInstanceId == other._primaryInstanceId && - _primaryRecordId == other._primaryRecordId && _primary == other._primary; } @@ -13480,9 +13245,6 @@ class Related extends amplify_core.Model { buffer.write(\\"Related {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); - buffer.write(\\"primaryTenantId=\\" + \\"$_primaryTenantId\\" + \\", \\"); - buffer.write(\\"primaryInstanceId=\\" + \\"$_primaryInstanceId\\" + \\", \\"); - buffer.write(\\"primaryRecordId=\\" + \\"$_primaryRecordId\\" + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -13491,29 +13253,20 @@ class Related extends amplify_core.Model { return buffer.toString(); } - Related copyWith({String? content, String? primaryTenantId, String? primaryInstanceId, String? primaryRecordId, Primary? primary}) { + Related copyWith({String? content, Primary? primary}) { return Related._internal( id: id, content: content ?? this.content, - primaryTenantId: primaryTenantId ?? this.primaryTenantId, - primaryInstanceId: primaryInstanceId ?? this.primaryInstanceId, - primaryRecordId: primaryRecordId ?? this.primaryRecordId, primary: primary ?? this.primary); } Related copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? primaryTenantId, - ModelFieldValue? primaryInstanceId, - ModelFieldValue? primaryRecordId, ModelFieldValue? primary }) { return Related._internal( id: id, content: content == null ? this.content : content.value, - primaryTenantId: primaryTenantId == null ? this.primaryTenantId : primaryTenantId.value, - primaryInstanceId: primaryInstanceId == null ? this.primaryInstanceId : primaryInstanceId.value, - primaryRecordId: primaryRecordId == null ? this.primaryRecordId : primaryRecordId.value, primary: primary == null ? this.primary : primary.value ); } @@ -13521,9 +13274,6 @@ class Related extends amplify_core.Model { Related.fromJson(Map json) : id = json['id'], _content = json['content'], - _primaryTenantId = json['primaryTenantId'], - _primaryInstanceId = json['primaryInstanceId'], - _primaryRecordId = json['primaryRecordId'], _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -13533,15 +13283,12 @@ class Related extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primaryTenantId': _primaryTenantId, 'primaryInstanceId': _primaryInstanceId, 'primaryRecordId': _primaryRecordId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, - 'primaryTenantId': _primaryTenantId, - 'primaryInstanceId': _primaryInstanceId, - 'primaryRecordId': _primaryRecordId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -13550,9 +13297,6 @@ class Related extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); - static final PRIMARYTENANTID = amplify_core.QueryField(fieldName: \\"primaryTenantId\\"); - static final PRIMARYINSTANCEID = amplify_core.QueryField(fieldName: \\"primaryInstanceId\\"); - static final PRIMARYRECORDID = amplify_core.QueryField(fieldName: \\"primaryRecordId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); @@ -13568,28 +13312,10 @@ class Related extends amplify_core.Model { ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYTENANTID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYINSTANCEID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Related.PRIMARYRECORDID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: Related.PRIMARY, isRequired: false, - targetNames: ['relatedPrimaryTenantId', 'relatedPrimaryInstanceId', 'relatedPrimaryRecordId'], + targetNames: ['primaryTenantId', 'primaryInstanceId', 'primaryRecordId'], ofModelName: 'Primary' )); @@ -13954,7 +13680,6 @@ class SqlRelated extends amplify_core.Model { static const classType = const _SqlRelatedModelType(); final int id; final String? _content; - final int? _primaryId; final SqlPrimary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -13976,19 +13701,6 @@ class SqlRelated extends amplify_core.Model { return _content; } - int get primaryId { - try { - return _primaryId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - SqlPrimary? get primary { return _primary; } @@ -14001,13 +13713,12 @@ class SqlRelated extends amplify_core.Model { return _updatedAt; } - const SqlRelated._internal({required this.id, content, required primaryId, primary, createdAt, updatedAt}): _content = content, _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const SqlRelated._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory SqlRelated({int? id, String? content, required int primaryId, SqlPrimary? primary}) { + factory SqlRelated({int? id, String? content, SqlPrimary? primary}) { return SqlRelated._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, - primaryId: primaryId, primary: primary); } @@ -14021,7 +13732,6 @@ class SqlRelated extends amplify_core.Model { return other is SqlRelated && id == other.id && _content == other._content && - _primaryId == other._primaryId && _primary == other._primary; } @@ -14035,7 +13745,6 @@ class SqlRelated extends amplify_core.Model { buffer.write(\\"SqlRelated {\\"); buffer.write(\\"id=\\" + (id != null ? id!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); - buffer.write(\\"primaryId=\\" + (_primaryId != null ? _primaryId!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -14044,23 +13753,20 @@ class SqlRelated extends amplify_core.Model { return buffer.toString(); } - SqlRelated copyWith({String? content, int? primaryId, SqlPrimary? primary}) { + SqlRelated copyWith({String? content, SqlPrimary? primary}) { return SqlRelated._internal( id: id, content: content ?? this.content, - primaryId: primaryId ?? this.primaryId, primary: primary ?? this.primary); } SqlRelated copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? primaryId, ModelFieldValue? primary }) { return SqlRelated._internal( id: id, content: content == null ? this.content : content.value, - primaryId: primaryId == null ? this.primaryId : primaryId.value, primary: primary == null ? this.primary : primary.value ); } @@ -14068,7 +13774,6 @@ class SqlRelated extends amplify_core.Model { SqlRelated.fromJson(Map json) : id = (json['id'] as num?)?.toInt(), _content = json['content'], - _primaryId = (json['primaryId'] as num?)?.toInt(), _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -14078,13 +13783,12 @@ class SqlRelated extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, - 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -14093,7 +13797,6 @@ class SqlRelated extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); - static final PRIMARYID = amplify_core.QueryField(fieldName: \\"primaryId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlPrimary')); @@ -14114,16 +13817,10 @@ class SqlRelated extends amplify_core.Model { ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: SqlRelated.PRIMARYID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.int) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: SqlRelated.PRIMARY, isRequired: false, - targetNames: ['sqlPrimaryRelatedId'], + targetNames: ['primaryId'], ofModelName: 'SqlPrimary' )); @@ -14236,7 +13933,6 @@ class Primary extends amplify_core.Model { final RelatedOne? _relatedOne; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; - final String? _primaryRelatedOneId; @override getInstanceType() => classType; @@ -14267,18 +13963,13 @@ class Primary extends amplify_core.Model { return _updatedAt; } - String? get primaryRelatedOneId { - return _primaryRelatedOneId; - } - - const Primary._internal({required this.id, relatedMany, relatedOne, createdAt, updatedAt, primaryRelatedOneId}): _relatedMany = relatedMany, _relatedOne = relatedOne, _createdAt = createdAt, _updatedAt = updatedAt, _primaryRelatedOneId = primaryRelatedOneId; + const Primary._internal({required this.id, relatedMany, relatedOne, createdAt, updatedAt}): _relatedMany = relatedMany, _relatedOne = relatedOne, _createdAt = createdAt, _updatedAt = updatedAt; - factory Primary({String? id, List? relatedMany, RelatedOne? relatedOne, String? primaryRelatedOneId}) { + factory Primary({String? id, List? relatedMany, RelatedOne? relatedOne}) { return Primary._internal( id: id == null ? amplify_core.UUID.getUUID() : id, relatedMany: relatedMany != null ? List.unmodifiable(relatedMany) : relatedMany, - relatedOne: relatedOne, - primaryRelatedOneId: primaryRelatedOneId); + relatedOne: relatedOne); } bool equals(Object other) { @@ -14291,8 +13982,7 @@ class Primary extends amplify_core.Model { return other is Primary && id == other.id && DeepCollectionEquality().equals(_relatedMany, other._relatedMany) && - _relatedOne == other._relatedOne && - _primaryRelatedOneId == other._primaryRelatedOneId; + _relatedOne == other._relatedOne; } @override @@ -14305,31 +13995,27 @@ class Primary extends amplify_core.Model { buffer.write(\\"Primary {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"primaryRelatedOneId=\\" + \\"$_primaryRelatedOneId\\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); buffer.write(\\"}\\"); return buffer.toString(); } - Primary copyWith({List? relatedMany, RelatedOne? relatedOne, String? primaryRelatedOneId}) { + Primary copyWith({List? relatedMany, RelatedOne? relatedOne}) { return Primary._internal( id: id, relatedMany: relatedMany ?? this.relatedMany, - relatedOne: relatedOne ?? this.relatedOne, - primaryRelatedOneId: primaryRelatedOneId ?? this.primaryRelatedOneId); + relatedOne: relatedOne ?? this.relatedOne); } Primary copyWithModelFieldValues({ ModelFieldValue?>? relatedMany, - ModelFieldValue? relatedOne, - ModelFieldValue? primaryRelatedOneId + ModelFieldValue? relatedOne }) { return Primary._internal( id: id, relatedMany: relatedMany == null ? this.relatedMany : relatedMany.value, - relatedOne: relatedOne == null ? this.relatedOne : relatedOne.value, - primaryRelatedOneId: primaryRelatedOneId == null ? this.primaryRelatedOneId : primaryRelatedOneId.value + relatedOne: relatedOne == null ? this.relatedOne : relatedOne.value ); } @@ -14354,11 +14040,10 @@ class Primary extends amplify_core.Model { : RelatedOne.fromJson(new Map.from(json['relatedOne'])) : null, _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, - _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null, - _primaryRelatedOneId = json['primaryRelatedOneId']; + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'relatedMany': _relatedMany?.map((RelatedMany? e) => e?.toJson()).toList(), 'relatedOne': _relatedOne?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format(), 'primaryRelatedOneId': _primaryRelatedOneId + 'id': id, 'relatedMany': _relatedMany?.map((RelatedMany? e) => e?.toJson()).toList(), 'relatedOne': _relatedOne?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { @@ -14366,8 +14051,7 @@ class Primary extends amplify_core.Model { 'relatedMany': _relatedMany, 'relatedOne': _relatedOne, 'createdAt': _createdAt, - 'updatedAt': _updatedAt, - 'primaryRelatedOneId': _primaryRelatedOneId + 'updatedAt': _updatedAt }; static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); @@ -14378,7 +14062,6 @@ class Primary extends amplify_core.Model { static final RELATEDONE = amplify_core.QueryField( fieldName: \\"relatedOne\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'RelatedOne')); - static final PRIMARYRELATEDONEID = amplify_core.QueryField(fieldName: \\"primaryRelatedOneId\\"); static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { modelSchemaDefinition.name = \\"Primary\\"; modelSchemaDefinition.pluralName = \\"Primaries\\"; @@ -14416,12 +14099,6 @@ class Primary extends amplify_core.Model { isReadOnly: true, ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: Primary.PRIMARYRELATEDONEID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); }); } @@ -14513,7 +14190,6 @@ import 'package:amplify_core/amplify_core.dart' as amplify_core; class RelatedOne extends amplify_core.Model { static const classType = const _RelatedOneModelType(); final String id; - final String? _primaryId; final Primary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -14531,19 +14207,6 @@ class RelatedOne extends amplify_core.Model { ); } - String get primaryId { - try { - return _primaryId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - Primary? get primary { return _primary; } @@ -14556,12 +14219,11 @@ class RelatedOne extends amplify_core.Model { return _updatedAt; } - const RelatedOne._internal({required this.id, required primaryId, primary, createdAt, updatedAt}): _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const RelatedOne._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory RelatedOne({String? id, required String primaryId, Primary? primary}) { + factory RelatedOne({String? id, Primary? primary}) { return RelatedOne._internal( id: id == null ? amplify_core.UUID.getUUID() : id, - primaryId: primaryId, primary: primary); } @@ -14574,7 +14236,6 @@ class RelatedOne extends amplify_core.Model { if (identical(other, this)) return true; return other is RelatedOne && id == other.id && - _primaryId == other._primaryId && _primary == other._primary; } @@ -14587,7 +14248,6 @@ class RelatedOne extends amplify_core.Model { buffer.write(\\"RelatedOne {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); - buffer.write(\\"primaryId=\\" + \\"$_primaryId\\" + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -14596,27 +14256,23 @@ class RelatedOne extends amplify_core.Model { return buffer.toString(); } - RelatedOne copyWith({String? primaryId, Primary? primary}) { + RelatedOne copyWith({Primary? primary}) { return RelatedOne._internal( id: id, - primaryId: primaryId ?? this.primaryId, primary: primary ?? this.primary); } RelatedOne copyWithModelFieldValues({ - ModelFieldValue? primaryId, ModelFieldValue? primary }) { return RelatedOne._internal( id: id, - primaryId: primaryId == null ? this.primaryId : primaryId.value, primary: primary == null ? this.primary : primary.value ); } RelatedOne.fromJson(Map json) : id = json['id'], - _primaryId = json['primaryId'], _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -14626,12 +14282,11 @@ class RelatedOne extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, - 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -14639,7 +14294,6 @@ class RelatedOne extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); - static final PRIMARYID = amplify_core.QueryField(fieldName: \\"primaryId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); @@ -14653,16 +14307,10 @@ class RelatedOne extends amplify_core.Model { modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: RelatedOne.PRIMARYID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: RelatedOne.PRIMARY, isRequired: false, - targetNames: ['relatedOnePrimaryId'], + targetNames: ['primaryId'], ofModelName: 'Primary' )); @@ -14770,7 +14418,6 @@ import 'package:amplify_core/amplify_core.dart' as amplify_core; class RelatedMany extends amplify_core.Model { static const classType = const _RelatedManyModelType(); final String id; - final String? _primaryId; final Primary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -14788,19 +14435,6 @@ class RelatedMany extends amplify_core.Model { ); } - String get primaryId { - try { - return _primaryId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - Primary? get primary { return _primary; } @@ -14813,12 +14447,11 @@ class RelatedMany extends amplify_core.Model { return _updatedAt; } - const RelatedMany._internal({required this.id, required primaryId, primary, createdAt, updatedAt}): _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const RelatedMany._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory RelatedMany({String? id, required String primaryId, Primary? primary}) { + factory RelatedMany({String? id, Primary? primary}) { return RelatedMany._internal( id: id == null ? amplify_core.UUID.getUUID() : id, - primaryId: primaryId, primary: primary); } @@ -14831,7 +14464,6 @@ class RelatedMany extends amplify_core.Model { if (identical(other, this)) return true; return other is RelatedMany && id == other.id && - _primaryId == other._primaryId && _primary == other._primary; } @@ -14844,7 +14476,6 @@ class RelatedMany extends amplify_core.Model { buffer.write(\\"RelatedMany {\\"); buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); - buffer.write(\\"primaryId=\\" + \\"$_primaryId\\" + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -14853,27 +14484,23 @@ class RelatedMany extends amplify_core.Model { return buffer.toString(); } - RelatedMany copyWith({String? primaryId, Primary? primary}) { + RelatedMany copyWith({Primary? primary}) { return RelatedMany._internal( id: id, - primaryId: primaryId ?? this.primaryId, primary: primary ?? this.primary); } RelatedMany copyWithModelFieldValues({ - ModelFieldValue? primaryId, ModelFieldValue? primary }) { return RelatedMany._internal( id: id, - primaryId: primaryId == null ? this.primaryId : primaryId.value, primary: primary == null ? this.primary : primary.value ); } RelatedMany.fromJson(Map json) : id = json['id'], - _primaryId = json['primaryId'], _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -14883,12 +14510,11 @@ class RelatedMany extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, - 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -14896,7 +14522,6 @@ class RelatedMany extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); - static final PRIMARYID = amplify_core.QueryField(fieldName: \\"primaryId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); @@ -14910,16 +14535,10 @@ class RelatedMany extends amplify_core.Model { modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: RelatedMany.PRIMARYID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: RelatedMany.PRIMARY, isRequired: false, - targetNames: ['primaryRelatedManyId'], + targetNames: ['primaryId'], ofModelName: 'Primary' )); @@ -15031,7 +14650,6 @@ class SqlPrimary extends amplify_core.Model { final SqlRelated? _related; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; - final int? _sqlPrimaryRelatedId; @override getInstanceType() => classType; @@ -15062,18 +14680,13 @@ class SqlPrimary extends amplify_core.Model { return _updatedAt; } - int? get sqlPrimaryRelatedId { - return _sqlPrimaryRelatedId; - } - - const SqlPrimary._internal({required this.id, content, related, createdAt, updatedAt, sqlPrimaryRelatedId}): _content = content, _related = related, _createdAt = createdAt, _updatedAt = updatedAt, _sqlPrimaryRelatedId = sqlPrimaryRelatedId; + const SqlPrimary._internal({required this.id, content, related, createdAt, updatedAt}): _content = content, _related = related, _createdAt = createdAt, _updatedAt = updatedAt; - factory SqlPrimary({int? id, String? content, SqlRelated? related, int? sqlPrimaryRelatedId}) { + factory SqlPrimary({int? id, String? content, SqlRelated? related}) { return SqlPrimary._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, - related: related, - sqlPrimaryRelatedId: sqlPrimaryRelatedId); + related: related); } bool equals(Object other) { @@ -15086,8 +14699,7 @@ class SqlPrimary extends amplify_core.Model { return other is SqlPrimary && id == other.id && _content == other._content && - _related == other._related && - _sqlPrimaryRelatedId == other._sqlPrimaryRelatedId; + _related == other._related; } @override @@ -15101,31 +14713,27 @@ class SqlPrimary extends amplify_core.Model { buffer.write(\\"id=\\" + (id != null ? id!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\") + \\", \\"); - buffer.write(\\"sqlPrimaryRelatedId=\\" + (_sqlPrimaryRelatedId != null ? _sqlPrimaryRelatedId!.toString() : \\"null\\")); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); buffer.write(\\"}\\"); return buffer.toString(); } - SqlPrimary copyWith({String? content, SqlRelated? related, int? sqlPrimaryRelatedId}) { + SqlPrimary copyWith({String? content, SqlRelated? related}) { return SqlPrimary._internal( id: id, content: content ?? this.content, - related: related ?? this.related, - sqlPrimaryRelatedId: sqlPrimaryRelatedId ?? this.sqlPrimaryRelatedId); + related: related ?? this.related); } SqlPrimary copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? related, - ModelFieldValue? sqlPrimaryRelatedId + ModelFieldValue? related }) { return SqlPrimary._internal( id: id, content: content == null ? this.content : content.value, - related: related == null ? this.related : related.value, - sqlPrimaryRelatedId: sqlPrimaryRelatedId == null ? this.sqlPrimaryRelatedId : sqlPrimaryRelatedId.value + related: related == null ? this.related : related.value ); } @@ -15138,11 +14746,10 @@ class SqlPrimary extends amplify_core.Model { : SqlRelated.fromJson(new Map.from(json['related'])) : null, _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, - _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null, - _sqlPrimaryRelatedId = (json['sqlPrimaryRelatedId'] as num?)?.toInt(); + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'related': _related?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format(), 'sqlPrimaryRelatedId': _sqlPrimaryRelatedId + 'id': id, 'content': _content, 'related': _related?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { @@ -15150,8 +14757,7 @@ class SqlPrimary extends amplify_core.Model { 'content': _content, 'related': _related, 'createdAt': _createdAt, - 'updatedAt': _updatedAt, - 'sqlPrimaryRelatedId': _sqlPrimaryRelatedId + 'updatedAt': _updatedAt }; static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); @@ -15160,7 +14766,6 @@ class SqlPrimary extends amplify_core.Model { static final RELATED = amplify_core.QueryField( fieldName: \\"related\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlRelated')); - static final SQLPRIMARYRELATEDID = amplify_core.QueryField(fieldName: \\"sqlPrimaryRelatedId\\"); static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { modelSchemaDefinition.name = \\"SqlPrimary\\"; modelSchemaDefinition.pluralName = \\"SqlPrimaries\\"; @@ -15197,12 +14802,6 @@ class SqlPrimary extends amplify_core.Model { isReadOnly: true, ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) )); - - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: SqlPrimary.SQLPRIMARYRELATEDID, - isRequired: false, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.int) - )); }); } @@ -15295,7 +14894,6 @@ class SqlRelated extends amplify_core.Model { static const classType = const _SqlRelatedModelType(); final int id; final String? _content; - final int? _primaryId; final SqlPrimary? _primary; final amplify_core.TemporalDateTime? _createdAt; final amplify_core.TemporalDateTime? _updatedAt; @@ -15317,19 +14915,6 @@ class SqlRelated extends amplify_core.Model { return _content; } - int get primaryId { - try { - return _primaryId!; - } catch(e) { - throw amplify_core.AmplifyCodeGenModelException( - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, - recoverySuggestion: - amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, - underlyingException: e.toString() - ); - } - } - SqlPrimary? get primary { return _primary; } @@ -15342,13 +14927,12 @@ class SqlRelated extends amplify_core.Model { return _updatedAt; } - const SqlRelated._internal({required this.id, content, required primaryId, primary, createdAt, updatedAt}): _content = content, _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const SqlRelated._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory SqlRelated({int? id, String? content, required int primaryId, SqlPrimary? primary}) { + factory SqlRelated({int? id, String? content, SqlPrimary? primary}) { return SqlRelated._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, - primaryId: primaryId, primary: primary); } @@ -15362,7 +14946,6 @@ class SqlRelated extends amplify_core.Model { return other is SqlRelated && id == other.id && _content == other._content && - _primaryId == other._primaryId && _primary == other._primary; } @@ -15376,7 +14959,6 @@ class SqlRelated extends amplify_core.Model { buffer.write(\\"SqlRelated {\\"); buffer.write(\\"id=\\" + (id != null ? id!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); - buffer.write(\\"primaryId=\\" + (_primaryId != null ? _primaryId!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); @@ -15385,23 +14967,20 @@ class SqlRelated extends amplify_core.Model { return buffer.toString(); } - SqlRelated copyWith({String? content, int? primaryId, SqlPrimary? primary}) { + SqlRelated copyWith({String? content, SqlPrimary? primary}) { return SqlRelated._internal( id: id, content: content ?? this.content, - primaryId: primaryId ?? this.primaryId, primary: primary ?? this.primary); } SqlRelated copyWithModelFieldValues({ ModelFieldValue? content, - ModelFieldValue? primaryId, ModelFieldValue? primary }) { return SqlRelated._internal( id: id, content: content == null ? this.content : content.value, - primaryId: primaryId == null ? this.primaryId : primaryId.value, primary: primary == null ? this.primary : primary.value ); } @@ -15409,7 +14988,6 @@ class SqlRelated extends amplify_core.Model { SqlRelated.fromJson(Map json) : id = (json['id'] as num?)?.toInt(), _content = json['content'], - _primaryId = (json['primaryId'] as num?)?.toInt(), _primary = json['primary'] != null ? json['primary']['serializedData'] != null ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) @@ -15419,13 +14997,12 @@ class SqlRelated extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, - 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -15434,7 +15011,6 @@ class SqlRelated extends amplify_core.Model { static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); static final ID = amplify_core.QueryField(fieldName: \\"id\\"); static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); - static final PRIMARYID = amplify_core.QueryField(fieldName: \\"primaryId\\"); static final PRIMARY = amplify_core.QueryField( fieldName: \\"primary\\", fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlPrimary')); @@ -15455,16 +15031,10 @@ class SqlRelated extends amplify_core.Model { ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( - key: SqlRelated.PRIMARYID, - isRequired: true, - ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.int) - )); - modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( key: SqlRelated.PRIMARY, isRequired: false, - targetNames: ['sqlRelatedPrimaryId'], + targetNames: ['primaryId'], ofModelName: 'SqlPrimary' )); diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap index 5548dfa39..b68a0cec3 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-java-visitor.test.ts.snap @@ -7871,15 +7871,11 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; @ModelConfig(pluralName = \\"Foos\\", type = Model.Type.USER, version = 1) public final class Foo implements Model { public static final QueryField ID = field(\\"Foo\\", \\"id\\"); - public static final QueryField FOO_BAR1_ID = field(\\"Foo\\", \\"fooBar1Id\\"); - public static final QueryField FOO_BAR2_ID = field(\\"Foo\\", \\"fooBar2Id\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"Bar\\") @HasOne(associatedWith = \\"foo1\\", type = Bar.class) Bar bar1 = null; - private final @ModelField(targetType=\\"Bar\\") @HasOne(associatedWith = \\"foo1\\", type = Bar.class) Bar bar2 = null; + private final @ModelField(targetType=\\"Bar\\") @HasOne(associatedWith = \\"foo2\\", type = Bar.class) Bar bar2 = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String fooBar1Id; - private final @ModelField(targetType=\\"ID\\") String fooBar2Id; /** @deprecated This API is internal to Amplify and should not be used. */ @Deprecated public String resolveIdentifier() { @@ -7906,18 +7902,8 @@ public final class Foo implements Model { return updatedAt; } - public String getFooBar1Id() { - return fooBar1Id; - } - - public String getFooBar2Id() { - return fooBar2Id; - } - - private Foo(String id, String fooBar1Id, String fooBar2Id) { + private Foo(String id) { this.id = id; - this.fooBar1Id = fooBar1Id; - this.fooBar2Id = fooBar2Id; } @Override @@ -7930,9 +7916,7 @@ public final class Foo implements Model { Foo foo = (Foo) obj; return ObjectsCompat.equals(getId(), foo.getId()) && ObjectsCompat.equals(getCreatedAt(), foo.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), foo.getUpdatedAt()) && - ObjectsCompat.equals(getFooBar1Id(), foo.getFooBar1Id()) && - ObjectsCompat.equals(getFooBar2Id(), foo.getFooBar2Id()); + ObjectsCompat.equals(getUpdatedAt(), foo.getUpdatedAt()); } } @@ -7942,8 +7926,6 @@ public final class Foo implements Model { .append(getId()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getFooBar1Id()) - .append(getFooBar2Id()) .toString() .hashCode(); } @@ -7954,9 +7936,7 @@ public final class Foo implements Model { .append(\\"Foo {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"fooBar1Id=\\" + String.valueOf(getFooBar1Id()) + \\", \\") - .append(\\"fooBar2Id=\\" + String.valueOf(getFooBar2Id())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } @@ -7975,37 +7955,27 @@ public final class Foo implements Model { */ public static Foo justId(String id) { return new Foo( - id, - null, - null + id ); } public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - fooBar1Id, - fooBar2Id); + return new CopyOfBuilder(id); } public interface BuildStep { Foo build(); BuildStep id(String id); - BuildStep fooBar1Id(String fooBar1Id); - BuildStep fooBar2Id(String fooBar2Id); } public static class Builder implements BuildStep { private String id; - private String fooBar1Id; - private String fooBar2Id; public Builder() { } - private Builder(String id, String fooBar1Id, String fooBar2Id) { + private Builder(String id) { this.id = id; - this.fooBar1Id = fooBar1Id; - this.fooBar2Id = fooBar2Id; } @Override @@ -8013,21 +7983,7 @@ public final class Foo implements Model { String id = this.id != null ? this.id : UUID.randomUUID().toString(); return new Foo( - id, - fooBar1Id, - fooBar2Id); - } - - @Override - public BuildStep fooBar1Id(String fooBar1Id) { - this.fooBar1Id = fooBar1Id; - return this; - } - - @Override - public BuildStep fooBar2Id(String fooBar2Id) { - this.fooBar2Id = fooBar2Id; - return this; + id); } /** @@ -8042,20 +7998,10 @@ public final class Foo implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String fooBar1Id, String fooBar2Id) { - super(id, fooBar1Id, fooBar2Id); + private CopyOfBuilder(String id) { + super(id); } - - @Override - public CopyOfBuilder fooBar1Id(String fooBar1Id) { - return (CopyOfBuilder) super.fooBar1Id(fooBar1Id); - } - - @Override - public CopyOfBuilder fooBar2Id(String fooBar2Id) { - return (CopyOfBuilder) super.fooBar2Id(fooBar2Id); - } } @@ -8096,15 +8042,11 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; @ModelConfig(pluralName = \\"Bars\\", type = Model.Type.USER, version = 1) public final class Bar implements Model { public static final QueryField ID = field(\\"Bar\\", \\"id\\"); - public static final QueryField BAR1_ID = field(\\"Bar\\", \\"bar1Id\\"); - public static final QueryField BAR2_ID = field(\\"Bar\\", \\"bar2Id\\"); - public static final QueryField FOO1 = field(\\"Bar\\", \\"barFoo1Id\\"); - public static final QueryField FOO2 = field(\\"Bar\\", \\"barFoo2Id\\"); + public static final QueryField FOO1 = field(\\"Bar\\", \\"bar1Id\\"); + public static final QueryField FOO2 = field(\\"Bar\\", \\"bar2Id\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\") String bar1Id; - private final @ModelField(targetType=\\"ID\\") String bar2Id; - private final @ModelField(targetType=\\"Foo\\") @BelongsTo(targetName = \\"barFoo1Id\\", targetNames = {\\"barFoo1Id\\"}, type = Foo.class) Foo foo1; - private final @ModelField(targetType=\\"Foo\\") @BelongsTo(targetName = \\"barFoo2Id\\", targetNames = {\\"barFoo2Id\\"}, type = Foo.class) Foo foo2; + private final @ModelField(targetType=\\"Foo\\") @BelongsTo(targetName = \\"bar1Id\\", targetNames = {\\"bar1Id\\"}, type = Foo.class) Foo foo1; + private final @ModelField(targetType=\\"Foo\\") @BelongsTo(targetName = \\"bar2Id\\", targetNames = {\\"bar2Id\\"}, type = Foo.class) Foo foo2; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -8117,14 +8059,6 @@ public final class Bar implements Model { return id; } - public String getBar1Id() { - return bar1Id; - } - - public String getBar2Id() { - return bar2Id; - } - public Foo getFoo1() { return foo1; } @@ -8141,10 +8075,8 @@ public final class Bar implements Model { return updatedAt; } - private Bar(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { + private Bar(String id, Foo foo1, Foo foo2) { this.id = id; - this.bar1Id = bar1Id; - this.bar2Id = bar2Id; this.foo1 = foo1; this.foo2 = foo2; } @@ -8158,8 +8090,6 @@ public final class Bar implements Model { } else { Bar bar = (Bar) obj; return ObjectsCompat.equals(getId(), bar.getId()) && - ObjectsCompat.equals(getBar1Id(), bar.getBar1Id()) && - ObjectsCompat.equals(getBar2Id(), bar.getBar2Id()) && ObjectsCompat.equals(getFoo1(), bar.getFoo1()) && ObjectsCompat.equals(getFoo2(), bar.getFoo2()) && ObjectsCompat.equals(getCreatedAt(), bar.getCreatedAt()) && @@ -8171,8 +8101,6 @@ public final class Bar implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getBar1Id()) - .append(getBar2Id()) .append(getFoo1()) .append(getFoo2()) .append(getCreatedAt()) @@ -8186,8 +8114,6 @@ public final class Bar implements Model { return new StringBuilder() .append(\\"Bar {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"bar1Id=\\" + String.valueOf(getBar1Id()) + \\", \\") - .append(\\"bar2Id=\\" + String.valueOf(getBar2Id()) + \\", \\") .append(\\"foo1=\\" + String.valueOf(getFoo1()) + \\", \\") .append(\\"foo2=\\" + String.valueOf(getFoo2()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") @@ -8212,24 +8138,18 @@ public final class Bar implements Model { return new Bar( id, null, - null, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - bar1Id, - bar2Id, foo1, foo2); } public interface BuildStep { Bar build(); BuildStep id(String id); - BuildStep bar1Id(String bar1Id); - BuildStep bar2Id(String bar2Id); BuildStep foo1(Foo foo1); BuildStep foo2(Foo foo2); } @@ -8237,18 +8157,14 @@ public final class Bar implements Model { public static class Builder implements BuildStep { private String id; - private String bar1Id; - private String bar2Id; private Foo foo1; private Foo foo2; public Builder() { } - private Builder(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { + private Builder(String id, Foo foo1, Foo foo2) { this.id = id; - this.bar1Id = bar1Id; - this.bar2Id = bar2Id; this.foo1 = foo1; this.foo2 = foo2; } @@ -8259,24 +8175,10 @@ public final class Bar implements Model { return new Bar( id, - bar1Id, - bar2Id, foo1, foo2); } - @Override - public BuildStep bar1Id(String bar1Id) { - this.bar1Id = bar1Id; - return this; - } - - @Override - public BuildStep bar2Id(String bar2Id) { - this.bar2Id = bar2Id; - return this; - } - @Override public BuildStep foo1(Foo foo1) { this.foo1 = foo1; @@ -8301,21 +8203,11 @@ public final class Bar implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { - super(id, bar1Id, bar2Id, foo1, foo2); + private CopyOfBuilder(String id, Foo foo1, Foo foo2) { + super(id, foo1, foo2); } - @Override - public CopyOfBuilder bar1Id(String bar1Id) { - return (CopyOfBuilder) super.bar1Id(bar1Id); - } - - @Override - public CopyOfBuilder bar2Id(String bar2Id) { - return (CopyOfBuilder) super.bar2Id(bar2Id); - } - @Override public CopyOfBuilder foo1(Foo foo1) { return (CopyOfBuilder) super.foo1(foo1); @@ -8619,16 +8511,10 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; public final class Related implements Model { public static final QueryField ID = field(\\"Related\\", \\"id\\"); public static final QueryField CONTENT = field(\\"Related\\", \\"content\\"); - public static final QueryField PRIMARY_TENANT_ID = field(\\"Related\\", \\"primaryTenantId\\"); - public static final QueryField PRIMARY_INSTANCE_ID = field(\\"Related\\", \\"primaryInstanceId\\"); - public static final QueryField PRIMARY_RECORD_ID = field(\\"Related\\", \\"primaryRecordId\\"); - public static final QueryField PRIMARY = field(\\"Related\\", \\"primaryRelatedTenantId\\"); + public static final QueryField PRIMARY = field(\\"Related\\", \\"primaryTenantId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryTenantId; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryInstanceId; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryRecordId; - private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryRelatedTenantId\\", targetNames = {\\"primaryRelatedTenantId\\", \\"primaryRelatedInstanceId\\", \\"primaryRelatedRecordId\\"}, type = Primary.class) Primary primary; + private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryTenantId\\", targetNames = {\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"}, type = Primary.class) Primary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -8645,18 +8531,6 @@ public final class Related implements Model { return content; } - public String getPrimaryTenantId() { - return primaryTenantId; - } - - public String getPrimaryInstanceId() { - return primaryInstanceId; - } - - public String getPrimaryRecordId() { - return primaryRecordId; - } - public Primary getPrimary() { return primary; } @@ -8669,12 +8543,9 @@ public final class Related implements Model { return updatedAt; } - private Related(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { + private Related(String id, String content, Primary primary) { this.id = id; this.content = content; - this.primaryTenantId = primaryTenantId; - this.primaryInstanceId = primaryInstanceId; - this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -8688,9 +8559,6 @@ public final class Related implements Model { Related related = (Related) obj; return ObjectsCompat.equals(getId(), related.getId()) && ObjectsCompat.equals(getContent(), related.getContent()) && - ObjectsCompat.equals(getPrimaryTenantId(), related.getPrimaryTenantId()) && - ObjectsCompat.equals(getPrimaryInstanceId(), related.getPrimaryInstanceId()) && - ObjectsCompat.equals(getPrimaryRecordId(), related.getPrimaryRecordId()) && ObjectsCompat.equals(getPrimary(), related.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), related.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), related.getUpdatedAt()); @@ -8702,9 +8570,6 @@ public final class Related implements Model { return new StringBuilder() .append(getId()) .append(getContent()) - .append(getPrimaryTenantId()) - .append(getPrimaryInstanceId()) - .append(getPrimaryRecordId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -8718,9 +8583,6 @@ public final class Related implements Model { .append(\\"Related {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"primaryTenantId=\\" + String.valueOf(getPrimaryTenantId()) + \\", \\") - .append(\\"primaryInstanceId=\\" + String.valueOf(getPrimaryInstanceId()) + \\", \\") - .append(\\"primaryRecordId=\\" + String.valueOf(getPrimaryRecordId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -8728,7 +8590,7 @@ public final class Related implements Model { .toString(); } - public static PrimaryTenantIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -8744,9 +8606,6 @@ public final class Related implements Model { return new Related( id, null, - null, - null, - null, null ); } @@ -8754,26 +8613,8 @@ public final class Related implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, content, - primaryTenantId, - primaryInstanceId, - primaryRecordId, primary); } - public interface PrimaryTenantIdStep { - PrimaryInstanceIdStep primaryTenantId(String primaryTenantId); - } - - - public interface PrimaryInstanceIdStep { - PrimaryRecordIdStep primaryInstanceId(String primaryInstanceId); - } - - - public interface PrimaryRecordIdStep { - BuildStep primaryRecordId(String primaryRecordId); - } - - public interface BuildStep { Related build(); BuildStep id(String id); @@ -8782,23 +8623,17 @@ public final class Related implements Model { } - public static class Builder implements PrimaryTenantIdStep, PrimaryInstanceIdStep, PrimaryRecordIdStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String primaryTenantId; - private String primaryInstanceId; - private String primaryRecordId; private String content; private Primary primary; public Builder() { } - private Builder(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { + private Builder(String id, String content, Primary primary) { this.id = id; this.content = content; - this.primaryTenantId = primaryTenantId; - this.primaryInstanceId = primaryInstanceId; - this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -8809,33 +8644,9 @@ public final class Related implements Model { return new Related( id, content, - primaryTenantId, - primaryInstanceId, - primaryRecordId, primary); } - @Override - public PrimaryInstanceIdStep primaryTenantId(String primaryTenantId) { - Objects.requireNonNull(primaryTenantId); - this.primaryTenantId = primaryTenantId; - return this; - } - - @Override - public PrimaryRecordIdStep primaryInstanceId(String primaryInstanceId) { - Objects.requireNonNull(primaryInstanceId); - this.primaryInstanceId = primaryInstanceId; - return this; - } - - @Override - public BuildStep primaryRecordId(String primaryRecordId) { - Objects.requireNonNull(primaryRecordId); - this.primaryRecordId = primaryRecordId; - return this; - } - @Override public BuildStep content(String content) { this.content = content; @@ -8860,26 +8671,9 @@ public final class Related implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { - super(id, content, primaryTenantId, primaryInstanceId, primaryRecordId, primary); - Objects.requireNonNull(primaryTenantId); - Objects.requireNonNull(primaryInstanceId); - Objects.requireNonNull(primaryRecordId); - } - - @Override - public CopyOfBuilder primaryTenantId(String primaryTenantId) { - return (CopyOfBuilder) super.primaryTenantId(primaryTenantId); - } - - @Override - public CopyOfBuilder primaryInstanceId(String primaryInstanceId) { - return (CopyOfBuilder) super.primaryInstanceId(primaryInstanceId); - } - - @Override - public CopyOfBuilder primaryRecordId(String primaryRecordId) { - return (CopyOfBuilder) super.primaryRecordId(primaryRecordId); + private CopyOfBuilder(String id, String content, Primary primary) { + super(id, content, primary); + } @Override @@ -8935,7 +8729,6 @@ public final class Primary implements Model { public static final QueryField INSTANCE_ID = field(\\"Primary\\", \\"instanceId\\"); public static final QueryField RECORD_ID = field(\\"Primary\\", \\"recordId\\"); public static final QueryField CONTENT = field(\\"Primary\\", \\"content\\"); - public static final QueryField PRIMARY_RELATED_ID = field(\\"Primary\\", \\"primaryRelatedId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String tenantId; private final @ModelField(targetType=\\"ID\\", isRequired = true) String instanceId; private final @ModelField(targetType=\\"ID\\", isRequired = true) String recordId; @@ -8943,7 +8736,6 @@ public final class Primary implements Model { private final @ModelField(targetType=\\"Related\\") @HasOne(associatedWith = \\"primary\\", type = Related.class) Related related = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String primaryRelatedId; private PrimaryIdentifier primaryIdentifier; /** @deprecated This API is internal to Amplify and should not be used. */ @Deprecated @@ -8982,16 +8774,11 @@ public final class Primary implements Model { return updatedAt; } - public String getPrimaryRelatedId() { - return primaryRelatedId; - } - - private Primary(String tenantId, String instanceId, String recordId, String content, String primaryRelatedId) { + private Primary(String tenantId, String instanceId, String recordId, String content) { this.tenantId = tenantId; this.instanceId = instanceId; this.recordId = recordId; this.content = content; - this.primaryRelatedId = primaryRelatedId; } @Override @@ -9007,8 +8794,7 @@ public final class Primary implements Model { ObjectsCompat.equals(getRecordId(), primary.getRecordId()) && ObjectsCompat.equals(getContent(), primary.getContent()) && ObjectsCompat.equals(getCreatedAt(), primary.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()) && - ObjectsCompat.equals(getPrimaryRelatedId(), primary.getPrimaryRelatedId()); + ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()); } } @@ -9021,7 +8807,6 @@ public final class Primary implements Model { .append(getContent()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getPrimaryRelatedId()) .toString() .hashCode(); } @@ -9035,8 +8820,7 @@ public final class Primary implements Model { .append(\\"recordId=\\" + String.valueOf(getRecordId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"primaryRelatedId=\\" + String.valueOf(getPrimaryRelatedId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } @@ -9049,8 +8833,7 @@ public final class Primary implements Model { return new CopyOfBuilder(tenantId, instanceId, recordId, - content, - primaryRelatedId); + content); } public interface TenantIdStep { InstanceIdStep tenantId(String tenantId); @@ -9070,7 +8853,6 @@ public final class Primary implements Model { public interface BuildStep { Primary build(); BuildStep content(String content); - BuildStep primaryRelatedId(String primaryRelatedId); } @@ -9079,17 +8861,15 @@ public final class Primary implements Model { private String instanceId; private String recordId; private String content; - private String primaryRelatedId; public Builder() { } - private Builder(String tenantId, String instanceId, String recordId, String content, String primaryRelatedId) { + private Builder(String tenantId, String instanceId, String recordId, String content) { this.tenantId = tenantId; this.instanceId = instanceId; this.recordId = recordId; this.content = content; - this.primaryRelatedId = primaryRelatedId; } @Override @@ -9099,8 +8879,7 @@ public final class Primary implements Model { tenantId, instanceId, recordId, - content, - primaryRelatedId); + content); } @Override @@ -9129,18 +8908,12 @@ public final class Primary implements Model { this.content = content; return this; } - - @Override - public BuildStep primaryRelatedId(String primaryRelatedId) { - this.primaryRelatedId = primaryRelatedId; - return this; - } } public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String tenantId, String instanceId, String recordId, String content, String primaryRelatedId) { - super(tenantId, instanceId, recordId, content, primaryRelatedId); + private CopyOfBuilder(String tenantId, String instanceId, String recordId, String content) { + super(tenantId, instanceId, recordId, content); Objects.requireNonNull(tenantId); Objects.requireNonNull(instanceId); Objects.requireNonNull(recordId); @@ -9165,11 +8938,6 @@ public final class Primary implements Model { public CopyOfBuilder content(String content) { return (CopyOfBuilder) super.content(content); } - - @Override - public CopyOfBuilder primaryRelatedId(String primaryRelatedId) { - return (CopyOfBuilder) super.primaryRelatedId(primaryRelatedId); - } } @@ -9211,16 +8979,10 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; public final class Related implements Model { public static final QueryField ID = field(\\"Related\\", \\"id\\"); public static final QueryField CONTENT = field(\\"Related\\", \\"content\\"); - public static final QueryField PRIMARY_TENANT_ID = field(\\"Related\\", \\"primaryTenantId\\"); - public static final QueryField PRIMARY_INSTANCE_ID = field(\\"Related\\", \\"primaryInstanceId\\"); - public static final QueryField PRIMARY_RECORD_ID = field(\\"Related\\", \\"primaryRecordId\\"); - public static final QueryField PRIMARY = field(\\"Related\\", \\"relatedPrimaryTenantId\\"); + public static final QueryField PRIMARY = field(\\"Related\\", \\"primaryTenantId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryTenantId; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryInstanceId; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryRecordId; - private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"relatedPrimaryTenantId\\", targetNames = {\\"relatedPrimaryTenantId\\", \\"relatedPrimaryInstanceId\\", \\"relatedPrimaryRecordId\\"}, type = Primary.class) Primary primary; + private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryTenantId\\", targetNames = {\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"}, type = Primary.class) Primary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -9237,18 +8999,6 @@ public final class Related implements Model { return content; } - public String getPrimaryTenantId() { - return primaryTenantId; - } - - public String getPrimaryInstanceId() { - return primaryInstanceId; - } - - public String getPrimaryRecordId() { - return primaryRecordId; - } - public Primary getPrimary() { return primary; } @@ -9261,12 +9011,9 @@ public final class Related implements Model { return updatedAt; } - private Related(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { + private Related(String id, String content, Primary primary) { this.id = id; this.content = content; - this.primaryTenantId = primaryTenantId; - this.primaryInstanceId = primaryInstanceId; - this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -9280,9 +9027,6 @@ public final class Related implements Model { Related related = (Related) obj; return ObjectsCompat.equals(getId(), related.getId()) && ObjectsCompat.equals(getContent(), related.getContent()) && - ObjectsCompat.equals(getPrimaryTenantId(), related.getPrimaryTenantId()) && - ObjectsCompat.equals(getPrimaryInstanceId(), related.getPrimaryInstanceId()) && - ObjectsCompat.equals(getPrimaryRecordId(), related.getPrimaryRecordId()) && ObjectsCompat.equals(getPrimary(), related.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), related.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), related.getUpdatedAt()); @@ -9294,9 +9038,6 @@ public final class Related implements Model { return new StringBuilder() .append(getId()) .append(getContent()) - .append(getPrimaryTenantId()) - .append(getPrimaryInstanceId()) - .append(getPrimaryRecordId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -9310,9 +9051,6 @@ public final class Related implements Model { .append(\\"Related {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"primaryTenantId=\\" + String.valueOf(getPrimaryTenantId()) + \\", \\") - .append(\\"primaryInstanceId=\\" + String.valueOf(getPrimaryInstanceId()) + \\", \\") - .append(\\"primaryRecordId=\\" + String.valueOf(getPrimaryRecordId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -9320,7 +9058,7 @@ public final class Related implements Model { .toString(); } - public static PrimaryTenantIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -9336,9 +9074,6 @@ public final class Related implements Model { return new Related( id, null, - null, - null, - null, null ); } @@ -9346,26 +9081,8 @@ public final class Related implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, content, - primaryTenantId, - primaryInstanceId, - primaryRecordId, primary); } - public interface PrimaryTenantIdStep { - PrimaryInstanceIdStep primaryTenantId(String primaryTenantId); - } - - - public interface PrimaryInstanceIdStep { - PrimaryRecordIdStep primaryInstanceId(String primaryInstanceId); - } - - - public interface PrimaryRecordIdStep { - BuildStep primaryRecordId(String primaryRecordId); - } - - public interface BuildStep { Related build(); BuildStep id(String id); @@ -9374,23 +9091,17 @@ public final class Related implements Model { } - public static class Builder implements PrimaryTenantIdStep, PrimaryInstanceIdStep, PrimaryRecordIdStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String primaryTenantId; - private String primaryInstanceId; - private String primaryRecordId; private String content; private Primary primary; public Builder() { } - private Builder(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { + private Builder(String id, String content, Primary primary) { this.id = id; this.content = content; - this.primaryTenantId = primaryTenantId; - this.primaryInstanceId = primaryInstanceId; - this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -9401,33 +9112,9 @@ public final class Related implements Model { return new Related( id, content, - primaryTenantId, - primaryInstanceId, - primaryRecordId, primary); } - @Override - public PrimaryInstanceIdStep primaryTenantId(String primaryTenantId) { - Objects.requireNonNull(primaryTenantId); - this.primaryTenantId = primaryTenantId; - return this; - } - - @Override - public PrimaryRecordIdStep primaryInstanceId(String primaryInstanceId) { - Objects.requireNonNull(primaryInstanceId); - this.primaryInstanceId = primaryInstanceId; - return this; - } - - @Override - public BuildStep primaryRecordId(String primaryRecordId) { - Objects.requireNonNull(primaryRecordId); - this.primaryRecordId = primaryRecordId; - return this; - } - @Override public BuildStep content(String content) { this.content = content; @@ -9452,26 +9139,9 @@ public final class Related implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { - super(id, content, primaryTenantId, primaryInstanceId, primaryRecordId, primary); - Objects.requireNonNull(primaryTenantId); - Objects.requireNonNull(primaryInstanceId); - Objects.requireNonNull(primaryRecordId); - } - - @Override - public CopyOfBuilder primaryTenantId(String primaryTenantId) { - return (CopyOfBuilder) super.primaryTenantId(primaryTenantId); - } - - @Override - public CopyOfBuilder primaryInstanceId(String primaryInstanceId) { - return (CopyOfBuilder) super.primaryInstanceId(primaryInstanceId); - } - - @Override - public CopyOfBuilder primaryRecordId(String primaryRecordId) { - return (CopyOfBuilder) super.primaryRecordId(primaryRecordId); + private CopyOfBuilder(String id, String content, Primary primary) { + super(id, content, primary); + } @Override @@ -9720,12 +9390,10 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; public final class SqlRelated implements Model { public static final QueryField ID = field(\\"SqlRelated\\", \\"id\\"); public static final QueryField CONTENT = field(\\"SqlRelated\\", \\"content\\"); - public static final QueryField PRIMARY_ID = field(\\"SqlRelated\\", \\"primaryId\\"); - public static final QueryField PRIMARY = field(\\"SqlRelated\\", \\"sqlPrimaryRelatedId\\"); + public static final QueryField PRIMARY = field(\\"SqlRelated\\", \\"primaryId\\"); private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer primaryId; - private final @ModelField(targetType=\\"SqlPrimary\\") @BelongsTo(targetName = \\"sqlPrimaryRelatedId\\", targetNames = {\\"sqlPrimaryRelatedId\\"}, type = SqlPrimary.class) SqlPrimary primary; + private final @ModelField(targetType=\\"SqlPrimary\\") @BelongsTo(targetName = \\"primaryId\\", targetNames = {\\"primaryId\\"}, type = SqlPrimary.class) SqlPrimary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -9742,10 +9410,6 @@ public final class SqlRelated implements Model { return content; } - public Integer getPrimaryId() { - return primaryId; - } - public SqlPrimary getPrimary() { return primary; } @@ -9758,10 +9422,9 @@ public final class SqlRelated implements Model { return updatedAt; } - private SqlRelated(Integer id, String content, Integer primaryId, SqlPrimary primary) { + private SqlRelated(Integer id, String content, SqlPrimary primary) { this.id = id; this.content = content; - this.primaryId = primaryId; this.primary = primary; } @@ -9775,7 +9438,6 @@ public final class SqlRelated implements Model { SqlRelated sqlRelated = (SqlRelated) obj; return ObjectsCompat.equals(getId(), sqlRelated.getId()) && ObjectsCompat.equals(getContent(), sqlRelated.getContent()) && - ObjectsCompat.equals(getPrimaryId(), sqlRelated.getPrimaryId()) && ObjectsCompat.equals(getPrimary(), sqlRelated.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), sqlRelated.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), sqlRelated.getUpdatedAt()); @@ -9787,7 +9449,6 @@ public final class SqlRelated implements Model { return new StringBuilder() .append(getId()) .append(getContent()) - .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -9801,7 +9462,6 @@ public final class SqlRelated implements Model { .append(\\"SqlRelated {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"primaryId=\\" + String.valueOf(getPrimaryId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -9809,7 +9469,7 @@ public final class SqlRelated implements Model { .toString(); } - public static PrimaryIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -9825,7 +9485,6 @@ public final class SqlRelated implements Model { return new SqlRelated( id, null, - null, null ); } @@ -9833,14 +9492,8 @@ public final class SqlRelated implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, content, - primaryId, primary); } - public interface PrimaryIdStep { - BuildStep primaryId(Integer primaryId); - } - - public interface BuildStep { SqlRelated build(); BuildStep id(String id); @@ -9849,19 +9502,17 @@ public final class SqlRelated implements Model { } - public static class Builder implements PrimaryIdStep, BuildStep { + public static class Builder implements BuildStep { private Integer id; - private Integer primaryId; private String content; private SqlPrimary primary; public Builder() { } - private Builder(Integer id, String content, Integer primaryId, SqlPrimary primary) { + private Builder(Integer id, String content, SqlPrimary primary) { this.id = id; this.content = content; - this.primaryId = primaryId; this.primary = primary; } @@ -9872,17 +9523,9 @@ public final class SqlRelated implements Model { return new SqlRelated( id, content, - primaryId, primary); } - @Override - public BuildStep primaryId(Integer primaryId) { - Objects.requireNonNull(primaryId); - this.primaryId = primaryId; - return this; - } - @Override public BuildStep content(String content) { this.content = content; @@ -9907,14 +9550,9 @@ public final class SqlRelated implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(Integer id, String content, Integer primaryId, SqlPrimary primary) { - super(id, content, primaryId, primary); - Objects.requireNonNull(primaryId); - } - - @Override - public CopyOfBuilder primaryId(Integer primaryId) { - return (CopyOfBuilder) super.primaryId(primaryId); + private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { + super(id, content, primary); + } @Override @@ -9968,13 +9606,11 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; @Index(name = \\"undefined\\", fields = {\\"id\\"}) public final class Primary implements Model { public static final QueryField ID = field(\\"Primary\\", \\"id\\"); - public static final QueryField PRIMARY_RELATED_ONE_ID = field(\\"Primary\\", \\"primaryRelatedOneId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; private final @ModelField(targetType=\\"RelatedMany\\") @HasMany(associatedWith = \\"primary\\", type = RelatedMany.class) List relatedMany = null; private final @ModelField(targetType=\\"RelatedOne\\") @HasOne(associatedWith = \\"primary\\", type = RelatedOne.class) RelatedOne relatedOne = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"ID\\") String primaryRelatedOneId; /** @deprecated This API is internal to Amplify and should not be used. */ @Deprecated public String resolveIdentifier() { @@ -10001,13 +9637,8 @@ public final class Primary implements Model { return updatedAt; } - public String getPrimaryRelatedOneId() { - return primaryRelatedOneId; - } - - private Primary(String id, String primaryRelatedOneId) { + private Primary(String id) { this.id = id; - this.primaryRelatedOneId = primaryRelatedOneId; } @Override @@ -10020,8 +9651,7 @@ public final class Primary implements Model { Primary primary = (Primary) obj; return ObjectsCompat.equals(getId(), primary.getId()) && ObjectsCompat.equals(getCreatedAt(), primary.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()) && - ObjectsCompat.equals(getPrimaryRelatedOneId(), primary.getPrimaryRelatedOneId()); + ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()); } } @@ -10031,7 +9661,6 @@ public final class Primary implements Model { .append(getId()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getPrimaryRelatedOneId()) .toString() .hashCode(); } @@ -10042,8 +9671,7 @@ public final class Primary implements Model { .append(\\"Primary {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"primaryRelatedOneId=\\" + String.valueOf(getPrimaryRelatedOneId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } @@ -10062,32 +9690,27 @@ public final class Primary implements Model { */ public static Primary justId(String id) { return new Primary( - id, - null + id ); } public CopyOfBuilder copyOfBuilder() { - return new CopyOfBuilder(id, - primaryRelatedOneId); + return new CopyOfBuilder(id); } public interface BuildStep { Primary build(); BuildStep id(String id); - BuildStep primaryRelatedOneId(String primaryRelatedOneId); } public static class Builder implements BuildStep { private String id; - private String primaryRelatedOneId; public Builder() { } - private Builder(String id, String primaryRelatedOneId) { + private Builder(String id) { this.id = id; - this.primaryRelatedOneId = primaryRelatedOneId; } @Override @@ -10095,14 +9718,7 @@ public final class Primary implements Model { String id = this.id != null ? this.id : UUID.randomUUID().toString(); return new Primary( - id, - primaryRelatedOneId); - } - - @Override - public BuildStep primaryRelatedOneId(String primaryRelatedOneId) { - this.primaryRelatedOneId = primaryRelatedOneId; - return this; + id); } /** @@ -10117,15 +9733,10 @@ public final class Primary implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String primaryRelatedOneId) { - super(id, primaryRelatedOneId); + private CopyOfBuilder(String id) { + super(id); } - - @Override - public CopyOfBuilder primaryRelatedOneId(String primaryRelatedOneId) { - return (CopyOfBuilder) super.primaryRelatedOneId(primaryRelatedOneId); - } } @@ -10167,11 +9778,9 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; @Index(name = \\"undefined\\", fields = {\\"id\\"}) public final class RelatedMany implements Model { public static final QueryField ID = field(\\"RelatedMany\\", \\"id\\"); - public static final QueryField PRIMARY_ID = field(\\"RelatedMany\\", \\"primaryId\\"); - public static final QueryField PRIMARY = field(\\"RelatedMany\\", \\"primaryRelatedManyId\\"); + public static final QueryField PRIMARY = field(\\"RelatedMany\\", \\"primaryId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryId; - private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryRelatedManyId\\", targetNames = {\\"primaryRelatedManyId\\"}, type = Primary.class) Primary primary; + private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryId\\", targetNames = {\\"primaryId\\"}, type = Primary.class) Primary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -10184,10 +9793,6 @@ public final class RelatedMany implements Model { return id; } - public String getPrimaryId() { - return primaryId; - } - public Primary getPrimary() { return primary; } @@ -10200,9 +9805,8 @@ public final class RelatedMany implements Model { return updatedAt; } - private RelatedMany(String id, String primaryId, Primary primary) { + private RelatedMany(String id, Primary primary) { this.id = id; - this.primaryId = primaryId; this.primary = primary; } @@ -10215,7 +9819,6 @@ public final class RelatedMany implements Model { } else { RelatedMany relatedMany = (RelatedMany) obj; return ObjectsCompat.equals(getId(), relatedMany.getId()) && - ObjectsCompat.equals(getPrimaryId(), relatedMany.getPrimaryId()) && ObjectsCompat.equals(getPrimary(), relatedMany.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), relatedMany.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), relatedMany.getUpdatedAt()); @@ -10226,7 +9829,6 @@ public final class RelatedMany implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -10239,7 +9841,6 @@ public final class RelatedMany implements Model { return new StringBuilder() .append(\\"RelatedMany {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"primaryId=\\" + String.valueOf(getPrimaryId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -10247,7 +9848,7 @@ public final class RelatedMany implements Model { .toString(); } - public static PrimaryIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -10262,21 +9863,14 @@ public final class RelatedMany implements Model { public static RelatedMany justId(String id) { return new RelatedMany( id, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - primaryId, primary); } - public interface PrimaryIdStep { - BuildStep primaryId(String primaryId); - } - - public interface BuildStep { RelatedMany build(); BuildStep id(String id); @@ -10284,17 +9878,15 @@ public final class RelatedMany implements Model { } - public static class Builder implements PrimaryIdStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String primaryId; private Primary primary; public Builder() { } - private Builder(String id, String primaryId, Primary primary) { + private Builder(String id, Primary primary) { this.id = id; - this.primaryId = primaryId; this.primary = primary; } @@ -10304,17 +9896,9 @@ public final class RelatedMany implements Model { return new RelatedMany( id, - primaryId, primary); } - @Override - public BuildStep primaryId(String primaryId) { - Objects.requireNonNull(primaryId); - this.primaryId = primaryId; - return this; - } - @Override public BuildStep primary(Primary primary) { this.primary = primary; @@ -10333,14 +9917,9 @@ public final class RelatedMany implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String primaryId, Primary primary) { - super(id, primaryId, primary); - Objects.requireNonNull(primaryId); - } - - @Override - public CopyOfBuilder primaryId(String primaryId) { - return (CopyOfBuilder) super.primaryId(primaryId); + private CopyOfBuilder(String id, Primary primary) { + super(id, primary); + } @Override @@ -10388,11 +9967,9 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; @Index(name = \\"undefined\\", fields = {\\"id\\"}) public final class RelatedOne implements Model { public static final QueryField ID = field(\\"RelatedOne\\", \\"id\\"); - public static final QueryField PRIMARY_ID = field(\\"RelatedOne\\", \\"primaryId\\"); - public static final QueryField PRIMARY = field(\\"RelatedOne\\", \\"relatedOnePrimaryId\\"); + public static final QueryField PRIMARY = field(\\"RelatedOne\\", \\"primaryId\\"); private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; - private final @ModelField(targetType=\\"ID\\", isRequired = true) String primaryId; - private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"relatedOnePrimaryId\\", targetNames = {\\"relatedOnePrimaryId\\"}, type = Primary.class) Primary primary; + private final @ModelField(targetType=\\"Primary\\") @BelongsTo(targetName = \\"primaryId\\", targetNames = {\\"primaryId\\"}, type = Primary.class) Primary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -10405,10 +9982,6 @@ public final class RelatedOne implements Model { return id; } - public String getPrimaryId() { - return primaryId; - } - public Primary getPrimary() { return primary; } @@ -10421,9 +9994,8 @@ public final class RelatedOne implements Model { return updatedAt; } - private RelatedOne(String id, String primaryId, Primary primary) { + private RelatedOne(String id, Primary primary) { this.id = id; - this.primaryId = primaryId; this.primary = primary; } @@ -10436,7 +10008,6 @@ public final class RelatedOne implements Model { } else { RelatedOne relatedOne = (RelatedOne) obj; return ObjectsCompat.equals(getId(), relatedOne.getId()) && - ObjectsCompat.equals(getPrimaryId(), relatedOne.getPrimaryId()) && ObjectsCompat.equals(getPrimary(), relatedOne.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), relatedOne.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), relatedOne.getUpdatedAt()); @@ -10447,7 +10018,6 @@ public final class RelatedOne implements Model { public int hashCode() { return new StringBuilder() .append(getId()) - .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -10460,7 +10030,6 @@ public final class RelatedOne implements Model { return new StringBuilder() .append(\\"RelatedOne {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") - .append(\\"primaryId=\\" + String.valueOf(getPrimaryId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -10468,7 +10037,7 @@ public final class RelatedOne implements Model { .toString(); } - public static PrimaryIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -10483,21 +10052,14 @@ public final class RelatedOne implements Model { public static RelatedOne justId(String id) { return new RelatedOne( id, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - primaryId, primary); } - public interface PrimaryIdStep { - BuildStep primaryId(String primaryId); - } - - public interface BuildStep { RelatedOne build(); BuildStep id(String id); @@ -10505,17 +10067,15 @@ public final class RelatedOne implements Model { } - public static class Builder implements PrimaryIdStep, BuildStep { + public static class Builder implements BuildStep { private String id; - private String primaryId; private Primary primary; public Builder() { } - private Builder(String id, String primaryId, Primary primary) { + private Builder(String id, Primary primary) { this.id = id; - this.primaryId = primaryId; this.primary = primary; } @@ -10525,17 +10085,9 @@ public final class RelatedOne implements Model { return new RelatedOne( id, - primaryId, primary); } - @Override - public BuildStep primaryId(String primaryId) { - Objects.requireNonNull(primaryId); - this.primaryId = primaryId; - return this; - } - @Override public BuildStep primary(Primary primary) { this.primary = primary; @@ -10554,14 +10106,9 @@ public final class RelatedOne implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String primaryId, Primary primary) { - super(id, primaryId, primary); - Objects.requireNonNull(primaryId); - } - - @Override - public CopyOfBuilder primaryId(String primaryId) { - return (CopyOfBuilder) super.primaryId(primaryId); + private CopyOfBuilder(String id, Primary primary) { + super(id, primary); + } @Override @@ -10610,13 +10157,11 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; public final class SqlPrimary implements Model { public static final QueryField ID = field(\\"SqlPrimary\\", \\"id\\"); public static final QueryField CONTENT = field(\\"SqlPrimary\\", \\"content\\"); - public static final QueryField SQL_PRIMARY_RELATED_ID = field(\\"SqlPrimary\\", \\"sqlPrimaryRelatedId\\"); private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; private final @ModelField(targetType=\\"String\\") String content; private final @ModelField(targetType=\\"SqlRelated\\") @HasOne(associatedWith = \\"primary\\", type = SqlRelated.class) SqlRelated related = null; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; - private final @ModelField(targetType=\\"Int\\") Integer sqlPrimaryRelatedId; /** @deprecated This API is internal to Amplify and should not be used. */ @Deprecated public Integer resolveIdentifier() { @@ -10643,14 +10188,9 @@ public final class SqlPrimary implements Model { return updatedAt; } - public Integer getSqlPrimaryRelatedId() { - return sqlPrimaryRelatedId; - } - - private SqlPrimary(Integer id, String content, Integer sqlPrimaryRelatedId) { + private SqlPrimary(Integer id, String content) { this.id = id; this.content = content; - this.sqlPrimaryRelatedId = sqlPrimaryRelatedId; } @Override @@ -10664,8 +10204,7 @@ public final class SqlPrimary implements Model { return ObjectsCompat.equals(getId(), sqlPrimary.getId()) && ObjectsCompat.equals(getContent(), sqlPrimary.getContent()) && ObjectsCompat.equals(getCreatedAt(), sqlPrimary.getCreatedAt()) && - ObjectsCompat.equals(getUpdatedAt(), sqlPrimary.getUpdatedAt()) && - ObjectsCompat.equals(getSqlPrimaryRelatedId(), sqlPrimary.getSqlPrimaryRelatedId()); + ObjectsCompat.equals(getUpdatedAt(), sqlPrimary.getUpdatedAt()); } } @@ -10676,7 +10215,6 @@ public final class SqlPrimary implements Model { .append(getContent()) .append(getCreatedAt()) .append(getUpdatedAt()) - .append(getSqlPrimaryRelatedId()) .toString() .hashCode(); } @@ -10688,8 +10226,7 @@ public final class SqlPrimary implements Model { .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") - .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt()) + \\", \\") - .append(\\"sqlPrimaryRelatedId=\\" + String.valueOf(getSqlPrimaryRelatedId())) + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) .append(\\"}\\") .toString(); } @@ -10709,36 +10246,31 @@ public final class SqlPrimary implements Model { public static SqlPrimary justId(String id) { return new SqlPrimary( id, - null, null ); } public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, - content, - sqlPrimaryRelatedId); + content); } public interface BuildStep { SqlPrimary build(); BuildStep id(String id); BuildStep content(String content); - BuildStep sqlPrimaryRelatedId(Integer sqlPrimaryRelatedId); } public static class Builder implements BuildStep { private Integer id; private String content; - private Integer sqlPrimaryRelatedId; public Builder() { } - private Builder(Integer id, String content, Integer sqlPrimaryRelatedId) { + private Builder(Integer id, String content) { this.id = id; this.content = content; - this.sqlPrimaryRelatedId = sqlPrimaryRelatedId; } @Override @@ -10747,8 +10279,7 @@ public final class SqlPrimary implements Model { return new SqlPrimary( id, - content, - sqlPrimaryRelatedId); + content); } @Override @@ -10757,12 +10288,6 @@ public final class SqlPrimary implements Model { return this; } - @Override - public BuildStep sqlPrimaryRelatedId(Integer sqlPrimaryRelatedId) { - this.sqlPrimaryRelatedId = sqlPrimaryRelatedId; - return this; - } - /** * @param id id * @return Current Builder instance, for fluent method chaining @@ -10775,8 +10300,8 @@ public final class SqlPrimary implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(Integer id, String content, Integer sqlPrimaryRelatedId) { - super(id, content, sqlPrimaryRelatedId); + private CopyOfBuilder(Integer id, String content) { + super(id, content); } @@ -10784,11 +10309,6 @@ public final class SqlPrimary implements Model { public CopyOfBuilder content(String content) { return (CopyOfBuilder) super.content(content); } - - @Override - public CopyOfBuilder sqlPrimaryRelatedId(Integer sqlPrimaryRelatedId) { - return (CopyOfBuilder) super.sqlPrimaryRelatedId(sqlPrimaryRelatedId); - } } @@ -10832,12 +10352,10 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field; public final class SqlRelated implements Model { public static final QueryField ID = field(\\"SqlRelated\\", \\"id\\"); public static final QueryField CONTENT = field(\\"SqlRelated\\", \\"content\\"); - public static final QueryField PRIMARY_ID = field(\\"SqlRelated\\", \\"primaryId\\"); - public static final QueryField PRIMARY = field(\\"SqlRelated\\", \\"sqlRelatedPrimaryId\\"); + public static final QueryField PRIMARY = field(\\"SqlRelated\\", \\"primaryId\\"); private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; private final @ModelField(targetType=\\"String\\") String content; - private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer primaryId; - private final @ModelField(targetType=\\"SqlPrimary\\") @BelongsTo(targetName = \\"sqlRelatedPrimaryId\\", targetNames = {\\"sqlRelatedPrimaryId\\"}, type = SqlPrimary.class) SqlPrimary primary; + private final @ModelField(targetType=\\"SqlPrimary\\") @BelongsTo(targetName = \\"primaryId\\", targetNames = {\\"primaryId\\"}, type = SqlPrimary.class) SqlPrimary primary; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; /** @deprecated This API is internal to Amplify and should not be used. */ @@ -10854,10 +10372,6 @@ public final class SqlRelated implements Model { return content; } - public Integer getPrimaryId() { - return primaryId; - } - public SqlPrimary getPrimary() { return primary; } @@ -10870,10 +10384,9 @@ public final class SqlRelated implements Model { return updatedAt; } - private SqlRelated(Integer id, String content, Integer primaryId, SqlPrimary primary) { + private SqlRelated(Integer id, String content, SqlPrimary primary) { this.id = id; this.content = content; - this.primaryId = primaryId; this.primary = primary; } @@ -10887,7 +10400,6 @@ public final class SqlRelated implements Model { SqlRelated sqlRelated = (SqlRelated) obj; return ObjectsCompat.equals(getId(), sqlRelated.getId()) && ObjectsCompat.equals(getContent(), sqlRelated.getContent()) && - ObjectsCompat.equals(getPrimaryId(), sqlRelated.getPrimaryId()) && ObjectsCompat.equals(getPrimary(), sqlRelated.getPrimary()) && ObjectsCompat.equals(getCreatedAt(), sqlRelated.getCreatedAt()) && ObjectsCompat.equals(getUpdatedAt(), sqlRelated.getUpdatedAt()); @@ -10899,7 +10411,6 @@ public final class SqlRelated implements Model { return new StringBuilder() .append(getId()) .append(getContent()) - .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -10913,7 +10424,6 @@ public final class SqlRelated implements Model { .append(\\"SqlRelated {\\") .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") - .append(\\"primaryId=\\" + String.valueOf(getPrimaryId()) + \\", \\") .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) @@ -10921,7 +10431,7 @@ public final class SqlRelated implements Model { .toString(); } - public static PrimaryIdStep builder() { + public static BuildStep builder() { return new Builder(); } @@ -10937,7 +10447,6 @@ public final class SqlRelated implements Model { return new SqlRelated( id, null, - null, null ); } @@ -10945,14 +10454,8 @@ public final class SqlRelated implements Model { public CopyOfBuilder copyOfBuilder() { return new CopyOfBuilder(id, content, - primaryId, primary); } - public interface PrimaryIdStep { - BuildStep primaryId(Integer primaryId); - } - - public interface BuildStep { SqlRelated build(); BuildStep id(String id); @@ -10961,19 +10464,17 @@ public final class SqlRelated implements Model { } - public static class Builder implements PrimaryIdStep, BuildStep { + public static class Builder implements BuildStep { private Integer id; - private Integer primaryId; private String content; private SqlPrimary primary; public Builder() { } - private Builder(Integer id, String content, Integer primaryId, SqlPrimary primary) { + private Builder(Integer id, String content, SqlPrimary primary) { this.id = id; this.content = content; - this.primaryId = primaryId; this.primary = primary; } @@ -10984,17 +10485,9 @@ public final class SqlRelated implements Model { return new SqlRelated( id, content, - primaryId, primary); } - @Override - public BuildStep primaryId(Integer primaryId) { - Objects.requireNonNull(primaryId); - this.primaryId = primaryId; - return this; - } - @Override public BuildStep content(String content) { this.content = content; @@ -11019,14 +10512,9 @@ public final class SqlRelated implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(Integer id, String content, Integer primaryId, SqlPrimary primary) { - super(id, content, primaryId, primary); - Objects.requireNonNull(primaryId); - } - - @Override - public CopyOfBuilder primaryId(Integer primaryId) { - return (CopyOfBuilder) super.primaryId(primaryId); + private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { + super(id, content, primary); + } @Override diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap index 6850c06e7..0dd1c07ed 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-swift-visitor.test.ts.snap @@ -1312,36 +1312,26 @@ public struct Foo: Model { } public var createdAt: Temporal.DateTime? public var updatedAt: Temporal.DateTime? - public var fooBar1Id: String? - public var fooBar2Id: String? public init(id: String = UUID().uuidString, bar1: Bar? = nil, - bar2: Bar? = nil, - fooBar1Id: String? = nil, - fooBar2Id: String? = nil) { + bar2: Bar? = nil) { self.init(id: id, bar1: bar1, bar2: bar2, createdAt: nil, - updatedAt: nil, - fooBar1Id: fooBar1Id, - fooBar2Id: fooBar2Id) + updatedAt: nil) } internal init(id: String = UUID().uuidString, bar1: Bar? = nil, bar2: Bar? = nil, createdAt: Temporal.DateTime? = nil, - updatedAt: Temporal.DateTime? = nil, - fooBar1Id: String? = nil, - fooBar2Id: String? = nil) { + updatedAt: Temporal.DateTime? = nil) { self.id = id self._bar1 = LazyReference(bar1) self._bar2 = LazyReference(bar2) self.createdAt = createdAt self.updatedAt = updatedAt - self.fooBar1Id = fooBar1Id - self.fooBar2Id = fooBar2Id } public mutating func setBar1(_ bar1: Bar? = nil) { self._bar1 = LazyReference(bar1) @@ -1356,8 +1346,6 @@ public struct Foo: Model { _bar2 = try values.decodeIfPresent(LazyReference.self, forKey: .bar2) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) - fooBar1Id = try? values.decode(String?.self, forKey: .fooBar1Id) - fooBar2Id = try? values.decode(String?.self, forKey: .fooBar2Id) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) @@ -1366,8 +1354,6 @@ public struct Foo: Model { try container.encode(_bar2, forKey: .bar2) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) - try container.encode(fooBar1Id, forKey: .fooBar1Id) - try container.encode(fooBar2Id, forKey: .fooBar2Id) } }" `; @@ -1385,8 +1371,6 @@ extension Foo { case bar2 case createdAt case updatedAt - case fooBar1Id - case fooBar2Id } public static let keys = CodingKeys.self @@ -1404,12 +1388,10 @@ extension Foo { model.fields( .field(foo.id, is: .required, ofType: .string), - .hasOne(foo.bar1, is: .optional, ofType: Bar.self, associatedWith: Bar.keys.foo1, targetNames: [\\"fooBar1Id\\"]), - .hasOne(foo.bar2, is: .optional, ofType: Bar.self, associatedWith: Bar.keys.foo1, targetNames: [\\"fooBar2Id\\"]), + .hasOne(foo.bar1, is: .optional, ofType: Bar.self, associatedFields: [Bar.keys.foo1]), + .hasOne(foo.bar2, is: .optional, ofType: Bar.self, associatedFields: [Bar.keys.foo2]), .field(foo.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(foo.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(foo.fooBar1Id, is: .optional, ofType: .string), - .field(foo.fooBar2Id, is: .optional, ofType: .string) + .field(foo.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) } public class Path: ModelPath { } @@ -1437,12 +1419,6 @@ extension ModelPath where ModelType == Foo { public var updatedAt: FieldPath { datetime(\\"updatedAt\\") } - public var fooBar1Id: FieldPath { - string(\\"fooBar1Id\\") - } - public var fooBar2Id: FieldPath { - string(\\"fooBar2Id\\") - } }" `; @@ -1453,8 +1429,6 @@ import Foundation public struct Bar: Model { public let id: String - public var bar1Id: String? - public var bar2Id: String? internal var _foo1: LazyReference public var foo1: Foo? { get async throws { @@ -1471,28 +1445,20 @@ public struct Bar: Model { public var updatedAt: Temporal.DateTime? public init(id: String = UUID().uuidString, - bar1Id: String? = nil, - bar2Id: String? = nil, foo1: Foo? = nil, foo2: Foo? = nil) { self.init(id: id, - bar1Id: bar1Id, - bar2Id: bar2Id, foo1: foo1, foo2: foo2, createdAt: nil, updatedAt: nil) } internal init(id: String = UUID().uuidString, - bar1Id: String? = nil, - bar2Id: String? = nil, foo1: Foo? = nil, foo2: Foo? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id - self.bar1Id = bar1Id - self.bar2Id = bar2Id self._foo1 = LazyReference(foo1) self._foo2 = LazyReference(foo2) self.createdAt = createdAt @@ -1507,8 +1473,6 @@ public struct Bar: Model { public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(String.self, forKey: .id) - bar1Id = try? values.decode(String?.self, forKey: .bar1Id) - bar2Id = try? values.decode(String?.self, forKey: .bar2Id) _foo1 = try values.decodeIfPresent(LazyReference.self, forKey: .foo1) ?? LazyReference(identifiers: nil) _foo2 = try values.decodeIfPresent(LazyReference.self, forKey: .foo2) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) @@ -1517,8 +1481,6 @@ public struct Bar: Model { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) - try container.encode(bar1Id, forKey: .bar1Id) - try container.encode(bar2Id, forKey: .bar2Id) try container.encode(_foo1, forKey: .foo1) try container.encode(_foo2, forKey: .foo2) try container.encode(createdAt, forKey: .createdAt) @@ -1536,8 +1498,6 @@ extension Bar { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id - case bar1Id - case bar2Id case foo1 case foo2 case createdAt @@ -1559,10 +1519,8 @@ extension Bar { model.fields( .field(bar.id, is: .required, ofType: .string), - .field(bar.bar1Id, is: .optional, ofType: .string), - .field(bar.bar2Id, is: .optional, ofType: .string), - .belongsTo(bar.foo1, is: .optional, ofType: Foo.self, targetNames: [\\"barFoo1Id\\"]), - .belongsTo(bar.foo2, is: .optional, ofType: Foo.self, targetNames: [\\"barFoo2Id\\"]), + .belongsTo(bar.foo1, is: .optional, ofType: Foo.self, targetNames: [\\"bar1Id\\"]), + .belongsTo(bar.foo2, is: .optional, ofType: Foo.self, targetNames: [\\"bar2Id\\"]), .field(bar.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(bar.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -1580,12 +1538,6 @@ extension ModelPath where ModelType == Bar { public var id: FieldPath { string(\\"id\\") } - public var bar1Id: FieldPath { - string(\\"bar1Id\\") - } - public var bar2Id: FieldPath { - string(\\"bar2Id\\") - } public var foo1: ModelPath { Foo.Path(name: \\"foo1\\", parent: self) } @@ -1682,7 +1634,7 @@ extension Primary { .field(primary.instanceId, is: .required, ofType: .string), .field(primary.recordId, is: .required, ofType: .string), .field(primary.content, is: .optional, ofType: .string), - .hasMany(primary.related, is: .optional, ofType: Related.self, associatedWith: Related.keys.primary), + .hasMany(primary.related, is: .optional, ofType: Related.self, associatedFields: [Related.keys.primary], .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -1737,9 +1689,6 @@ import Foundation public struct Related: Model { public let id: String public var content: String? - public var primaryTenantId: String - public var primaryInstanceId: String - public var primaryRecordId: String internal var _primary: LazyReference public var primary: Primary? { get async throws { @@ -1751,32 +1700,20 @@ public struct Related: Model { public init(id: String = UUID().uuidString, content: String? = nil, - primaryTenantId: String, - primaryInstanceId: String, - primaryRecordId: String, primary: Primary? = nil) { self.init(id: id, content: content, - primaryTenantId: primaryTenantId, - primaryInstanceId: primaryInstanceId, - primaryRecordId: primaryRecordId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: String = UUID().uuidString, content: String? = nil, - primaryTenantId: String, - primaryInstanceId: String, - primaryRecordId: String, primary: Primary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id self.content = content - self.primaryTenantId = primaryTenantId - self.primaryInstanceId = primaryInstanceId - self.primaryRecordId = primaryRecordId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -1788,9 +1725,6 @@ public struct Related: Model { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(String.self, forKey: .id) content = try? values.decode(String?.self, forKey: .content) - primaryTenantId = try values.decode(String.self, forKey: .primaryTenantId) - primaryInstanceId = try values.decode(String.self, forKey: .primaryInstanceId) - primaryRecordId = try values.decode(String.self, forKey: .primaryRecordId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -1799,9 +1733,6 @@ public struct Related: Model { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(content, forKey: .content) - try container.encode(primaryTenantId, forKey: .primaryTenantId) - try container.encode(primaryInstanceId, forKey: .primaryInstanceId) - try container.encode(primaryRecordId, forKey: .primaryRecordId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -1819,9 +1750,6 @@ extension Related { public enum CodingKeys: String, ModelKey { case id case content - case primaryTenantId - case primaryInstanceId - case primaryRecordId case primary case createdAt case updatedAt @@ -1843,10 +1771,7 @@ extension Related { model.fields( .field(related.id, is: .required, ofType: .string), .field(related.content, is: .optional, ofType: .string), - .field(related.primaryTenantId, is: .required, ofType: .string), - .field(related.primaryInstanceId, is: .required, ofType: .string), - .field(related.primaryRecordId, is: .required, ofType: .string), - .belongsTo(related.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryRelatedTenantId\\", \\"primaryRelatedInstanceId\\", \\"primaryRelatedRecordId\\"]), + .belongsTo(related.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"]), .field(related.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(related.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -1867,15 +1792,6 @@ extension ModelPath where ModelType == Related { public var content: FieldPath { string(\\"content\\") } - public var primaryTenantId: FieldPath { - string(\\"primaryTenantId\\") - } - public var primaryInstanceId: FieldPath { - string(\\"primaryInstanceId\\") - } - public var primaryRecordId: FieldPath { - string(\\"primaryRecordId\\") - } public var primary: ModelPath { Primary.Path(name: \\"primary\\", parent: self) } @@ -1906,22 +1822,19 @@ public struct Primary: Model { } public var createdAt: Temporal.DateTime? public var updatedAt: Temporal.DateTime? - public var primaryRelatedId: String? public init(tenantId: String, instanceId: String, recordId: String, content: String? = nil, - related: Related? = nil, - primaryRelatedId: String? = nil) { + related: Related? = nil) { self.init(tenantId: tenantId, instanceId: instanceId, recordId: recordId, content: content, related: related, createdAt: nil, - updatedAt: nil, - primaryRelatedId: primaryRelatedId) + updatedAt: nil) } internal init(tenantId: String, instanceId: String, @@ -1929,8 +1842,7 @@ public struct Primary: Model { content: String? = nil, related: Related? = nil, createdAt: Temporal.DateTime? = nil, - updatedAt: Temporal.DateTime? = nil, - primaryRelatedId: String? = nil) { + updatedAt: Temporal.DateTime? = nil) { self.tenantId = tenantId self.instanceId = instanceId self.recordId = recordId @@ -1938,7 +1850,6 @@ public struct Primary: Model { self._related = LazyReference(related) self.createdAt = createdAt self.updatedAt = updatedAt - self.primaryRelatedId = primaryRelatedId } public mutating func setRelated(_ related: Related? = nil) { self._related = LazyReference(related) @@ -1952,7 +1863,6 @@ public struct Primary: Model { _related = try values.decodeIfPresent(LazyReference.self, forKey: .related) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) - primaryRelatedId = try? values.decode(String?.self, forKey: .primaryRelatedId) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) @@ -1963,7 +1873,6 @@ public struct Primary: Model { try container.encode(_related, forKey: .related) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) - try container.encode(primaryRelatedId, forKey: .primaryRelatedId) } }" `; @@ -1983,7 +1892,6 @@ extension Primary { case related case createdAt case updatedAt - case primaryRelatedId } public static let keys = CodingKeys.self @@ -2005,10 +1913,9 @@ extension Primary { .field(primary.instanceId, is: .required, ofType: .string), .field(primary.recordId, is: .required, ofType: .string), .field(primary.content, is: .optional, ofType: .string), - .hasOne(primary.related, is: .optional, ofType: Related.self, associatedWith: Related.keys.primary, targetNames: [\\"primaryRelatedId\\"]), + .hasOne(primary.related, is: .optional, ofType: Related.self, associatedFields: [Related.keys.primary]), .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(primary.primaryRelatedId, is: .optional, ofType: .string) + .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) } public class Path: ModelPath { } @@ -2050,9 +1957,6 @@ extension ModelPath where ModelType == Primary { public var updatedAt: FieldPath { datetime(\\"updatedAt\\") } - public var primaryRelatedId: FieldPath { - string(\\"primaryRelatedId\\") - } }" `; @@ -2064,9 +1968,6 @@ import Foundation public struct Related: Model { public let id: String public var content: String? - public var primaryTenantId: String - public var primaryInstanceId: String - public var primaryRecordId: String internal var _primary: LazyReference public var primary: Primary? { get async throws { @@ -2078,32 +1979,20 @@ public struct Related: Model { public init(id: String = UUID().uuidString, content: String? = nil, - primaryTenantId: String, - primaryInstanceId: String, - primaryRecordId: String, primary: Primary? = nil) { self.init(id: id, content: content, - primaryTenantId: primaryTenantId, - primaryInstanceId: primaryInstanceId, - primaryRecordId: primaryRecordId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: String = UUID().uuidString, content: String? = nil, - primaryTenantId: String, - primaryInstanceId: String, - primaryRecordId: String, primary: Primary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id self.content = content - self.primaryTenantId = primaryTenantId - self.primaryInstanceId = primaryInstanceId - self.primaryRecordId = primaryRecordId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -2115,9 +2004,6 @@ public struct Related: Model { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(String.self, forKey: .id) content = try? values.decode(String?.self, forKey: .content) - primaryTenantId = try values.decode(String.self, forKey: .primaryTenantId) - primaryInstanceId = try values.decode(String.self, forKey: .primaryInstanceId) - primaryRecordId = try values.decode(String.self, forKey: .primaryRecordId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -2126,9 +2012,6 @@ public struct Related: Model { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(content, forKey: .content) - try container.encode(primaryTenantId, forKey: .primaryTenantId) - try container.encode(primaryInstanceId, forKey: .primaryInstanceId) - try container.encode(primaryRecordId, forKey: .primaryRecordId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -2146,9 +2029,6 @@ extension Related { public enum CodingKeys: String, ModelKey { case id case content - case primaryTenantId - case primaryInstanceId - case primaryRecordId case primary case createdAt case updatedAt @@ -2170,10 +2050,7 @@ extension Related { model.fields( .field(related.id, is: .required, ofType: .string), .field(related.content, is: .optional, ofType: .string), - .field(related.primaryTenantId, is: .required, ofType: .string), - .field(related.primaryInstanceId, is: .required, ofType: .string), - .field(related.primaryRecordId, is: .required, ofType: .string), - .belongsTo(related.primary, is: .optional, ofType: Primary.self, targetNames: [\\"relatedPrimaryTenantId\\", \\"relatedPrimaryInstanceId\\", \\"relatedPrimaryRecordId\\"]), + .belongsTo(related.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"]), .field(related.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(related.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -2194,15 +2071,6 @@ extension ModelPath where ModelType == Related { public var content: FieldPath { string(\\"content\\") } - public var primaryTenantId: FieldPath { - string(\\"primaryTenantId\\") - } - public var primaryInstanceId: FieldPath { - string(\\"primaryInstanceId\\") - } - public var primaryRecordId: FieldPath { - string(\\"primaryRecordId\\") - } public var primary: ModelPath { Primary.Path(name: \\"primary\\", parent: self) } @@ -2282,7 +2150,7 @@ extension SqlPrimary { model.fields( .field(sqlPrimary.id, is: .required, ofType: .int), .field(sqlPrimary.content, is: .optional, ofType: .string), - .hasMany(sqlPrimary.related, is: .optional, ofType: SqlRelated.self, associatedWith: SqlRelated.keys.primary), + .hasMany(sqlPrimary.related, is: .optional, ofType: SqlRelated.self, associatedFields: [SqlRelated.keys.primary], .field(sqlPrimary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(sqlPrimary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -2323,7 +2191,6 @@ import Foundation public struct SqlRelated: Model { public let id: Int public var content: String? - public var primaryId: Int internal var _primary: LazyReference public var primary: SqlPrimary? { get async throws { @@ -2335,24 +2202,20 @@ public struct SqlRelated: Model { public init(id: Int = UUID().uuidString, content: String? = nil, - primaryId: Int, primary: SqlPrimary? = nil) { self.init(id: id, content: content, - primaryId: primaryId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: Int = UUID().uuidString, content: String? = nil, - primaryId: Int, primary: SqlPrimary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id self.content = content - self.primaryId = primaryId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -2364,7 +2227,6 @@ public struct SqlRelated: Model { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(Int.self, forKey: .id) content = try? values.decode(String?.self, forKey: .content) - primaryId = try values.decode(Int.self, forKey: .primaryId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -2373,7 +2235,6 @@ public struct SqlRelated: Model { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(content, forKey: .content) - try container.encode(primaryId, forKey: .primaryId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -2391,7 +2252,6 @@ extension SqlRelated { public enum CodingKeys: String, ModelKey { case id case content - case primaryId case primary case createdAt case updatedAt @@ -2415,8 +2275,7 @@ extension SqlRelated { model.fields( .field(sqlRelated.id, is: .required, ofType: .int), .field(sqlRelated.content, is: .optional, ofType: .string), - .field(sqlRelated.primaryId, is: .required, ofType: .int), - .belongsTo(sqlRelated.primary, is: .optional, ofType: SqlPrimary.self, targetNames: [\\"sqlPrimaryRelatedId\\"]), + .belongsTo(sqlRelated.primary, is: .optional, ofType: SqlPrimary.self, targetNames: [\\"primaryId\\"]), .field(sqlRelated.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(sqlRelated.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -2437,9 +2296,6 @@ extension ModelPath where ModelType == SqlRelated { public var content: FieldPath { string(\\"content\\") } - public var primaryId: FieldPath { - int(\\"primaryId\\") - } public var primary: ModelPath { SqlPrimary.Path(name: \\"primary\\", parent: self) } @@ -2468,31 +2324,26 @@ public struct Primary: Model { } public var createdAt: Temporal.DateTime? public var updatedAt: Temporal.DateTime? - public var primaryRelatedOneId: String? public init(id: String = UUID().uuidString, relatedMany: List? = [], - relatedOne: RelatedOne? = nil, - primaryRelatedOneId: String? = nil) { + relatedOne: RelatedOne? = nil) { self.init(id: id, relatedMany: relatedMany, relatedOne: relatedOne, createdAt: nil, - updatedAt: nil, - primaryRelatedOneId: primaryRelatedOneId) + updatedAt: nil) } internal init(id: String = UUID().uuidString, relatedMany: List? = [], relatedOne: RelatedOne? = nil, createdAt: Temporal.DateTime? = nil, - updatedAt: Temporal.DateTime? = nil, - primaryRelatedOneId: String? = nil) { + updatedAt: Temporal.DateTime? = nil) { self.id = id self.relatedMany = relatedMany self._relatedOne = LazyReference(relatedOne) self.createdAt = createdAt self.updatedAt = updatedAt - self.primaryRelatedOneId = primaryRelatedOneId } public mutating func setRelatedOne(_ relatedOne: RelatedOne? = nil) { self._relatedOne = LazyReference(relatedOne) @@ -2504,7 +2355,6 @@ public struct Primary: Model { _relatedOne = try values.decodeIfPresent(LazyReference.self, forKey: .relatedOne) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) - primaryRelatedOneId = try? values.decode(String?.self, forKey: .primaryRelatedOneId) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) @@ -2513,7 +2363,6 @@ public struct Primary: Model { try container.encode(_relatedOne, forKey: .relatedOne) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) - try container.encode(primaryRelatedOneId, forKey: .primaryRelatedOneId) } }" `; @@ -2531,7 +2380,6 @@ extension Primary { case relatedOne case createdAt case updatedAt - case primaryRelatedOneId } public static let keys = CodingKeys.self @@ -2550,11 +2398,10 @@ extension Primary { model.fields( .field(primary.id, is: .required, ofType: .string), - .hasMany(primary.relatedMany, is: .optional, ofType: RelatedMany.self, associatedWith: RelatedMany.keys.primary), - .hasOne(primary.relatedOne, is: .optional, ofType: RelatedOne.self, associatedWith: RelatedOne.keys.primary, targetNames: [\\"primaryRelatedOneId\\"]), + .hasMany(primary.relatedMany, is: .optional, ofType: RelatedMany.self, associatedFields: [RelatedMany.keys.primary], + .hasOne(primary.relatedOne, is: .optional, ofType: RelatedOne.self, associatedFields: [RelatedOne.keys.primary]), .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(primary.primaryRelatedOneId, is: .optional, ofType: .string) + .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) } public class Path: ModelPath { } @@ -2582,9 +2429,6 @@ extension ModelPath where ModelType == Primary { public var updatedAt: FieldPath { datetime(\\"updatedAt\\") } - public var primaryRelatedOneId: FieldPath { - string(\\"primaryRelatedOneId\\") - } }" `; @@ -2595,7 +2439,6 @@ import Foundation public struct RelatedMany: Model { public let id: String - public var primaryId: String internal var _primary: LazyReference public var primary: Primary? { get async throws { @@ -2606,21 +2449,17 @@ public struct RelatedMany: Model { public var updatedAt: Temporal.DateTime? public init(id: String = UUID().uuidString, - primaryId: String, primary: Primary? = nil) { self.init(id: id, - primaryId: primaryId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: String = UUID().uuidString, - primaryId: String, primary: Primary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id - self.primaryId = primaryId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -2631,7 +2470,6 @@ public struct RelatedMany: Model { public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(String.self, forKey: .id) - primaryId = try values.decode(String.self, forKey: .primaryId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -2639,7 +2477,6 @@ public struct RelatedMany: Model { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) - try container.encode(primaryId, forKey: .primaryId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -2656,7 +2493,6 @@ extension RelatedMany { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id - case primaryId case primary case createdAt case updatedAt @@ -2678,8 +2514,7 @@ extension RelatedMany { model.fields( .field(relatedMany.id, is: .required, ofType: .string), - .field(relatedMany.primaryId, is: .required, ofType: .string), - .belongsTo(relatedMany.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryRelatedManyId\\"]), + .belongsTo(relatedMany.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryId\\"]), .field(relatedMany.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(relatedMany.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -2697,9 +2532,6 @@ extension ModelPath where ModelType == RelatedMany { public var id: FieldPath { string(\\"id\\") } - public var primaryId: FieldPath { - string(\\"primaryId\\") - } public var primary: ModelPath { Primary.Path(name: \\"primary\\", parent: self) } @@ -2719,7 +2551,6 @@ import Foundation public struct RelatedOne: Model { public let id: String - public var primaryId: String internal var _primary: LazyReference public var primary: Primary? { get async throws { @@ -2730,21 +2561,17 @@ public struct RelatedOne: Model { public var updatedAt: Temporal.DateTime? public init(id: String = UUID().uuidString, - primaryId: String, primary: Primary? = nil) { self.init(id: id, - primaryId: primaryId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: String = UUID().uuidString, - primaryId: String, primary: Primary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id - self.primaryId = primaryId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -2755,7 +2582,6 @@ public struct RelatedOne: Model { public init(from decoder: Decoder) throws { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(String.self, forKey: .id) - primaryId = try values.decode(String.self, forKey: .primaryId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -2763,7 +2589,6 @@ public struct RelatedOne: Model { public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) - try container.encode(primaryId, forKey: .primaryId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -2780,7 +2605,6 @@ extension RelatedOne { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id - case primaryId case primary case createdAt case updatedAt @@ -2802,8 +2626,7 @@ extension RelatedOne { model.fields( .field(relatedOne.id, is: .required, ofType: .string), - .field(relatedOne.primaryId, is: .required, ofType: .string), - .belongsTo(relatedOne.primary, is: .optional, ofType: Primary.self, targetNames: [\\"relatedOnePrimaryId\\"]), + .belongsTo(relatedOne.primary, is: .optional, ofType: Primary.self, targetNames: [\\"primaryId\\"]), .field(relatedOne.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(relatedOne.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -2821,9 +2644,6 @@ extension ModelPath where ModelType == RelatedOne { public var id: FieldPath { string(\\"id\\") } - public var primaryId: FieldPath { - string(\\"primaryId\\") - } public var primary: ModelPath { Primary.Path(name: \\"primary\\", parent: self) } @@ -2852,31 +2672,26 @@ public struct SqlPrimary: Model { } public var createdAt: Temporal.DateTime? public var updatedAt: Temporal.DateTime? - public var sqlPrimaryRelatedId: Int? public init(id: Int = UUID().uuidString, content: String? = nil, - related: SqlRelated? = nil, - sqlPrimaryRelatedId: Int? = nil) { + related: SqlRelated? = nil) { self.init(id: id, content: content, related: related, createdAt: nil, - updatedAt: nil, - sqlPrimaryRelatedId: sqlPrimaryRelatedId) + updatedAt: nil) } internal init(id: Int = UUID().uuidString, content: String? = nil, related: SqlRelated? = nil, createdAt: Temporal.DateTime? = nil, - updatedAt: Temporal.DateTime? = nil, - sqlPrimaryRelatedId: Int? = nil) { + updatedAt: Temporal.DateTime? = nil) { self.id = id self.content = content self._related = LazyReference(related) self.createdAt = createdAt self.updatedAt = updatedAt - self.sqlPrimaryRelatedId = sqlPrimaryRelatedId } public mutating func setRelated(_ related: SqlRelated? = nil) { self._related = LazyReference(related) @@ -2888,7 +2703,6 @@ public struct SqlPrimary: Model { _related = try values.decodeIfPresent(LazyReference.self, forKey: .related) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) - sqlPrimaryRelatedId = try? values.decode(Int?.self, forKey: .sqlPrimaryRelatedId) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) @@ -2897,7 +2711,6 @@ public struct SqlPrimary: Model { try container.encode(_related, forKey: .related) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) - try container.encode(sqlPrimaryRelatedId, forKey: .sqlPrimaryRelatedId) } }" `; @@ -2915,7 +2728,6 @@ extension SqlPrimary { case related case createdAt case updatedAt - case sqlPrimaryRelatedId } public static let keys = CodingKeys.self @@ -2935,10 +2747,9 @@ extension SqlPrimary { model.fields( .field(sqlPrimary.id, is: .required, ofType: .int), .field(sqlPrimary.content, is: .optional, ofType: .string), - .hasOne(sqlPrimary.related, is: .optional, ofType: SqlRelated.self, associatedWith: SqlRelated.keys.primary, targetNames: [\\"sqlPrimaryRelatedId\\"]), + .hasOne(sqlPrimary.related, is: .optional, ofType: SqlRelated.self, associatedFields: [SqlRelated.keys.primary]), .field(sqlPrimary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(sqlPrimary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime), - .field(sqlPrimary.sqlPrimaryRelatedId, is: .optional, ofType: .int) + .field(sqlPrimary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) } public class Path: ModelPath { } @@ -2966,9 +2777,6 @@ extension ModelPath where ModelType == SqlPrimary { public var updatedAt: FieldPath { datetime(\\"updatedAt\\") } - public var sqlPrimaryRelatedId: FieldPath { - int(\\"sqlPrimaryRelatedId\\") - } }" `; @@ -2980,7 +2788,6 @@ import Foundation public struct SqlRelated: Model { public let id: Int public var content: String? - public var primaryId: Int internal var _primary: LazyReference public var primary: SqlPrimary? { get async throws { @@ -2992,24 +2799,20 @@ public struct SqlRelated: Model { public init(id: Int = UUID().uuidString, content: String? = nil, - primaryId: Int, primary: SqlPrimary? = nil) { self.init(id: id, content: content, - primaryId: primaryId, primary: primary, createdAt: nil, updatedAt: nil) } internal init(id: Int = UUID().uuidString, content: String? = nil, - primaryId: Int, primary: SqlPrimary? = nil, createdAt: Temporal.DateTime? = nil, updatedAt: Temporal.DateTime? = nil) { self.id = id self.content = content - self.primaryId = primaryId self._primary = LazyReference(primary) self.createdAt = createdAt self.updatedAt = updatedAt @@ -3021,7 +2824,6 @@ public struct SqlRelated: Model { let values = try decoder.container(keyedBy: CodingKeys.self) id = try values.decode(Int.self, forKey: .id) content = try? values.decode(String?.self, forKey: .content) - primaryId = try values.decode(Int.self, forKey: .primaryId) _primary = try values.decodeIfPresent(LazyReference.self, forKey: .primary) ?? LazyReference(identifiers: nil) createdAt = try? values.decode(Temporal.DateTime?.self, forKey: .createdAt) updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) @@ -3030,7 +2832,6 @@ public struct SqlRelated: Model { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(id, forKey: .id) try container.encode(content, forKey: .content) - try container.encode(primaryId, forKey: .primaryId) try container.encode(_primary, forKey: .primary) try container.encode(createdAt, forKey: .createdAt) try container.encode(updatedAt, forKey: .updatedAt) @@ -3048,7 +2849,6 @@ extension SqlRelated { public enum CodingKeys: String, ModelKey { case id case content - case primaryId case primary case createdAt case updatedAt @@ -3072,8 +2872,7 @@ extension SqlRelated { model.fields( .field(sqlRelated.id, is: .required, ofType: .int), .field(sqlRelated.content, is: .optional, ofType: .string), - .field(sqlRelated.primaryId, is: .required, ofType: .int), - .belongsTo(sqlRelated.primary, is: .optional, ofType: SqlPrimary.self, targetNames: [\\"sqlRelatedPrimaryId\\"]), + .belongsTo(sqlRelated.primary, is: .optional, ofType: SqlPrimary.self, targetNames: [\\"primaryId\\"]), .field(sqlRelated.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(sqlRelated.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) ) @@ -3094,9 +2893,6 @@ extension ModelPath where ModelType == SqlRelated { public var content: FieldPath { string(\\"content\\") } - public var primaryId: FieldPath { - int(\\"primaryId\\") - } public var primary: ModelPath { SqlPrimary.Path(name: \\"primary\\", parent: self) } diff --git a/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts b/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts index 7a1377399..76cf7623a 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts @@ -15,7 +15,6 @@ export function processBelongsToConnection( modelMap: CodeGenModelMap, connectionDirective: CodeGenDirective, isCustomPKEnabled: boolean = false, - respectReferences: boolean = false, // remove when enabled references for all targets ): CodeGenFieldConnection | undefined { if (field.isList) { throw new Error( @@ -29,7 +28,7 @@ export function processBelongsToConnection( `A 'belongsTo' field should match to a corresponding 'hasMany' or 'hasOne' field` ); } - const otherSideField = isCustomPKEnabled ? otherSideConnectedFields[0] : getConnectedFieldV2(field, model, otherSide, connectionDirective.name, false, respectReferences); + const otherSideField = isCustomPKEnabled ? otherSideConnectedFields[0] : getConnectedFieldV2(field, model, otherSide, connectionDirective.name); const connectionFields = connectionDirective.arguments.fields || []; const references = connectionDirective.arguments.references || []; @@ -42,9 +41,9 @@ export function processBelongsToConnection( // but if the field are connected using fields argument in connection directive // we are reusing the field and it should be preserved in selection set const otherSideHasMany = otherSideField.isList; - const isUsingReferences = respectReferences && references.length > 0; + const isUsingReferences = references.length > 0; // New metada type introduced by custom PK v2 support - let targetNames = isUsingReferences ? [ ...connectionFields, ...references ] : [ ...connectionFields ]; + let targetNames: string[] = [ ...connectionFields, ...references ]; if (targetNames.length === 0) { if (otherSideHasMany) { targetNames = isCustomPKEnabled diff --git a/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts b/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts index 054955af2..851f541e3 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts @@ -13,8 +13,7 @@ export function getConnectedFieldV2( model: CodeGenModel, connectedModel: CodeGenModel, directiveName: string, - shouldUseModelNameFieldInHasManyAndBelongsTo: boolean = false, - respectReferences: boolean = false, + shouldUseModelNameFieldInHasManyAndBelongsTo: boolean = false ): CodeGenField { const connectionInfo = getDirective(field)(directiveName); if (!connectionInfo) { @@ -24,7 +23,7 @@ export function getConnectedFieldV2( const references = connectionInfo.arguments.references; if (connectionInfo.name === 'belongsTo') { let connectedFieldsBelongsTo = getBelongsToConnectedFields(model, connectedModel); - if (respectReferences && references) { + if (references) { const connectedField = connectedFieldsBelongsTo.find((field) => { return field.directives.some((dir) => { return (dir.name === 'hasOne' || dir.name === 'hasMany') @@ -50,7 +49,7 @@ export function getConnectedFieldV2( } if (references || connectionFields || directiveName === 'hasOne') { let connectionDirective; - if (respectReferences && references) { + if (references) { if (connectionInfo) { connectionDirective = flattenFieldDirectives(connectedModel).find((dir) => { return dir.arguments.references @@ -162,18 +161,17 @@ export function processConnectionsV2( shouldUseModelNameFieldInHasManyAndBelongsTo: boolean = false, isCustomPKEnabled: boolean = false, shouldUseFieldsInAssociatedWithInHasOne: boolean = false, - respectReferences: boolean = false, // remove when enabled references for all targets ): CodeGenFieldConnection | undefined { const connectionDirective = field.directives.find(d => d.name === 'hasOne' || d.name === 'hasMany' || d.name === 'belongsTo'); if (connectionDirective) { switch (connectionDirective.name) { case 'hasOne': - return processHasOneConnection(field, model, modelMap, connectionDirective, isCustomPKEnabled, shouldUseFieldsInAssociatedWithInHasOne, respectReferences); + return processHasOneConnection(field, model, modelMap, connectionDirective, isCustomPKEnabled, shouldUseFieldsInAssociatedWithInHasOne); case 'belongsTo': - return processBelongsToConnection(field, model, modelMap, connectionDirective, isCustomPKEnabled, respectReferences); + return processBelongsToConnection(field, model, modelMap, connectionDirective, isCustomPKEnabled); case 'hasMany': - return processHasManyConnection(field, model, modelMap, connectionDirective, shouldUseModelNameFieldInHasManyAndBelongsTo, isCustomPKEnabled, respectReferences); + return processHasManyConnection(field, model, modelMap, connectionDirective, shouldUseModelNameFieldInHasManyAndBelongsTo, isCustomPKEnabled); default: break; } diff --git a/packages/appsync-modelgen-plugin/src/utils/process-connections.ts b/packages/appsync-modelgen-plugin/src/utils/process-connections.ts index 2ad12d3db..e2f33113e 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-connections.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-connections.ts @@ -22,6 +22,7 @@ export type CodeGenFieldConnectionBelongsTo = CodeGenConnectionTypeBase & { export type CodeGenFieldConnectionHasOne = CodeGenConnectionTypeBase & { kind: CodeGenConnectionType.HAS_ONE; associatedWith: CodeGenField;// Legacy field remained for backward compatability + associatedWithNativeReferences?: CodeGenField; // native uses the connected field instead of associatedWithFields associatedWithFields: CodeGenField[]; // New attribute for v2 custom pk support targetName?: string; // Legacy field remained for backward compatability targetNames?: string[]; // New attribute for v2 custom pk support @@ -30,6 +31,7 @@ export type CodeGenFieldConnectionHasOne = CodeGenConnectionTypeBase & { export type CodeGenFieldConnectionHasMany = CodeGenConnectionTypeBase & { kind: CodeGenConnectionType.HAS_MANY; associatedWith: CodeGenField;// Legacy field remained for backward compatability + associatedWithNativeReferences?: CodeGenField; // native uses the connected field instead of associatedWithFields associatedWithFields: CodeGenField[]; // New attribute for v2 custom pk support }; diff --git a/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts b/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts index 3f0f41bb6..baebe65ba 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts @@ -19,7 +19,6 @@ export function processHasManyConnection( connectionDirective: CodeGenDirective, shouldUseModelNameFieldInHasManyAndBelongsTo: boolean, isCustomPKEnabled: boolean = false, - respectReferences: boolean = false, // remove when enabled references for all targets ): CodeGenFieldConnection | undefined { if (!field.isList) { throw new Error("A field with hasMany must be a list type"); @@ -32,14 +31,17 @@ export function processHasManyConnection( throw new Error(fieldsAndReferencesErrorMessage); } - if (respectReferences && references.length > 0) { - // ensure there is a matching belongsTo field with references - getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo, respectReferences) + if (references.length > 0) { + // native uses the connected field instead of associatedWithFields + // when using references associatedWithFields and associatedWithNative are not the same + // getConnectedFieldV2 also ensures there is a matching belongsTo field with references + const associatedWithNativeReferences = getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo) const associatedWithFields = references.map((reference: string) => otherSide.fields.find((field) => reference === field.name)) return { kind: CodeGenConnectionType.HAS_MANY, associatedWith: associatedWithFields[0], associatedWithFields, + associatedWithNativeReferences, isConnectingFieldAutoCreated: false, connectedModel: otherSide, }; @@ -47,7 +49,7 @@ export function processHasManyConnection( const otherSideFields = isCustomPKEnabled ? getConnectedFieldsForHasMany(field, model, otherSide, shouldUseModelNameFieldInHasManyAndBelongsTo) - : [getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo, respectReferences)]; + : [getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo)]; const otherSideField = otherSideFields[0]; // if a type is connected using name, then graphql-connection-transformer adds a field to diff --git a/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts b/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts index 8de63914c..45d0fb781 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts @@ -14,8 +14,7 @@ export function processHasOneConnection( modelMap: CodeGenModelMap, connectionDirective: CodeGenDirective, isCustomPKEnabled: boolean = false, - shouldUseFieldsInAssociatedWithInHasOne:boolean = false, - respectReferences: boolean = false, // remove when enabled references for all targets + shouldUseFieldsInAssociatedWithInHasOne:boolean = false ): CodeGenFieldConnection | undefined { const otherSide = modelMap[field.type]; // Find other side belongsTo field when in bi direction connection @@ -32,21 +31,24 @@ export function processHasOneConnection( } let associatedWithFields; - if (respectReferences && references.length > 0) { - // ensure there is a matching belongsTo field with references - getConnectedFieldV2(field, model, otherSide, connectionDirective.name, false, respectReferences); + if (references.length > 0) { + // native uses the connected field instead of associatedWithFields + // when using references associatedWithFields and associatedWithNative are not the same + // getConnectedFieldV2 also ensures there is a matching belongsTo field with references + const associatedWithNativeReferences = getConnectedFieldV2(field, model, otherSide, connectionDirective.name); associatedWithFields = references.map((reference: string) => otherSide.fields.find((field) => reference === field.name)) return { kind: CodeGenConnectionType.HAS_ONE, associatedWith: associatedWithFields[0], associatedWithFields, + associatedWithNativeReferences, connectedModel: otherSide, isConnectingFieldAutoCreated: false, }; } else if (isCustomPKEnabled) { associatedWithFields = getConnectedFieldsForHasOne(otherSideBelongsToField, otherSide, shouldUseFieldsInAssociatedWithInHasOne); } else { - const otherSideField = getConnectedFieldV2(field, model, otherSide, connectionDirective.name, false, respectReferences); + const otherSideField = getConnectedFieldV2(field, model, otherSide, connectionDirective.name); associatedWithFields = [otherSideField]; } diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-dart-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-dart-visitor.ts index 5726471bc..8bb3da5a7 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-dart-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-dart-visitor.ts @@ -1006,24 +1006,34 @@ export class AppSyncModelDartVisitor< else if (field.connectionInfo) { const connectedModelName = this.getNativeType({ ...field, isList: false }); switch (field.connectionInfo.kind) { - case CodeGenConnectionType.HAS_ONE: + case CodeGenConnectionType.HAS_ONE: { + let associatedString = `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWith)}`; + if (field.connectionInfo.associatedWithNativeReferences) { + associatedString = `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWithNativeReferences)}`; + } fieldParam = [ `key: ${modelName}.${queryFieldName}`, `isRequired: ${!field.isNullable}`, `ofModelName: '${connectedModelName}'`, - `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWith)}`, + associatedString, ].join(',\n'); fieldsToAdd.push([`${DART_AMPLIFY_CORE_TYPES.ModelFieldDefinition}.hasOne(`, indentMultiline(fieldParam), ')'].join('\n')); break; - case CodeGenConnectionType.HAS_MANY: + } + case CodeGenConnectionType.HAS_MANY: { + let associatedString = `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWith)}`; + if (field.connectionInfo.associatedWithNativeReferences) { + associatedString = `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWithNativeReferences)}`; + } fieldParam = [ `key: ${modelName}.${queryFieldName}`, `isRequired: ${!field.isNullable}`, `ofModelName: '${connectedModelName}'`, - `associatedKey: ${connectedModelName}.${this.getQueryFieldName(field.connectionInfo.associatedWith)}`, + associatedString, ].join(',\n'); fieldsToAdd.push([`${DART_AMPLIFY_CORE_TYPES.ModelFieldDefinition}.hasMany(`, indentMultiline(fieldParam), ')'].join('\n')); break; + } case CodeGenConnectionType.BELONGS_TO: fieldParam = [ `key: ${modelName}.${queryFieldName}`, diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts index d4699b6fd..d25c9cd3d 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-java-visitor.ts @@ -1110,7 +1110,11 @@ export class AppSyncModelJavaVisitor< switch (connectionInfo.kind) { case CodeGenConnectionType.HAS_ONE: connectionDirectiveName = 'HasOne'; - connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + if (connectionInfo.associatedWithNativeReferences) { + connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWithNativeReferences)}"`); + } else { + connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + } if (this.isCustomPKEnabled() && this.isGenerateModelsForLazyLoadAndCustomSelectionSet() && connectionInfo.targetNames) { const hasOneTargetNamesArgs = `targetNames = {${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}}`; connectionArguments.push(hasOneTargetNamesArgs); @@ -1118,7 +1122,11 @@ export class AppSyncModelJavaVisitor< break; case CodeGenConnectionType.HAS_MANY: connectionDirectiveName = 'HasMany'; - connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + if (connectionInfo.associatedWithNativeReferences) { + connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWithNativeReferences)}"`); + } else { + connectionArguments.push(`associatedWith = "${this.getFieldName(connectionInfo.associatedWith)}"`); + } break; case CodeGenConnectionType.BELONGS_TO: connectionDirectiveName = 'BelongsTo'; diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts index 2e61897a6..4ea2085fb 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-swift-visitor.ts @@ -620,17 +620,29 @@ export class AppSyncSwiftVisitor< // connected field if (connectionInfo) { if (connectionInfo.kind === CodeGenConnectionType.HAS_MANY) { - return `.hasMany(${name}, is: ${isRequired}, ofType: ${typeName}, associatedWith: ${this.getModelName( + let association = `associatedWith: ${this.getModelName( connectionInfo.connectedModel, )}.keys.${this.getFieldName(connectionInfo.associatedWith)})`; + if (connectionInfo.associatedWithNativeReferences) { + association = `associatedFields: [${this.getCodingKey(connectionInfo.connectedModel, connectionInfo.associatedWithNativeReferences)}]` + } + return `.hasMany(${name}, is: ${isRequired}, ofType: ${typeName}, ${association}`; } - if (connectionInfo.kind === CodeGenConnectionType.HAS_ONE && (connectionInfo.targetNames || connectionInfo.targetName)) { - const targetNameAttrStr = this.isCustomPKEnabled() && connectionInfo.targetNames - ? `targetNames: [${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}]` - : `targetName: "${connectionInfo.targetName}"`; - return `.hasOne(${name}, is: ${isRequired}, ofType: ${typeName}, associatedWith: ${this.getModelName( + if (connectionInfo.kind === CodeGenConnectionType.HAS_ONE) { + let association = `associatedWith: ${this.getModelName( connectionInfo.connectedModel, - )}.keys.${this.getFieldName(connectionInfo.associatedWith)}, ${targetNameAttrStr})`; + )}.keys.${this.getFieldName(connectionInfo.associatedWith)}`; + if (connectionInfo.associatedWithNativeReferences) { + association = `associatedFields: [${this.getCodingKey(connectionInfo.connectedModel, connectionInfo.associatedWithNativeReferences)}]` + } + + let targetNameAttrStr = ''; + if (connectionInfo.targetNames || connectionInfo.targetName) { + targetNameAttrStr = this.isCustomPKEnabled() && connectionInfo.targetNames + ? `, targetNames: [${connectionInfo.targetNames.map(target => `"${target}"`).join(', ')}]` + : `, targetName: "${connectionInfo.targetName}"`; + } + return `.hasOne(${name}, is: ${isRequired}, ofType: ${typeName}, ${association}${targetNameAttrStr})`; } if (connectionInfo.kind === CodeGenConnectionType.BELONGS_TO) { const targetNameAttrStr = this.isCustomPKEnabled() @@ -815,4 +827,8 @@ export class AppSyncSwiftVisitor< protected hasReadOnlyFields(model: CodeGenModel): boolean { return model.fields.filter(f => f.isReadOnly).length !== 0; } + + private getCodingKey(model: CodeGenModel, field: CodeGenField): string { + return `${this.getModelName(model)}.keys.${this.getFieldName(field)}`; + } } diff --git a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index e8a611384..cb2cea965 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -1087,8 +1087,7 @@ export class AppSyncModelVisitor< this.modelMap, shouldUseModelNameFieldInHasManyAndBelongsTo, isCustomPKEnabled, - shouldUseFieldsInAssociatedWithInHasOne, - this.config.target === 'introspection', + shouldUseFieldsInAssociatedWithInHasOne ); if (connectionInfo) { if (connectionInfo.kind === CodeGenConnectionType.HAS_MANY) { From a909ff333af7513c6babfa8cf5f6cfce57e854e5 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Fri, 26 Apr 2024 08:22:29 -0600 Subject: [PATCH 2/2] fix: validate references on belongsTo when cpk is disabled (#822) --- ...ppsync-model-introspection-visitor.test.ts | 48 ++++++++--- .../src/utils/process-belongs-to.ts | 15 ++-- .../src/utils/process-connections-v2.ts | 86 +++++++++++-------- .../src/utils/process-has-many.ts | 10 +-- .../src/utils/process-has-one.ts | 10 +-- 5 files changed, 101 insertions(+), 68 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts index 179f33afb..49be70b1f 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-model-introspection-visitor.test.ts @@ -523,7 +523,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -543,7 +543,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -567,7 +567,7 @@ describe('custom references', () => { primary: Primary @belongsTo(references: ["primaryId"]) } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -588,7 +588,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -611,7 +611,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -633,7 +633,7 @@ describe('custom references', () => { primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(visitor.generate()).toMatchSnapshot(); }); @@ -653,7 +653,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`'fields' and 'references' cannot be used together.`); }); @@ -674,7 +674,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`'fields' and 'references' cannot be used together.`); }); @@ -695,7 +695,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`'fields' and 'references' cannot be used together.`); }); @@ -716,7 +716,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`Error processing @hasOne directive on SqlPrimary.related. @belongsTo directive with references ["primaryId"] was not found in connected model SqlRelated`); }); @@ -737,11 +737,33 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`Error processing @belongsTo directive on SqlRelated.primary. @hasOne or @hasMany directive with references ["primaryId"] was not found in connected model SqlPrimary`); }); + test('throws error when missing references on hasMany related model when custom pk is disabled', () => { + const schema = /* GraphQL */ ` + type SqlPrimary @refersTo(name: "sql_primary") @model { + id: Int! @primaryKey + content: String + related: [SqlRelated] @hasMany(references: ["primaryId"]) + } + + type SqlRelated @refersTo(name: "sql_related") @model { + id: Int! @primaryKey + content: String + primaryId: Int! @refersTo(name: "primary_id") @index(name: "primary_id") + primary: SqlPrimary @belongsTo + } + `; + + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: false }); + expect(() => visitor.generate()) + .toThrowError(`Error processing @hasMany directive on SqlPrimary.related. @belongsTo directive with references ["primaryId"] was not found in connected model SqlRelated`); + }); + + test('throws error when missing references on hasMany related model', () => { const schema = /* GraphQL */ ` type SqlPrimary @refersTo(name: "sql_primary") @model { @@ -758,7 +780,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`Error processing @hasMany directive on SqlPrimary.related. @belongsTo directive with references ["primaryId"] was not found in connected model SqlRelated`); }); @@ -779,7 +801,7 @@ describe('custom references', () => { } `; - const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema, { respectPrimaryKeyAttributesOnConnectionField: true }); expect(() => visitor.generate()) .toThrowError(`Error processing @belongsTo directive on SqlRelated.primary. @hasOne or @hasMany directive with references ["primaryId"] was not found in connected model SqlPrimary`); }); diff --git a/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts b/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts index 76cf7623a..501e951f5 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-belongs-to.ts @@ -6,7 +6,7 @@ import { flattenFieldDirectives, makeConnectionAttributeName, } from './process-connections'; -import { getConnectedFieldV2, fieldsAndReferencesErrorMessage } from './process-connections-v2'; +import { getConnectedFieldV2, getConnectedFieldForReferences } from './process-connections-v2'; export function processBelongsToConnection( @@ -28,20 +28,21 @@ export function processBelongsToConnection( `A 'belongsTo' field should match to a corresponding 'hasMany' or 'hasOne' field` ); } + const references = connectionDirective.arguments.references || []; + const isUsingReferences = references.length > 0; + if (isUsingReferences) { + // ensure there is a matching hasOne/hasMany field with references + getConnectedFieldForReferences(field, model, otherSide, connectionDirective.name) + } + const otherSideField = isCustomPKEnabled ? otherSideConnectedFields[0] : getConnectedFieldV2(field, model, otherSide, connectionDirective.name); const connectionFields = connectionDirective.arguments.fields || []; - const references = connectionDirective.arguments.references || []; - - if (connectionFields.length > 0 && references.length > 0) { - throw new Error(fieldsAndReferencesErrorMessage); - } // if a type is connected using name, then amplify-graphql-relational-transformer adds a field to // track the connection and that field is not part of the selection set // but if the field are connected using fields argument in connection directive // we are reusing the field and it should be preserved in selection set const otherSideHasMany = otherSideField.isList; - const isUsingReferences = references.length > 0; // New metada type introduced by custom PK v2 support let targetNames: string[] = [ ...connectionFields, ...references ]; if (targetNames.length === 0) { diff --git a/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts b/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts index 851f541e3..f8d9f733b 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-connections-v2.ts @@ -19,23 +19,8 @@ export function getConnectedFieldV2( if (!connectionInfo) { throw new Error(`The ${field.name} on model ${model.name} is not connected`); } - - const references = connectionInfo.arguments.references; if (connectionInfo.name === 'belongsTo') { let connectedFieldsBelongsTo = getBelongsToConnectedFields(model, connectedModel); - if (references) { - const connectedField = connectedFieldsBelongsTo.find((field) => { - return field.directives.some((dir) => { - return (dir.name === 'hasOne' || dir.name === 'hasMany') - && dir.arguments.references - && JSON.stringify(dir.arguments.references) === JSON.stringify(connectionInfo.arguments.references); - }); - }); - if (!connectedField) { - throw new Error(`Error processing @belongsTo directive on ${model.name}.${field.name}. @hasOne or @hasMany directive with references ${JSON.stringify(connectionInfo.arguments?.references)} was not found in connected model ${connectedModel.name}`); - } - return connectedField; - } if (connectedFieldsBelongsTo.length === 1) { return connectedFieldsBelongsTo[0]; @@ -44,25 +29,10 @@ export function getConnectedFieldV2( const indexName = connectionInfo.arguments.indexName; const connectionFields = connectionInfo.arguments.fields; - if (connectionFields && references) { - throw new Error(fieldsAndReferencesErrorMessage); - } - if (references || connectionFields || directiveName === 'hasOne') { + if (connectionFields || directiveName === 'hasOne') { let connectionDirective; - if (references) { - if (connectionInfo) { - connectionDirective = flattenFieldDirectives(connectedModel).find((dir) => { - return dir.arguments.references - && JSON.stringify(dir.arguments.references) === JSON.stringify(connectionInfo.arguments.references); - }); - if (!connectionDirective) { - throw new Error(`Error processing @${connectionInfo.name} directive on ${model.name}.${field.name}. @belongsTo directive with references ${JSON.stringify(connectionInfo.arguments?.references)} was not found in connected model ${connectedModel.name}`); - } - } - } - // Find gsi on other side if index is defined - else if (indexName) { + if (indexName) { connectionDirective = flattenFieldDirectives(connectedModel).find(dir => { return dir.name === 'index' && dir.arguments.name === indexName; }); @@ -154,6 +124,56 @@ export function getConnectedFieldV2( }; } +export function getConnectedFieldForReferences( + field: CodeGenField, + model: CodeGenModel, + connectedModel: CodeGenModel, + directiveName: string, +): CodeGenField { + const connectionInfo = getDirective(field)(directiveName); + if (!connectionInfo) { + throw new Error(`The ${field.name} on model ${model.name} is not connected`); + } + const references = connectionInfo.arguments.references; + if (!references) { + throw new Error(`The ${field.name} on model ${model.name} does not have references.`); + } + const connectionFields = connectionInfo.arguments.fields; + if (connectionFields && references) { + throw new Error(`'fields' and 'references' cannot be used together.`); + } + + if (connectionInfo.name === 'belongsTo') { + let connectedFieldsBelongsTo = getBelongsToConnectedFields(model, connectedModel); + const connectedField = connectedFieldsBelongsTo.find((field) => { + return field.directives.some((dir) => { + return (dir.name === 'hasOne' || dir.name === 'hasMany') + && dir.arguments.references + && JSON.stringify(dir.arguments.references) === JSON.stringify(connectionInfo.arguments.references); + }); + }); + if (!connectedField) { + throw new Error(`Error processing @belongsTo directive on ${model.name}.${field.name}. @hasOne or @hasMany directive with references ${JSON.stringify(connectionInfo.arguments?.references)} was not found in connected model ${connectedModel.name}`); + } + return connectedField; + } + + // hasOne and hasMany + const connectionDirective = flattenFieldDirectives(connectedModel).find((dir) => { + return dir.arguments.references + && JSON.stringify(dir.arguments.references) === JSON.stringify(connectionInfo.arguments.references); + }); + if (!connectionDirective) { + throw new Error(`Error processing @${connectionInfo.name} directive on ${model.name}.${field.name}. @belongsTo directive with references ${JSON.stringify(connectionInfo.arguments?.references)} was not found in connected model ${connectedModel.name}`); + } + const connectedFieldName = ((fieldDir: CodeGenFieldDirective) => { + return fieldDir.fieldName; + })(connectionDirective as CodeGenFieldDirective) + + const connectedField = connectedModel.fields.find(f => f.name === connectedFieldName); + return connectedField!; +} + export function processConnectionsV2( field: CodeGenField, model: CodeGenModel, @@ -177,5 +197,3 @@ export function processConnectionsV2( } } } - -export const fieldsAndReferencesErrorMessage = `'fields' and 'references' cannot be used together.`; diff --git a/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts b/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts index baebe65ba..6443eef2c 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-has-many.ts @@ -9,7 +9,7 @@ import { flattenFieldDirectives, CodeGenFieldConnectionHasMany, } from './process-connections'; -import { getConnectedFieldV2, fieldsAndReferencesErrorMessage } from './process-connections-v2'; +import { getConnectedFieldV2, getConnectedFieldForReferences } from './process-connections-v2'; export function processHasManyConnection( @@ -27,15 +27,11 @@ export function processHasManyConnection( const connectionFields = connectionDirective.arguments.fields || []; const references = connectionDirective.arguments.references || []; - if (connectionFields.length > 0 && references.length > 0) { - throw new Error(fieldsAndReferencesErrorMessage); - } - if (references.length > 0) { // native uses the connected field instead of associatedWithFields // when using references associatedWithFields and associatedWithNative are not the same - // getConnectedFieldV2 also ensures there is a matching belongsTo field with references - const associatedWithNativeReferences = getConnectedFieldV2(field, model, otherSide, connectionDirective.name, shouldUseModelNameFieldInHasManyAndBelongsTo) + // getConnectedFieldForRerences also ensures there is a matching belongsTo field with references + const associatedWithNativeReferences = getConnectedFieldForReferences(field, model, otherSide, connectionDirective.name) const associatedWithFields = references.map((reference: string) => otherSide.fields.find((field) => reference === field.name)) return { kind: CodeGenConnectionType.HAS_MANY, diff --git a/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts b/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts index 45d0fb781..bcaa63a07 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-has-one.ts @@ -4,7 +4,7 @@ import { CodeGenFieldConnection, makeConnectionAttributeName, } from './process-connections'; -import { getConnectedFieldV2, fieldsAndReferencesErrorMessage } from './process-connections-v2'; +import { getConnectedFieldV2, getConnectedFieldForReferences } from './process-connections-v2'; import { getModelPrimaryKeyComponentFields } from './fieldUtils'; import { getOtherSideBelongsToField } from './fieldUtils'; @@ -26,16 +26,12 @@ export function processHasOneConnection( const connectionFields = connectionDirective.arguments.fields || []; const references = connectionDirective.arguments.references || []; - if (connectionFields.length > 0 && references.length > 0) { - throw new Error(fieldsAndReferencesErrorMessage); - } - let associatedWithFields; if (references.length > 0) { // native uses the connected field instead of associatedWithFields // when using references associatedWithFields and associatedWithNative are not the same - // getConnectedFieldV2 also ensures there is a matching belongsTo field with references - const associatedWithNativeReferences = getConnectedFieldV2(field, model, otherSide, connectionDirective.name); + // getConnectedFieldForReferences also ensures there is a matching belongsTo field with references + const associatedWithNativeReferences = getConnectedFieldForReferences(field, model, otherSide, connectionDirective.name) associatedWithFields = references.map((reference: string) => otherSide.fields.find((field) => reference === field.name)) return { kind: CodeGenConnectionType.HAS_ONE,