From e42d10f69058d7bc0b3181746d8223b054776156 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Fri, 19 Apr 2024 09:40:40 -0600 Subject: [PATCH 1/3] test: add references snapshots for native platforms --- .../appsync-dart-visitor.test.ts.snap | 2773 +++++++++++++++++ .../appsync-java-visitor.test.ts.snap | 2227 +++++++++++++ .../appsync-swift-visitor.test.ts.snap | 1335 ++++++++ .../visitors/appsync-dart-visitor.test.ts | 150 + .../visitors/appsync-java-visitor.test.ts | 130 + .../visitors/appsync-swift-visitor.test.ts | 163 + 6 files changed, 6778 insertions(+) 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 6e6c50422..ed4eda111 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 @@ -11597,3 +11597,2776 @@ class CpkOneToOneBidirectionalChildExplicitModelIdentifier implements amplify_co name.hashCode; }" `; + +exports[`AppSync Dart Visitor custom references double linked references 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Foo type in your schema. */ +class Foo extends amplify_core.Model { + static const classType = const _FooModelType(); + final String id; + final Bar? _bar1; + final Bar? _bar2; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + FooModelIdentifier get modelIdentifier { + return FooModelIdentifier( + id: id + ); + } + + Bar? get bar1 { + return _bar1; + } + + Bar? get bar2 { + return _bar2; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + 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}) { + return Foo._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + bar1: bar1, + bar2: bar2); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Foo && + id == other.id && + _bar1 == other._bar1 && + _bar2 == other._bar2; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + 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(\\"}\\"); + + return buffer.toString(); + } + + Foo copyWith({Bar? bar1, Bar? bar2}) { + return Foo._internal( + id: id, + bar1: bar1 ?? this.bar1, + bar2: bar2 ?? this.bar2); + } + + Foo copyWithModelFieldValues({ + ModelFieldValue? bar1, + ModelFieldValue? bar2 + }) { + return Foo._internal( + id: id, + bar1: bar1 == null ? this.bar1 : bar1.value, + bar2: bar2 == null ? this.bar2 : bar2.value + ); + } + + Foo.fromJson(Map json) + : id = json['id'], + _bar1 = json['bar1']?['serializedData'] != null + ? Bar.fromJson(new Map.from(json['bar1']['serializedData'])) + : null, + _bar2 = json['bar2']?['serializedData'] != null + ? Bar.fromJson(new Map.from(json['bar2']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _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() + }; + + Map toMap() => { + 'id': id, + 'bar1': _bar1, + 'bar2': _bar2, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final BAR1 = amplify_core.QueryField( + fieldName: \\"bar1\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Bar')); + static final BAR2 = amplify_core.QueryField( + fieldName: \\"bar2\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Bar')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Foo\\"; + modelSchemaDefinition.pluralName = \\"Foos\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasOne( + key: Foo.BAR1, + isRequired: false, + ofModelName: 'Bar', + associatedKey: Bar.BAR1ID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasOne( + key: Foo.BAR2, + isRequired: false, + ofModelName: 'Bar', + associatedKey: Bar.BAR2ID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _FooModelType extends amplify_core.ModelType { + const _FooModelType(); + + @override + Foo fromJson(Map jsonData) { + return Foo.fromJson(jsonData); + } + + @override + String modelName() { + return 'Foo'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Foo] in your schema. + */ +class FooModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of FooModelIdentifier using [id] the primary key. */ + const FooModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'FooModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is FooModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references double linked references 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Bar type in your schema. */ +class Bar extends amplify_core.Model { + static const classType = const _BarModelType(); + final String id; + final Foo? _foo1; + final Foo? _foo2; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + BarModelIdentifier get modelIdentifier { + return BarModelIdentifier( + id: id + ); + } + + Foo? get foo1 { + return _foo1; + } + + Foo? get foo2 { + return _foo2; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const Bar._internal({required this.id, foo1, foo2, createdAt, updatedAt}): _foo1 = foo1, _foo2 = foo2, _createdAt = createdAt, _updatedAt = updatedAt; + + factory Bar({String? id, Foo? foo1, Foo? foo2}) { + return Bar._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + foo1: foo1, + foo2: foo2); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Bar && + id == other.id && + _foo1 == other._foo1 && + _foo2 == other._foo2; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Bar {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"foo1=\\" + (_foo1 != null ? _foo1!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"foo2=\\" + (_foo2 != null ? _foo2!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Bar copyWith({Foo? foo1, Foo? foo2}) { + return Bar._internal( + id: id, + foo1: foo1 ?? this.foo1, + foo2: foo2 ?? this.foo2); + } + + Bar copyWithModelFieldValues({ + ModelFieldValue? foo1, + ModelFieldValue? foo2 + }) { + return Bar._internal( + id: id, + foo1: foo1 == null ? this.foo1 : foo1.value, + foo2: foo2 == null ? this.foo2 : foo2.value + ); + } + + Bar.fromJson(Map json) + : id = json['id'], + _foo1 = json['foo1']?['serializedData'] != null + ? Foo.fromJson(new Map.from(json['foo1']['serializedData'])) + : null, + _foo2 = json['foo2']?['serializedData'] != null + ? Foo.fromJson(new Map.from(json['foo2']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'foo1': _foo1?.toJson(), 'foo2': _foo2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'foo1': _foo1, + 'foo2': _foo2, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final FOO1 = amplify_core.QueryField( + fieldName: \\"foo1\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Foo')); + static final FOO2 = amplify_core.QueryField( + fieldName: \\"foo2\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Foo')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Bar\\"; + modelSchemaDefinition.pluralName = \\"Bars\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Bar.FOO1, + isRequired: false, + targetNames: ['bar1Id'], + ofModelName: 'Foo' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Bar.FOO2, + isRequired: false, + targetNames: ['bar2Id'], + ofModelName: 'Foo' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _BarModelType extends amplify_core.ModelType { + const _BarModelType(); + + @override + Bar fromJson(Map jsonData) { + return Bar.fromJson(jsonData); + } + + @override + String modelName() { + return 'Bar'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Bar] in your schema. + */ +class BarModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of BarModelIdentifier using [id] the primary key. */ + const BarModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'BarModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is BarModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references hasMany with sortKeyFields on primary key 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Primary type in your schema. */ +class Primary extends amplify_core.Model { + static const classType = const _PrimaryModelType(); + final String? _tenantId; + final String? _instanceId; + final String? _recordId; + final String? _content; + final List? _related; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => modelIdentifier.serializeAsString(); + + PrimaryModelIdentifier get modelIdentifier { + try { + return PrimaryModelIdentifier( + tenantId: _tenantId!, + instanceId: _instanceId!, + recordId: _recordId! + ); + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get tenantId { + try { + return _tenantId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get instanceId { + try { + return _instanceId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get recordId { + try { + return _recordId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String? get content { + return _content; + } + + List? get related { + return _related; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + 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, List? related}) { + return Primary._internal( + tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content, + related: related != null ? List.unmodifiable(related) : related); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Primary && + _tenantId == other._tenantId && + _instanceId == other._instanceId && + _recordId == other._recordId && + _content == other._content && + DeepCollectionEquality().equals(_related, other._related); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Primary {\\"); + buffer.write(\\"tenantId=\\" + \\"$_tenantId\\" + \\", \\"); + buffer.write(\\"instanceId=\\" + \\"$_instanceId\\" + \\", \\"); + 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(\\"}\\"); + + return buffer.toString(); + } + + Primary copyWith({String? content, List? related}) { + return Primary._internal( + tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content ?? this.content, + related: related ?? this.related); + } + + Primary copyWithModelFieldValues({ + ModelFieldValue? content, + 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 + ); + } + + Primary.fromJson(Map json) + : _tenantId = json['tenantId'], + _instanceId = json['instanceId'], + _recordId = json['recordId'], + _content = json['content'], + _related = json['related'] is List + ? (json['related'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => Related.fromJson(new Map.from(e['serializedData']))) + .toList() + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'tenantId': _tenantId, 'instanceId': _instanceId, 'recordId': _recordId, 'content': _content, 'related': _related?.map((Related? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'tenantId': _tenantId, + 'instanceId': _instanceId, + 'recordId': _recordId, + 'content': _content, + 'related': _related, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final TENANTID = amplify_core.QueryField(fieldName: \\"tenantId\\"); + static final INSTANCEID = amplify_core.QueryField(fieldName: \\"instanceId\\"); + static final RECORDID = amplify_core.QueryField(fieldName: \\"recordId\\"); + static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); + static final RELATED = amplify_core.QueryField( + fieldName: \\"related\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Related')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Primary\\"; + modelSchemaDefinition.pluralName = \\"Primaries\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"tenantId\\", \\"instanceId\\", \\"recordId\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.TENANTID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.INSTANCEID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.RECORDID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Primary.RELATED, + isRequired: true, + ofModelName: 'Related', + associatedKey: Related.PRIMARYTENANTID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _PrimaryModelType extends amplify_core.ModelType { + const _PrimaryModelType(); + + @override + Primary fromJson(Map jsonData) { + return Primary.fromJson(jsonData); + } + + @override + String modelName() { + return 'Primary'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Primary] in your schema. + */ +class PrimaryModelIdentifier implements amplify_core.ModelIdentifier { + final String tenantId; + final String instanceId; + final String recordId; + + /** + * Create an instance of PrimaryModelIdentifier using [tenantId] the primary key. + * And [instanceId], [recordId] the sort keys. + */ + const PrimaryModelIdentifier({ + required this.tenantId, + required this.instanceId, + required this.recordId}); + + @override + Map serializeAsMap() => ({ + 'tenantId': tenantId, + 'instanceId': instanceId, + 'recordId': recordId + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PrimaryModelIdentifier(tenantId: $tenantId, instanceId: $instanceId, recordId: $recordId)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PrimaryModelIdentifier && + tenantId == other.tenantId && + instanceId == other.instanceId && + recordId == other.recordId; + } + + @override + int get hashCode => + tenantId.hashCode ^ + instanceId.hashCode ^ + recordId.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references hasMany with sortKeyFields on primary key 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Related type in your schema. */ +class Related extends amplify_core.Model { + static const classType = const _RelatedModelType(); + final String id; + final String? _content; + final Primary? _primary; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + RelatedModelIdentifier get modelIdentifier { + return RelatedModelIdentifier( + id: id + ); + } + + String? get content { + return _content; + } + + Primary? get primary { + return _primary; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _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, Primary? primary}) { + return Related._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Related && + id == other.id && + _content == other._content && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Related {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); + buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Related copyWith({String? content, Primary? primary}) { + return Related._internal( + id: id, + content: content ?? this.content, + primary: primary ?? this.primary); + } + + Related copyWithModelFieldValues({ + ModelFieldValue? content, + ModelFieldValue? primary + }) { + return Related._internal( + id: id, + content: content == null ? this.content : content.value, + primary: primary == null ? this.primary : primary.value + ); + } + + Related.fromJson(Map json) + : id = json['id'], + _content = json['content'], + _primary = json['primary']?['serializedData'] != null + ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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 PRIMARY = amplify_core.QueryField( + fieldName: \\"primary\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Related\\"; + modelSchemaDefinition.pluralName = \\"Relateds\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Related.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: Related.PRIMARY, + isRequired: false, + targetNames: ['primaryTenantId', 'primaryInstanceId', 'primaryRecordId'], + ofModelName: 'Primary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _RelatedModelType extends amplify_core.ModelType { + const _RelatedModelType(); + + @override + Related fromJson(Map jsonData) { + return Related.fromJson(jsonData); + } + + @override + String modelName() { + return 'Related'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Related] in your schema. + */ +class RelatedModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of RelatedModelIdentifier using [id] the primary key. */ + const RelatedModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'RelatedModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is RelatedModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the SqlPrimary type in your schema. */ +class SqlPrimary extends amplify_core.Model { + static const classType = const _SqlPrimaryModelType(); + final int id; + final String? _content; + final List? _related; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + SqlPrimaryModelIdentifier get modelIdentifier { + return SqlPrimaryModelIdentifier( + id: id + ); + } + + String? get content { + return _content; + } + + List? get related { + return _related; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const SqlPrimary._internal({required this.id, content, related, createdAt, updatedAt}): _content = content, _related = related, _createdAt = createdAt, _updatedAt = updatedAt; + + factory SqlPrimary({int? id, String? content, List? related}) { + return SqlPrimary._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + related: related != null ? List.unmodifiable(related) : related); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SqlPrimary && + id == other.id && + _content == other._content && + DeepCollectionEquality().equals(_related, other._related); + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"SqlPrimary {\\"); + 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(\\"}\\"); + + return buffer.toString(); + } + + SqlPrimary copyWith({String? content, List? related}) { + return SqlPrimary._internal( + id: id, + content: content ?? this.content, + related: related ?? this.related); + } + + SqlPrimary copyWithModelFieldValues({ + ModelFieldValue? content, + ModelFieldValue>? related + }) { + return SqlPrimary._internal( + id: id, + content: content == null ? this.content : content.value, + related: related == null ? this.related : related.value + ); + } + + SqlPrimary.fromJson(Map json) + : id = (json['id'] as num?)?.toInt(), + _content = json['content'], + _related = json['related'] is List + ? (json['related'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => SqlRelated.fromJson(new Map.from(e['serializedData']))) + .toList() + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'content': _content, 'related': _related?.map((SqlRelated? e) => e?.toJson()).toList(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'related': _related, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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 RELATED = amplify_core.QueryField( + fieldName: \\"related\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlRelated')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"SqlPrimary\\"; + modelSchemaDefinition.pluralName = \\"SqlPrimaries\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: SqlPrimary.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: SqlPrimary.RELATED, + isRequired: true, + ofModelName: 'SqlRelated', + associatedKey: SqlRelated.PRIMARYID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _SqlPrimaryModelType extends amplify_core.ModelType { + const _SqlPrimaryModelType(); + + @override + SqlPrimary fromJson(Map jsonData) { + return SqlPrimary.fromJson(jsonData); + } + + @override + String modelName() { + return 'SqlPrimary'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [SqlPrimary] in your schema. + */ +class SqlPrimaryModelIdentifier implements amplify_core.ModelIdentifier { + final int id; + + /** Create an instance of SqlPrimaryModelIdentifier using [id] the primary key. */ + const SqlPrimaryModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'SqlPrimaryModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SqlPrimaryModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasMany/belongsTo 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the SqlRelated type in your schema. */ +class SqlRelated extends amplify_core.Model { + static const classType = const _SqlRelatedModelType(); + final int id; + final String? _content; + final SqlPrimary? _primary; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + SqlRelatedModelIdentifier get modelIdentifier { + return SqlRelatedModelIdentifier( + id: id + ); + } + + String? get content { + return _content; + } + + SqlPrimary? get primary { + return _primary; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _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, SqlPrimary? primary}) { + return SqlRelated._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SqlRelated && + id == other.id && + _content == other._content && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"SqlRelated {\\"); + buffer.write(\\"id=\\" + (id != null ? id!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); + buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + SqlRelated copyWith({String? content, SqlPrimary? primary}) { + return SqlRelated._internal( + id: id, + content: content ?? this.content, + primary: primary ?? this.primary); + } + + SqlRelated copyWithModelFieldValues({ + ModelFieldValue? content, + ModelFieldValue? primary + }) { + return SqlRelated._internal( + id: id, + content: content == null ? this.content : content.value, + primary: primary == null ? this.primary : primary.value + ); + } + + SqlRelated.fromJson(Map json) + : id = (json['id'] as num?)?.toInt(), + _content = json['content'], + _primary = json['primary']?['serializedData'] != null + ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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 PRIMARY = amplify_core.QueryField( + fieldName: \\"primary\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlPrimary')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"SqlRelated\\"; + modelSchemaDefinition.pluralName = \\"SqlRelateds\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null), + amplify_core.ModelIndex(fields: const [\\"primaryId\\"], name: \\"primary_id\\") + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: SqlRelated.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: SqlRelated.PRIMARY, + isRequired: false, + targetNames: ['primaryId'], + ofModelName: 'SqlPrimary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _SqlRelatedModelType extends amplify_core.ModelType { + const _SqlRelatedModelType(); + + @override + SqlRelated fromJson(Map jsonData) { + return SqlRelated.fromJson(jsonData); + } + + @override + String modelName() { + return 'SqlRelated'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [SqlRelated] in your schema. + */ +class SqlRelatedModelIdentifier implements amplify_core.ModelIdentifier { + final int id; + + /** Create an instance of SqlRelatedModelIdentifier using [id] the primary key. */ + const SqlRelatedModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'SqlRelatedModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SqlRelatedModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasOne and hasMany 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; +import 'package:collection/collection.dart'; + + +/** This is an auto generated class representing the Primary type in your schema. */ +class Primary extends amplify_core.Model { + static const classType = const _PrimaryModelType(); + final String id; + final List? _relatedMany; + final RelatedOne? _relatedOne; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + PrimaryModelIdentifier get modelIdentifier { + return PrimaryModelIdentifier( + id: id + ); + } + + List? get relatedMany { + return _relatedMany; + } + + RelatedOne? get relatedOne { + return _relatedOne; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + 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}) { + return Primary._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + relatedMany: relatedMany != null ? List.unmodifiable(relatedMany) : relatedMany, + relatedOne: relatedOne); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Primary && + id == other.id && + DeepCollectionEquality().equals(_relatedMany, other._relatedMany) && + _relatedOne == other._relatedOne; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + 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(\\"}\\"); + + return buffer.toString(); + } + + Primary copyWith({List? relatedMany, RelatedOne? relatedOne}) { + return Primary._internal( + id: id, + relatedMany: relatedMany ?? this.relatedMany, + relatedOne: relatedOne ?? this.relatedOne); + } + + Primary copyWithModelFieldValues({ + ModelFieldValue?>? relatedMany, + ModelFieldValue? relatedOne + }) { + return Primary._internal( + id: id, + relatedMany: relatedMany == null ? this.relatedMany : relatedMany.value, + relatedOne: relatedOne == null ? this.relatedOne : relatedOne.value + ); + } + + Primary.fromJson(Map json) + : id = json['id'], + _relatedMany = json['relatedMany'] is List + ? (json['relatedMany'] as List) + .where((e) => e?['serializedData'] != null) + .map((e) => RelatedMany.fromJson(new Map.from(e['serializedData']))) + .toList() + : null, + _relatedOne = json['relatedOne']?['serializedData'] != null + ? RelatedOne.fromJson(new Map.from(json['relatedOne']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _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() + }; + + Map toMap() => { + 'id': id, + 'relatedMany': _relatedMany, + 'relatedOne': _relatedOne, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final RELATEDMANY = amplify_core.QueryField( + fieldName: \\"relatedMany\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'RelatedMany')); + static final RELATEDONE = amplify_core.QueryField( + fieldName: \\"relatedOne\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'RelatedOne')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Primary\\"; + modelSchemaDefinition.pluralName = \\"Primaries\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasMany( + key: Primary.RELATEDMANY, + isRequired: false, + ofModelName: 'RelatedMany', + associatedKey: RelatedMany.PRIMARYID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasOne( + key: Primary.RELATEDONE, + isRequired: false, + ofModelName: 'RelatedOne', + associatedKey: RelatedOne.PRIMARYID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _PrimaryModelType extends amplify_core.ModelType { + const _PrimaryModelType(); + + @override + Primary fromJson(Map jsonData) { + return Primary.fromJson(jsonData); + } + + @override + String modelName() { + return 'Primary'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Primary] in your schema. + */ +class PrimaryModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of PrimaryModelIdentifier using [id] the primary key. */ + const PrimaryModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PrimaryModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PrimaryModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasOne and hasMany 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the RelatedOne type in your schema. */ +class RelatedOne extends amplify_core.Model { + static const classType = const _RelatedOneModelType(); + final String id; + final Primary? _primary; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + RelatedOneModelIdentifier get modelIdentifier { + return RelatedOneModelIdentifier( + id: id + ); + } + + Primary? get primary { + return _primary; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const RelatedOne._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + + factory RelatedOne({String? id, Primary? primary}) { + return RelatedOne._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is RelatedOne && + id == other.id && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"RelatedOne {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + RelatedOne copyWith({Primary? primary}) { + return RelatedOne._internal( + id: id, + primary: primary ?? this.primary); + } + + RelatedOne copyWithModelFieldValues({ + ModelFieldValue? primary + }) { + return RelatedOne._internal( + id: id, + primary: primary == null ? this.primary : primary.value + ); + } + + RelatedOne.fromJson(Map json) + : id = json['id'], + _primary = json['primary']?['serializedData'] != null + ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final PRIMARY = amplify_core.QueryField( + fieldName: \\"primary\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"RelatedOne\\"; + modelSchemaDefinition.pluralName = \\"RelatedOnes\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: RelatedOne.PRIMARY, + isRequired: false, + targetNames: ['primaryId'], + ofModelName: 'Primary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _RelatedOneModelType extends amplify_core.ModelType { + const _RelatedOneModelType(); + + @override + RelatedOne fromJson(Map jsonData) { + return RelatedOne.fromJson(jsonData); + } + + @override + String modelName() { + return 'RelatedOne'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [RelatedOne] in your schema. + */ +class RelatedOneModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of RelatedOneModelIdentifier using [id] the primary key. */ + const RelatedOneModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'RelatedOneModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is RelatedOneModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasOne and hasMany 3`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the RelatedMany type in your schema. */ +class RelatedMany extends amplify_core.Model { + static const classType = const _RelatedManyModelType(); + final String id; + final Primary? _primary; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + RelatedManyModelIdentifier get modelIdentifier { + return RelatedManyModelIdentifier( + id: id + ); + } + + Primary? get primary { + return _primary; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + const RelatedMany._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + + factory RelatedMany({String? id, Primary? primary}) { + return RelatedMany._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is RelatedMany && + id == other.id && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"RelatedMany {\\"); + buffer.write(\\"id=\\" + \\"$id\\" + \\", \\"); + buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + RelatedMany copyWith({Primary? primary}) { + return RelatedMany._internal( + id: id, + primary: primary ?? this.primary); + } + + RelatedMany copyWithModelFieldValues({ + ModelFieldValue? primary + }) { + return RelatedMany._internal( + id: id, + primary: primary == null ? this.primary : primary.value + ); + } + + RelatedMany.fromJson(Map json) + : id = json['id'], + _primary = json['primary']?['serializedData'] != null + ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final ID = amplify_core.QueryField(fieldName: \\"id\\"); + static final PRIMARY = amplify_core.QueryField( + fieldName: \\"primary\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Primary')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"RelatedMany\\"; + modelSchemaDefinition.pluralName = \\"RelatedManies\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: RelatedMany.PRIMARY, + isRequired: false, + targetNames: ['primaryId'], + ofModelName: 'Primary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _RelatedManyModelType extends amplify_core.ModelType { + const _RelatedManyModelType(); + + @override + RelatedMany fromJson(Map jsonData) { + return RelatedMany.fromJson(jsonData); + } + + @override + String modelName() { + return 'RelatedMany'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [RelatedMany] in your schema. + */ +class RelatedManyModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of RelatedManyModelIdentifier using [id] the primary key. */ + const RelatedManyModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'RelatedManyModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is RelatedManyModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasOne/belongsTo 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the SqlPrimary type in your schema. */ +class SqlPrimary extends amplify_core.Model { + static const classType = const _SqlPrimaryModelType(); + final int id; + final String? _content; + final SqlRelated? _related; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + SqlPrimaryModelIdentifier get modelIdentifier { + return SqlPrimaryModelIdentifier( + id: id + ); + } + + String? get content { + return _content; + } + + SqlRelated? get related { + return _related; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + 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}) { + return SqlPrimary._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + related: related); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SqlPrimary && + id == other.id && + _content == other._content && + _related == other._related; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"SqlPrimary {\\"); + 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(\\"}\\"); + + return buffer.toString(); + } + + SqlPrimary copyWith({String? content, SqlRelated? related}) { + return SqlPrimary._internal( + id: id, + content: content ?? this.content, + related: related ?? this.related); + } + + SqlPrimary copyWithModelFieldValues({ + ModelFieldValue? content, + ModelFieldValue? related + }) { + return SqlPrimary._internal( + id: id, + content: content == null ? this.content : content.value, + related: related == null ? this.related : related.value + ); + } + + SqlPrimary.fromJson(Map json) + : id = (json['id'] as num?)?.toInt(), + _content = json['content'], + _related = json['related']?['serializedData'] != null + ? SqlRelated.fromJson(new Map.from(json['related']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _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() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'related': _related, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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 RELATED = amplify_core.QueryField( + fieldName: \\"related\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlRelated')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"SqlPrimary\\"; + modelSchemaDefinition.pluralName = \\"SqlPrimaries\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: SqlPrimary.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasOne( + key: SqlPrimary.RELATED, + isRequired: false, + ofModelName: 'SqlRelated', + associatedKey: SqlRelated.PRIMARYID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _SqlPrimaryModelType extends amplify_core.ModelType { + const _SqlPrimaryModelType(); + + @override + SqlPrimary fromJson(Map jsonData) { + return SqlPrimary.fromJson(jsonData); + } + + @override + String modelName() { + return 'SqlPrimary'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [SqlPrimary] in your schema. + */ +class SqlPrimaryModelIdentifier implements amplify_core.ModelIdentifier { + final int id; + + /** Create an instance of SqlPrimaryModelIdentifier using [id] the primary key. */ + const SqlPrimaryModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'SqlPrimaryModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SqlPrimaryModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references sets the association to the references field for hasOne/belongsTo 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the SqlRelated type in your schema. */ +class SqlRelated extends amplify_core.Model { + static const classType = const _SqlRelatedModelType(); + final int id; + final String? _content; + final SqlPrimary? _primary; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + SqlRelatedModelIdentifier get modelIdentifier { + return SqlRelatedModelIdentifier( + id: id + ); + } + + String? get content { + return _content; + } + + SqlPrimary? get primary { + return _primary; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _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, SqlPrimary? primary}) { + return SqlRelated._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is SqlRelated && + id == other.id && + _content == other._content && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"SqlRelated {\\"); + buffer.write(\\"id=\\" + (id != null ? id!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"content=\\" + \\"$_content\\" + \\", \\"); + buffer.write(\\"primary=\\" + (_primary != null ? _primary!.toString() : \\"null\\") + \\", \\"); + buffer.write(\\"createdAt=\\" + (_createdAt != null ? _createdAt!.format() : \\"null\\") + \\", \\"); + buffer.write(\\"updatedAt=\\" + (_updatedAt != null ? _updatedAt!.format() : \\"null\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + SqlRelated copyWith({String? content, SqlPrimary? primary}) { + return SqlRelated._internal( + id: id, + content: content ?? this.content, + primary: primary ?? this.primary); + } + + SqlRelated copyWithModelFieldValues({ + ModelFieldValue? content, + ModelFieldValue? primary + }) { + return SqlRelated._internal( + id: id, + content: content == null ? this.content : content.value, + primary: primary == null ? this.primary : primary.value + ); + } + + SqlRelated.fromJson(Map json) + : id = (json['id'] as num?)?.toInt(), + _content = json['content'], + _primary = json['primary']?['serializedData'] != null + ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; + + Map toJson() => { + 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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 PRIMARY = amplify_core.QueryField( + fieldName: \\"primary\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'SqlPrimary')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"SqlRelated\\"; + modelSchemaDefinition.pluralName = \\"SqlRelateds\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"id\\"], name: null), + amplify_core.ModelIndex(fields: const [\\"primaryId\\"], name: \\"primary_id\\") + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: SqlRelated.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.belongsTo( + key: SqlRelated.PRIMARY, + isRequired: false, + targetNames: ['primaryId'], + ofModelName: 'SqlPrimary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _SqlRelatedModelType extends amplify_core.ModelType { + const _SqlRelatedModelType(); + + @override + SqlRelated fromJson(Map jsonData) { + return SqlRelated.fromJson(jsonData); + } + + @override + String modelName() { + return 'SqlRelated'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [SqlRelated] in your schema. + */ +class SqlRelatedModelIdentifier implements amplify_core.ModelIdentifier { + final int id; + + /** Create an instance of SqlRelatedModelIdentifier using [id] the primary key. */ + const SqlRelatedModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'SqlRelatedModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is SqlRelatedModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; 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 b973bf217..2ad2640f4 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 @@ -7845,6 +7845,2233 @@ public final class Todo implements Model { " `; +exports[`AppSyncModelVisitor custom references double linked references 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Foo type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Foos\\", type = Model.Type.USER, version = 1) +public final class Foo implements Model { + public static final QueryField ID = field(\\"Foo\\", \\"id\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"Bar\\") @HasOne(associatedWith = \\"bar1Id\\", type = Bar.class) Bar bar1 = null; + private final @ModelField(targetType=\\"Bar\\") @HasOne(associatedWith = \\"bar2Id\\", type = Bar.class) Bar bar2 = null; + 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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public Bar getBar1() { + return bar1; + } + + public Bar getBar2() { + return bar2; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Foo(String id) { + this.id = id; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Foo foo = (Foo) obj; + return ObjectsCompat.equals(getId(), foo.getId()) && + ObjectsCompat.equals(getCreatedAt(), foo.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), foo.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Foo {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Foo justId(String id) { + return new Foo( + id + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id); + } + public interface BuildStep { + Foo build(); + BuildStep id(String id); + } + + + public static class Builder implements BuildStep { + private String id; + public Builder() { + + } + + private Builder(String id) { + this.id = id; + } + + @Override + public Foo build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Foo( + id); + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id) { + super(id); + + } + } + + + public static class FooIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public FooIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references double linked references 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Bar type in your schema. */ +@SuppressWarnings(\\"all\\") +@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 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=\\"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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public Foo getFoo1() { + return foo1; + } + + public Foo getFoo2() { + return foo2; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Bar(String id, Foo foo1, Foo foo2) { + this.id = id; + this.foo1 = foo1; + this.foo2 = foo2; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Bar bar = (Bar) obj; + return ObjectsCompat.equals(getId(), bar.getId()) && + ObjectsCompat.equals(getFoo1(), bar.getFoo1()) && + ObjectsCompat.equals(getFoo2(), bar.getFoo2()) && + ObjectsCompat.equals(getCreatedAt(), bar.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), bar.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getFoo1()) + .append(getFoo2()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Bar {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"foo1=\\" + String.valueOf(getFoo1()) + \\", \\") + .append(\\"foo2=\\" + String.valueOf(getFoo2()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Bar justId(String id) { + return new Bar( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + foo1, + foo2); + } + public interface BuildStep { + Bar build(); + BuildStep id(String id); + BuildStep foo1(Foo foo1); + BuildStep foo2(Foo foo2); + } + + + public static class Builder implements BuildStep { + private String id; + private Foo foo1; + private Foo foo2; + public Builder() { + + } + + private Builder(String id, Foo foo1, Foo foo2) { + this.id = id; + this.foo1 = foo1; + this.foo2 = foo2; + } + + @Override + public Bar build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Bar( + id, + foo1, + foo2); + } + + @Override + public BuildStep foo1(Foo foo1) { + this.foo1 = foo1; + return this; + } + + @Override + public BuildStep foo2(Foo foo2) { + this.foo2 = foo2; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, Foo foo1, Foo foo2) { + super(id, foo1, foo2); + + } + + @Override + public CopyOfBuilder foo1(Foo foo1) { + return (CopyOfBuilder) super.foo1(foo1); + } + + @Override + public CopyOfBuilder foo2(Foo foo2) { + return (CopyOfBuilder) super.foo2(foo2); + } + } + + + public static class BarIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public BarIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references hasMany with sortKeyFields on primary key 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Primary type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Primaries\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"tenantId\\",\\"instanceId\\",\\"recordId\\"}) +public final class Primary implements Model { + public static final QueryField TENANT_ID = field(\\"Primary\\", \\"tenantId\\"); + 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\\"); + 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; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"Related\\") @HasMany(associatedWith = \\"primaryTenantId\\", type = Related.class) List related = null; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime createdAt; + private @ModelField(targetType=\\"AWSDateTime\\", isReadOnly = true) Temporal.DateTime updatedAt; + private PrimaryIdentifier primaryIdentifier; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public PrimaryIdentifier resolveIdentifier() { + if (primaryIdentifier == null) { + this.primaryIdentifier = new PrimaryIdentifier(tenantId, instanceId, recordId); + } + return primaryIdentifier; + } + + public String getTenantId() { + return tenantId; + } + + public String getInstanceId() { + return instanceId; + } + + public String getRecordId() { + return recordId; + } + + public String getContent() { + return content; + } + + public List getRelated() { + return related; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Primary(String tenantId, String instanceId, String recordId, String content) { + this.tenantId = tenantId; + this.instanceId = instanceId; + this.recordId = recordId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Primary primary = (Primary) obj; + return ObjectsCompat.equals(getTenantId(), primary.getTenantId()) && + ObjectsCompat.equals(getInstanceId(), primary.getInstanceId()) && + ObjectsCompat.equals(getRecordId(), primary.getRecordId()) && + ObjectsCompat.equals(getContent(), primary.getContent()) && + ObjectsCompat.equals(getCreatedAt(), primary.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getTenantId()) + .append(getInstanceId()) + .append(getRecordId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Primary {\\") + .append(\\"tenantId=\\" + String.valueOf(getTenantId()) + \\", \\") + .append(\\"instanceId=\\" + String.valueOf(getInstanceId()) + \\", \\") + .append(\\"recordId=\\" + String.valueOf(getRecordId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static TenantIdStep builder() { + return new Builder(); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(tenantId, + instanceId, + recordId, + content); + } + public interface TenantIdStep { + InstanceIdStep tenantId(String tenantId); + } + + + public interface InstanceIdStep { + RecordIdStep instanceId(String instanceId); + } + + + public interface RecordIdStep { + BuildStep recordId(String recordId); + } + + + public interface BuildStep { + Primary build(); + BuildStep content(String content); + } + + + public static class Builder implements TenantIdStep, InstanceIdStep, RecordIdStep, BuildStep { + private String tenantId; + private String instanceId; + private String recordId; + private String content; + public Builder() { + + } + + private Builder(String tenantId, String instanceId, String recordId, String content) { + this.tenantId = tenantId; + this.instanceId = instanceId; + this.recordId = recordId; + this.content = content; + } + + @Override + public Primary build() { + + return new Primary( + tenantId, + instanceId, + recordId, + content); + } + + @Override + public InstanceIdStep tenantId(String tenantId) { + Objects.requireNonNull(tenantId); + this.tenantId = tenantId; + return this; + } + + @Override + public RecordIdStep instanceId(String instanceId) { + Objects.requireNonNull(instanceId); + this.instanceId = instanceId; + return this; + } + + @Override + public BuildStep recordId(String recordId) { + Objects.requireNonNull(recordId); + this.recordId = recordId; + return this; + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String tenantId, String instanceId, String recordId, String content) { + super(tenantId, instanceId, recordId, content); + Objects.requireNonNull(tenantId); + Objects.requireNonNull(instanceId); + Objects.requireNonNull(recordId); + } + + @Override + public CopyOfBuilder tenantId(String tenantId) { + return (CopyOfBuilder) super.tenantId(tenantId); + } + + @Override + public CopyOfBuilder instanceId(String instanceId) { + return (CopyOfBuilder) super.instanceId(instanceId); + } + + @Override + public CopyOfBuilder recordId(String recordId) { + return (CopyOfBuilder) super.recordId(recordId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + + + public static class PrimaryIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public PrimaryIdentifier(String tenantId, String instanceId, String recordId) { + super(tenantId, instanceId, recordId); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references hasMany with sortKeyFields on primary key 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Related type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Relateds\\", type = Model.Type.USER, version = 1) +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 = field(\\"Related\\", \\"primaryTenantId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"String\\") String content; + 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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public Primary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Related(String id, String content, Primary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Related related = (Related) obj; + return ObjectsCompat.equals(getId(), related.getId()) && + ObjectsCompat.equals(getContent(), related.getContent()) && + ObjectsCompat.equals(getPrimary(), related.getPrimary()) && + ObjectsCompat.equals(getCreatedAt(), related.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), related.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Related {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Related justId(String id) { + return new Related( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + primary); + } + public interface BuildStep { + Related build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep primary(Primary primary); + } + + + public static class Builder implements BuildStep { + private String id; + private String content; + private Primary primary; + public Builder() { + + } + + private Builder(String id, String content, Primary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public Related build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Related( + id, + content, + primary); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep primary(Primary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, String content, Primary primary) { + super(id, content, primary); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder primary(Primary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class RelatedIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public RelatedIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the SqlPrimary type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"SqlPrimaries\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class SqlPrimary implements Model { + public static final QueryField ID = field(\\"SqlPrimary\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"SqlPrimary\\", \\"content\\"); + private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"SqlRelated\\") @HasMany(associatedWith = \\"primaryId\\", type = SqlRelated.class) List related = null; + 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. */ + @Deprecated + public Integer resolveIdentifier() { + return id; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } + + public List getRelated() { + return related; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private SqlPrimary(Integer id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + SqlPrimary sqlPrimary = (SqlPrimary) obj; + return ObjectsCompat.equals(getId(), sqlPrimary.getId()) && + ObjectsCompat.equals(getContent(), sqlPrimary.getContent()) && + ObjectsCompat.equals(getCreatedAt(), sqlPrimary.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), sqlPrimary.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"SqlPrimary {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static SqlPrimary justId(String id) { + return new SqlPrimary( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + SqlPrimary build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private Integer id; + private String content; + public Builder() { + + } + + private Builder(Integer id, String content) { + this.id = id; + this.content = content; + } + + @Override + public SqlPrimary build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new SqlPrimary( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(Integer id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + + + public static class SqlPrimaryIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public SqlPrimaryIdentifier(Integer id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasMany/belongsTo 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the SqlRelated type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"SqlRelateds\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +@Index(name = \\"primary_id\\", fields = {\\"primaryId\\"}) +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 = field(\\"SqlRelated\\", \\"primaryId\\"); + private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; + private final @ModelField(targetType=\\"String\\") String content; + 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. */ + @Deprecated + public Integer resolveIdentifier() { + return id; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } + + public SqlPrimary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private SqlRelated(Integer id, String content, SqlPrimary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + SqlRelated sqlRelated = (SqlRelated) obj; + return ObjectsCompat.equals(getId(), sqlRelated.getId()) && + ObjectsCompat.equals(getContent(), sqlRelated.getContent()) && + ObjectsCompat.equals(getPrimary(), sqlRelated.getPrimary()) && + ObjectsCompat.equals(getCreatedAt(), sqlRelated.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), sqlRelated.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"SqlRelated {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static SqlRelated justId(String id) { + return new SqlRelated( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + primary); + } + public interface BuildStep { + SqlRelated build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep primary(SqlPrimary primary); + } + + + public static class Builder implements BuildStep { + private Integer id; + private String content; + private SqlPrimary primary; + public Builder() { + + } + + private Builder(Integer id, String content, SqlPrimary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public SqlRelated build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new SqlRelated( + id, + content, + primary); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep primary(SqlPrimary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { + super(id, content, primary); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder primary(SqlPrimary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class SqlRelatedIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public SqlRelatedIdentifier(Integer id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasOne and hasMany 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasMany; +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Primary type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Primaries\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class Primary implements Model { + public static final QueryField ID = field(\\"Primary\\", \\"id\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + private final @ModelField(targetType=\\"RelatedMany\\") @HasMany(associatedWith = \\"primaryId\\", type = RelatedMany.class) List relatedMany = null; + private final @ModelField(targetType=\\"RelatedOne\\") @HasOne(associatedWith = \\"primaryId\\", type = RelatedOne.class) RelatedOne relatedOne = null; + 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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public List getRelatedMany() { + return relatedMany; + } + + public RelatedOne getRelatedOne() { + return relatedOne; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Primary(String id) { + this.id = id; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Primary primary = (Primary) obj; + return ObjectsCompat.equals(getId(), primary.getId()) && + ObjectsCompat.equals(getCreatedAt(), primary.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Primary {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Primary justId(String id) { + return new Primary( + id + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id); + } + public interface BuildStep { + Primary build(); + BuildStep id(String id); + } + + + public static class Builder implements BuildStep { + private String id; + public Builder() { + + } + + private Builder(String id) { + this.id = id; + } + + @Override + public Primary build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new Primary( + id); + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id) { + super(id); + + } + } + + + public static class PrimaryIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public PrimaryIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasOne and hasMany 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the RelatedMany type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"RelatedManies\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class RelatedMany implements Model { + public static final QueryField ID = field(\\"RelatedMany\\", \\"id\\"); + public static final QueryField PRIMARY = field(\\"RelatedMany\\", \\"primaryId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + 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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public Primary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private RelatedMany(String id, Primary primary) { + this.id = id; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + RelatedMany relatedMany = (RelatedMany) obj; + return ObjectsCompat.equals(getId(), relatedMany.getId()) && + ObjectsCompat.equals(getPrimary(), relatedMany.getPrimary()) && + ObjectsCompat.equals(getCreatedAt(), relatedMany.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), relatedMany.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"RelatedMany {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static RelatedMany justId(String id) { + return new RelatedMany( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + primary); + } + public interface BuildStep { + RelatedMany build(); + BuildStep id(String id); + BuildStep primary(Primary primary); + } + + + public static class Builder implements BuildStep { + private String id; + private Primary primary; + public Builder() { + + } + + private Builder(String id, Primary primary) { + this.id = id; + this.primary = primary; + } + + @Override + public RelatedMany build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new RelatedMany( + id, + primary); + } + + @Override + public BuildStep primary(Primary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, Primary primary) { + super(id, primary); + + } + + @Override + public CopyOfBuilder primary(Primary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class RelatedManyIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public RelatedManyIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasOne and hasMany 3`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the RelatedOne type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"RelatedOnes\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class RelatedOne implements Model { + public static final QueryField ID = field(\\"RelatedOne\\", \\"id\\"); + public static final QueryField PRIMARY = field(\\"RelatedOne\\", \\"primaryId\\"); + private final @ModelField(targetType=\\"ID\\", isRequired = true) String id; + 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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public Primary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private RelatedOne(String id, Primary primary) { + this.id = id; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + RelatedOne relatedOne = (RelatedOne) obj; + return ObjectsCompat.equals(getId(), relatedOne.getId()) && + ObjectsCompat.equals(getPrimary(), relatedOne.getPrimary()) && + ObjectsCompat.equals(getCreatedAt(), relatedOne.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), relatedOne.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"RelatedOne {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static RelatedOne justId(String id) { + return new RelatedOne( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + primary); + } + public interface BuildStep { + RelatedOne build(); + BuildStep id(String id); + BuildStep primary(Primary primary); + } + + + public static class Builder implements BuildStep { + private String id; + private Primary primary; + public Builder() { + + } + + private Builder(String id, Primary primary) { + this.id = id; + this.primary = primary; + } + + @Override + public RelatedOne build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new RelatedOne( + id, + primary); + } + + @Override + public BuildStep primary(Primary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String id, Primary primary) { + super(id, primary); + + } + + @Override + public CopyOfBuilder primary(Primary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class RelatedOneIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public RelatedOneIdentifier(String id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasOne/belongsTo 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the SqlPrimary type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"SqlPrimaries\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +public final class SqlPrimary implements Model { + public static final QueryField ID = field(\\"SqlPrimary\\", \\"id\\"); + public static final QueryField CONTENT = field(\\"SqlPrimary\\", \\"content\\"); + private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"SqlRelated\\") @HasOne(associatedWith = \\"primaryId\\", type = SqlRelated.class) SqlRelated related = null; + 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. */ + @Deprecated + public Integer resolveIdentifier() { + return id; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } + + public SqlRelated getRelated() { + return related; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private SqlPrimary(Integer id, String content) { + this.id = id; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + SqlPrimary sqlPrimary = (SqlPrimary) obj; + return ObjectsCompat.equals(getId(), sqlPrimary.getId()) && + ObjectsCompat.equals(getContent(), sqlPrimary.getContent()) && + ObjectsCompat.equals(getCreatedAt(), sqlPrimary.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), sqlPrimary.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"SqlPrimary {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static SqlPrimary justId(String id) { + return new SqlPrimary( + id, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content); + } + public interface BuildStep { + SqlPrimary build(); + BuildStep id(String id); + BuildStep content(String content); + } + + + public static class Builder implements BuildStep { + private Integer id; + private String content; + public Builder() { + + } + + private Builder(Integer id, String content) { + this.id = id; + this.content = content; + } + + @Override + public SqlPrimary build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new SqlPrimary( + id, + content); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(Integer id, String content) { + super(id, content); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + + + public static class SqlPrimaryIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public SqlPrimaryIdentifier(Integer id) { + super(id); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references sets the association to the references field for hasOne/belongsTo 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the SqlRelated type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"SqlRelateds\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"id\\"}) +@Index(name = \\"primary_id\\", fields = {\\"primaryId\\"}) +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 = field(\\"SqlRelated\\", \\"primaryId\\"); + private final @ModelField(targetType=\\"Int\\", isRequired = true) Integer id; + private final @ModelField(targetType=\\"String\\") String content; + 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. */ + @Deprecated + public Integer resolveIdentifier() { + return id; + } + + public Integer getId() { + return id; + } + + public String getContent() { + return content; + } + + public SqlPrimary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private SqlRelated(Integer id, String content, SqlPrimary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + SqlRelated sqlRelated = (SqlRelated) obj; + return ObjectsCompat.equals(getId(), sqlRelated.getId()) && + ObjectsCompat.equals(getContent(), sqlRelated.getContent()) && + ObjectsCompat.equals(getPrimary(), sqlRelated.getPrimary()) && + ObjectsCompat.equals(getCreatedAt(), sqlRelated.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), sqlRelated.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"SqlRelated {\\") + .append(\\"id=\\" + String.valueOf(getId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"primary=\\" + String.valueOf(getPrimary()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static BuildStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static SqlRelated justId(String id) { + return new SqlRelated( + id, + null, + null + ); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(id, + content, + primary); + } + public interface BuildStep { + SqlRelated build(); + BuildStep id(String id); + BuildStep content(String content); + BuildStep primary(SqlPrimary primary); + } + + + public static class Builder implements BuildStep { + private Integer id; + private String content; + private SqlPrimary primary; + public Builder() { + + } + + private Builder(Integer id, String content, SqlPrimary primary) { + this.id = id; + this.content = content; + this.primary = primary; + } + + @Override + public SqlRelated build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + return new SqlRelated( + id, + content, + primary); + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + + @Override + public BuildStep primary(SqlPrimary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { + super(id, content, primary); + + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder primary(SqlPrimary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class SqlRelatedIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public SqlRelatedIdentifier(Integer id) { + super(id); + } + } + +} +" +`; + exports[`AppSyncModelVisitor should avoid name collision on builder step 1`] = ` "package com.amplifyframework.datastore.generated.model; 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 0bc3e755e..e997414fc 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 @@ -1290,3 +1290,1338 @@ extension ModelPath where ModelType == task { } }" `; + +exports[`AppSyncSwiftVisitor custom references double linked references 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Foo: Model { + public let id: String + internal var _bar1: LazyReference + public var bar1: Bar? { + get async throws { + try await _bar1.get() + } + } + internal var _bar2: LazyReference + public var bar2: Bar? { + get async throws { + try await _bar2.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + bar1: Bar? = nil, + bar2: Bar? = nil) { + self.init(id: id, + bar1: bar1, + bar2: bar2, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + bar1: Bar? = nil, + bar2: Bar? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._bar1 = LazyReference(bar1) + self._bar2 = LazyReference(bar2) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setBar1(_ bar1: Bar? = nil) { + self._bar1 = LazyReference(bar1) + } + public mutating func setBar2(_ bar2: Bar? = nil) { + self._bar2 = LazyReference(bar2) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _bar1 = try values.decodeIfPresent(LazyReference.self, forKey: .bar1) ?? LazyReference(identifiers: nil) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_bar1, forKey: .bar1) + try container.encode(_bar2, forKey: .bar2) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references double linked references 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Foo { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case bar1 + case bar2 + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let foo = Foo.keys + + model.listPluralName = \\"Foos\\" + model.syncPluralName = \\"Foos\\" + + model.attributes( + .primaryKey(fields: [foo.id]) + ) + + model.fields( + .field(foo.id, is: .required, ofType: .string), + .field(foo.bar1, is: .optional, ofType: .model(Bar.self)), + .field(foo.bar2, is: .optional, ofType: .model(Bar.self)), + .field(foo.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(foo.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Foo: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Foo { + public var id: FieldPath { + string(\\"id\\") + } + public var bar1: ModelPath { + Bar.Path(name: \\"bar1\\", parent: self) + } + public var bar2: ModelPath { + Bar.Path(name: \\"bar2\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references double linked references 3`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Bar: Model { + public let id: String + internal var _foo1: LazyReference + public var foo1: Foo? { + get async throws { + try await _foo1.get() + } + } + internal var _foo2: LazyReference + public var foo2: Foo? { + get async throws { + try await _foo2.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + foo1: Foo? = nil, + foo2: Foo? = nil) { + self.init(id: id, + foo1: foo1, + foo2: foo2, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + foo1: Foo? = nil, + foo2: Foo? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._foo1 = LazyReference(foo1) + self._foo2 = LazyReference(foo2) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setFoo1(_ foo1: Foo? = nil) { + self._foo1 = LazyReference(foo1) + } + public mutating func setFoo2(_ foo2: Foo? = nil) { + self._foo2 = LazyReference(foo2) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _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) + updatedAt = try? values.decode(Temporal.DateTime?.self, forKey: .updatedAt) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_foo1, forKey: .foo1) + try container.encode(_foo2, forKey: .foo2) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references double linked references 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Bar { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case foo1 + case foo2 + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let bar = Bar.keys + + model.listPluralName = \\"Bars\\" + model.syncPluralName = \\"Bars\\" + + model.attributes( + .primaryKey(fields: [bar.id]) + ) + + model.fields( + .field(bar.id, is: .required, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Bar: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Bar { + public var id: FieldPath { + string(\\"id\\") + } + public var foo1: ModelPath { + Foo.Path(name: \\"foo1\\", parent: self) + } + public var foo2: ModelPath { + Foo.Path(name: \\"foo2\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasMany with sortKeyFields on primary key 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Primary: Model { + public let tenantId: String + public let instanceId: String + public let recordId: String + public var content: String? + public var related: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(tenantId: String, + instanceId: String, + recordId: String, + content: String? = nil, + related: List = []) { + self.init(tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content, + related: related, + createdAt: nil, + updatedAt: nil) + } + internal init(tenantId: String, + instanceId: String, + recordId: String, + content: String? = nil, + related: List = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.tenantId = tenantId + self.instanceId = instanceId + self.recordId = recordId + self.content = content + self.related = related + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasMany with sortKeyFields on primary key 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Primary { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case tenantId + case instanceId + case recordId + case content + case related + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let primary = Primary.keys + + model.listPluralName = \\"Primaries\\" + model.syncPluralName = \\"Primaries\\" + + model.attributes( + .index(fields: [\\"tenantId\\", \\"instanceId\\", \\"recordId\\"], name: nil), + .primaryKey(fields: [primary.tenantId, primary.instanceId, primary.recordId]) + ) + + model.fields( + .field(primary.tenantId, is: .required, ofType: .string), + .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.primaryTenantId), + .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Primary: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Custom + public typealias IdentifierProtocol = ModelIdentifier +} + +extension Primary.IdentifierProtocol { + public static func identifier(tenantId: String, + instanceId: String, + recordId: String) -> Self { + .make(fields:[(name: \\"tenantId\\", value: tenantId), (name: \\"instanceId\\", value: instanceId), (name: \\"recordId\\", value: recordId)]) + } +} +extension ModelPath where ModelType == Primary { + public var tenantId: FieldPath { + string(\\"tenantId\\") + } + public var instanceId: FieldPath { + string(\\"instanceId\\") + } + public var recordId: FieldPath { + string(\\"recordId\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var related: ModelPath { + Related.Path(name: \\"related\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasMany with sortKeyFields on primary key 3`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Related: Model { + public let id: String + public var content: String? + internal var _primary: LazyReference + public var primary: Primary? { + get async throws { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil, + primary: Primary? = nil) { + self.init(id: id, + content: content, + primary: primary, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + primary: Primary? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self._primary = LazyReference(primary) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPrimary(_ primary: Primary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + content = try? values.decode(String?.self, forKey: .content) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(content, forKey: .content) + try container.encode(_primary, forKey: .primary) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasMany with sortKeyFields on primary key 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Related { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let related = Related.keys + + model.listPluralName = \\"Relateds\\" + model.syncPluralName = \\"Relateds\\" + + model.attributes( + .primaryKey(fields: [related.id]) + ) + + model.fields( + .field(related.id, is: .required, ofType: .string), + .field(related.content, is: .optional, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Related: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Related { + public var id: FieldPath { + string(\\"id\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var primary: ModelPath { + Primary.Path(name: \\"primary\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct SqlPrimary: Model { + public let id: Int + public var content: String? + public var related: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: Int = UUID().uuidString, + content: String? = nil, + related: List = []) { + self.init(id: id, + content: content, + related: related, + createdAt: nil, + updatedAt: nil) + } + internal init(id: Int = UUID().uuidString, + content: String? = nil, + related: List = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.related = related + self.createdAt = createdAt + self.updatedAt = updatedAt + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasMany/belongsTo 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension SqlPrimary { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case related + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let sqlPrimary = SqlPrimary.keys + + model.listPluralName = \\"SqlPrimaries\\" + model.syncPluralName = \\"SqlPrimaries\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .primaryKey(fields: [sqlPrimary.id]) + ) + + 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.primaryId), + .field(sqlPrimary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(sqlPrimary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension SqlPrimary: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == SqlPrimary { + public var id: FieldPath { + int(\\"id\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var related: ModelPath { + SqlRelated.Path(name: \\"related\\", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasMany/belongsTo 3`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct SqlRelated: Model { + public let id: Int + public var content: String? + internal var _primary: LazyReference + public var primary: SqlPrimary? { + get async throws { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: Int = UUID().uuidString, + content: String? = nil, + primary: SqlPrimary? = nil) { + self.init(id: id, + content: content, + primary: primary, + createdAt: nil, + updatedAt: nil) + } + internal init(id: Int = UUID().uuidString, + content: String? = nil, + primary: SqlPrimary? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self._primary = LazyReference(primary) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPrimary(_ primary: SqlPrimary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(Int.self, forKey: .id) + content = try? values.decode(String?.self, forKey: .content) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(content, forKey: .content) + try container.encode(_primary, forKey: .primary) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasMany/belongsTo 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension SqlRelated { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let sqlRelated = SqlRelated.keys + + model.listPluralName = \\"SqlRelateds\\" + model.syncPluralName = \\"SqlRelateds\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .index(fields: [\\"primaryId\\"], name: \\"primary_id\\"), + .primaryKey(fields: [sqlRelated.id]) + ) + + model.fields( + .field(sqlRelated.id, is: .required, ofType: .int), + .field(sqlRelated.content, is: .optional, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension SqlRelated: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == SqlRelated { + public var id: FieldPath { + int(\\"id\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var primary: ModelPath { + SqlPrimary.Path(name: \\"primary\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Primary: Model { + public let id: String + public var relatedMany: List? + internal var _relatedOne: LazyReference + public var relatedOne: RelatedOne? { + get async throws { + try await _relatedOne.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + relatedMany: List? = [], + relatedOne: RelatedOne? = nil) { + self.init(id: id, + relatedMany: relatedMany, + relatedOne: relatedOne, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + relatedMany: List? = [], + relatedOne: RelatedOne? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.relatedMany = relatedMany + self._relatedOne = LazyReference(relatedOne) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setRelatedOne(_ relatedOne: RelatedOne? = nil) { + self._relatedOne = LazyReference(relatedOne) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + relatedMany = try values.decodeIfPresent(List?.self, forKey: .relatedMany) ?? .init() + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(relatedMany, forKey: .relatedMany) + try container.encode(_relatedOne, forKey: .relatedOne) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Primary { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case relatedMany + case relatedOne + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let primary = Primary.keys + + model.listPluralName = \\"Primaries\\" + model.syncPluralName = \\"Primaries\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .primaryKey(fields: [primary.id]) + ) + + model.fields( + .field(primary.id, is: .required, ofType: .string), + .hasMany(primary.relatedMany, is: .optional, ofType: RelatedMany.self, associatedWith: RelatedMany.keys.primaryId), + .field(primary.relatedOne, is: .optional, ofType: .model(RelatedOne.self)), + .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Primary: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Primary { + public var id: FieldPath { + string(\\"id\\") + } + public var relatedMany: ModelPath { + RelatedMany.Path(name: \\"relatedMany\\", isCollection: true, parent: self) + } + public var relatedOne: ModelPath { + RelatedOne.Path(name: \\"relatedOne\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 3`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct RelatedMany: Model { + public let id: String + internal var _primary: LazyReference + public var primary: Primary? { + get async throws { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + primary: Primary? = nil) { + self.init(id: id, + primary: primary, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + primary: Primary? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._primary = LazyReference(primary) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPrimary(_ primary: Primary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_primary, forKey: .primary) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension RelatedMany { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let relatedMany = RelatedMany.keys + + model.listPluralName = \\"RelatedManies\\" + model.syncPluralName = \\"RelatedManies\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .primaryKey(fields: [relatedMany.id]) + ) + + model.fields( + .field(relatedMany.id, is: .required, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension RelatedMany: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == RelatedMany { + public var id: FieldPath { + string(\\"id\\") + } + public var primary: ModelPath { + Primary.Path(name: \\"primary\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 5`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct RelatedOne: Model { + public let id: String + internal var _primary: LazyReference + public var primary: Primary? { + get async throws { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + primary: Primary? = nil) { + self.init(id: id, + primary: primary, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + primary: Primary? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self._primary = LazyReference(primary) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPrimary(_ primary: Primary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(_primary, forKey: .primary) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne and hasMany 6`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension RelatedOne { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let relatedOne = RelatedOne.keys + + model.listPluralName = \\"RelatedOnes\\" + model.syncPluralName = \\"RelatedOnes\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .primaryKey(fields: [relatedOne.id]) + ) + + model.fields( + .field(relatedOne.id, is: .required, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension RelatedOne: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == RelatedOne { + public var id: FieldPath { + string(\\"id\\") + } + public var primary: ModelPath { + Primary.Path(name: \\"primary\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne/belongsTo 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct SqlPrimary: Model { + public let id: Int + public var content: String? + internal var _related: LazyReference + public var related: SqlRelated? { + get async throws { + try await _related.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: Int = UUID().uuidString, + content: String? = nil, + related: SqlRelated? = nil) { + self.init(id: id, + content: content, + related: related, + createdAt: nil, + updatedAt: nil) + } + internal init(id: Int = UUID().uuidString, + content: String? = nil, + related: SqlRelated? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self._related = LazyReference(related) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setRelated(_ related: SqlRelated? = nil) { + self._related = LazyReference(related) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(Int.self, forKey: .id) + content = try? values.decode(String?.self, forKey: .content) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(content, forKey: .content) + try container.encode(_related, forKey: .related) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne/belongsTo 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension SqlPrimary { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case related + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let sqlPrimary = SqlPrimary.keys + + model.listPluralName = \\"SqlPrimaries\\" + model.syncPluralName = \\"SqlPrimaries\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .primaryKey(fields: [sqlPrimary.id]) + ) + + model.fields( + .field(sqlPrimary.id, is: .required, ofType: .int), + .field(sqlPrimary.content, is: .optional, ofType: .string), + .field(sqlPrimary.related, is: .optional, ofType: .model(SqlRelated.self)), + .field(sqlPrimary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(sqlPrimary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension SqlPrimary: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == SqlPrimary { + public var id: FieldPath { + int(\\"id\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var related: ModelPath { + SqlRelated.Path(name: \\"related\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne/belongsTo 3`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct SqlRelated: Model { + public let id: Int + public var content: String? + internal var _primary: LazyReference + public var primary: SqlPrimary? { + get async throws { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: Int = UUID().uuidString, + content: String? = nil, + primary: SqlPrimary? = nil) { + self.init(id: id, + content: content, + primary: primary, + createdAt: nil, + updatedAt: nil) + } + internal init(id: Int = UUID().uuidString, + content: String? = nil, + primary: SqlPrimary? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self._primary = LazyReference(primary) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setPrimary(_ primary: SqlPrimary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(Int.self, forKey: .id) + content = try? values.decode(String?.self, forKey: .content) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(id, forKey: .id) + try container.encode(content, forKey: .content) + try container.encode(_primary, forKey: .primary) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasOne/belongsTo 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension SqlRelated { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let sqlRelated = SqlRelated.keys + + model.listPluralName = \\"SqlRelateds\\" + model.syncPluralName = \\"SqlRelateds\\" + + model.attributes( + .index(fields: [\\"id\\"], name: nil), + .index(fields: [\\"primaryId\\"], name: \\"primary_id\\"), + .primaryKey(fields: [sqlRelated.id]) + ) + + model.fields( + .field(sqlRelated.id, is: .required, ofType: .int), + .field(sqlRelated.content, is: .optional, ofType: .string), + .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) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension SqlRelated: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == SqlRelated { + public var id: FieldPath { + int(\\"id\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var primary: ModelPath { + SqlPrimary.Path(name: \\"primary\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts index b51eefd58..96ef18d2d 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts @@ -796,4 +796,154 @@ describe('AppSync Dart Visitor', () => { }) }) }); + + describe('custom references', () => { + test('sets the association to the references field for hasMany/belongsTo', () => { + 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(references: ["primaryId"]) + } + `; + + ['SqlPrimary', 'SqlRelated'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); + + test('sets the association to the references field for hasOne/belongsTo', () => { + const schema = /* GraphQL */ ` + type SqlPrimary @refersTo(name: "sql_primary") @model { + id: Int! @primaryKey + content: String + related: SqlRelated @hasOne(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(references: ["primaryId"]) + } + `; + + ['SqlPrimary', 'SqlRelated'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); + + test('sets the association to the references field for hasOne and hasMany', () => { + const schema = /* GraphQL */ ` + type Primary @model { + id: ID! @primaryKey + relatedMany: [RelatedMany] @hasMany(references: ["primaryId"]) + relatedOne: RelatedOne @hasOne(references: ["primaryId"]) + } + + type RelatedMany @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + + type RelatedOne @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + `; + ['Primary', 'RelatedOne', 'RelatedMany'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); + + test('double linked references', () => { + const schema = /* GraphQL */ ` + type Foo @model { + id: ID! + bar1: Bar @hasOne(references: ["bar1Id"]) + bar2: Bar @hasOne(references: ["bar2Id"]) + } + + type Bar @model { + id: ID! + bar1Id: ID + bar2Id: ID + foo1: Foo @belongsTo(references: ["bar1Id"]) + foo2: Foo @belongsTo(references: ["bar2Id"]) + } + `; + + ['Foo', 'Bar'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); + + test('hasMany with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: [Related!] @hasMany(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + + ['Primary', 'Related'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); + }); }); diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts index 39a9b839b..1b5bf455a 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts @@ -781,4 +781,134 @@ describe('AppSyncModelVisitor', () => { expect(generatedCodeIntModel).toMatchSnapshot(); }); }); + + describe('custom references', () => { + test('sets the association to the references field for hasMany/belongsTo', () => { + 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(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('sets the association to the references field for hasOne/belongsTo', () => { + const schema = /* GraphQL */ ` + type SqlPrimary @refersTo(name: "sql_primary") @model { + id: Int! @primaryKey + content: String + related: SqlRelated @hasOne(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(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('sets the association to the references field for hasOne and hasMany', () => { + const schema = /* GraphQL */ ` + type Primary @model { + id: ID! @primaryKey + relatedMany: [RelatedMany] @hasMany(references: ["primaryId"]) + relatedOne: RelatedOne @hasOne(references: ["primaryId"]) + } + + type RelatedMany @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + + type RelatedOne @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'Primary', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedMany', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedOne', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('double linked references', () => { + const schema = /* GraphQL */ ` + type Foo @model { + id: ID! + bar1: Bar @hasOne(references: ["bar1Id"]) + bar2: Bar @hasOne(references: ["bar2Id"]) + } + + type Bar @model { + id: ID! + bar1Id: ID + bar2Id: ID + foo1: Foo @belongsTo(references: ["bar1Id"]) + foo2: Foo @belongsTo(references: ["bar2Id"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'Foo', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Bar', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('hasMany with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: [Related!] @hasMany(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + + expect(getVisitorPipelinedTransformer(schema, 'Primary', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + }); }); diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts index a59eccfbf..3bb624acb 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts @@ -2976,4 +2976,167 @@ describe('AppSyncSwiftVisitor', () => { expect(generatedMetaComment).toMatchSnapshot(); }); }); + + describe('custom references', () => { + test('sets the association to the references field for hasMany/belongsTo', () => { + 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(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('sets the association to the references field for hasOne/belongsTo', () => { + const schema = /* GraphQL */ ` + type SqlPrimary @refersTo(name: "sql_primary") @model { + id: Int! @primaryKey + content: String + related: SqlRelated @hasOne(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(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlPrimary', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'SqlRelated', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('sets the association to the references field for hasOne and hasMany', () => { + const schema = /* GraphQL */ ` + type Primary @model { + id: ID! @primaryKey + relatedMany: [RelatedMany] @hasMany(references: ["primaryId"]) + relatedOne: RelatedOne @hasOne(references: ["primaryId"]) + } + + type RelatedMany @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + + type RelatedOne @model { + id: ID! @primaryKey + primaryId: ID! + primary: Primary @belongsTo(references: ["primaryId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedMany', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedMany', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedOne', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'RelatedOne', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('double linked references', () => { + const schema = /* GraphQL */ ` + type Foo @model { + id: ID! + bar1: Bar @hasOne(references: ["bar1Id"]) + bar2: Bar @hasOne(references: ["bar2Id"]) + } + + type Bar @model { + id: ID! + bar1Id: ID + bar2Id: ID + foo1: Foo @belongsTo(references: ["bar1Id"]) + foo2: Foo @belongsTo(references: ["bar2Id"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'Foo', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Foo', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Bar', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Bar', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + + test('hasMany with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: [Related!] @hasMany(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); + }); }); From 0ace7d86223af716441fdf8da2f9a0aeada922be Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Fri, 19 Apr 2024 09:41:40 -0600 Subject: [PATCH 2/3] fix: do not remove belongsTo target names when using references --- .../appsync-dart-visitor.test.ts.snap | 291 ++++++++++++-- .../appsync-java-visitor.test.ts.snap | 358 ++++++++++++++++-- .../appsync-swift-visitor.test.ts.snap | 108 ++++++ .../src/visitors/appsync-visitor.ts | 3 +- 4 files changed, 696 insertions(+), 64 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 ed4eda111..91d7eb2b5 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 @@ -11873,6 +11873,8 @@ 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; @@ -11891,6 +11893,14 @@ class Bar extends amplify_core.Model { ); } + String? get bar1Id { + return _bar1Id; + } + + String? get bar2Id { + return _bar2Id; + } + Foo? get foo1 { return _foo1; } @@ -11907,11 +11917,13 @@ class Bar extends amplify_core.Model { return _updatedAt; } - const Bar._internal({required this.id, foo1, foo2, createdAt, updatedAt}): _foo1 = foo1, _foo2 = foo2, _createdAt = createdAt, _updatedAt = 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; - factory Bar({String? id, Foo? foo1, Foo? foo2}) { + factory Bar({String? id, String? bar1Id, String? bar2Id, Foo? foo1, Foo? foo2}) { return Bar._internal( id: id == null ? amplify_core.UUID.getUUID() : id, + bar1Id: bar1Id, + bar2Id: bar2Id, foo1: foo1, foo2: foo2); } @@ -11925,6 +11937,8 @@ 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; } @@ -11938,6 +11952,8 @@ 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\\") + \\", \\"); @@ -11947,19 +11963,25 @@ class Bar extends amplify_core.Model { return buffer.toString(); } - Bar copyWith({Foo? foo1, Foo? foo2}) { + Bar copyWith({String? bar1Id, String? bar2Id, 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 ); @@ -11967,6 +11989,8 @@ class Bar extends amplify_core.Model { Bar.fromJson(Map json) : id = json['id'], + _bar1Id = json['bar1Id'], + _bar2Id = json['bar2Id'], _foo1 = json['foo1']?['serializedData'] != null ? Foo.fromJson(new Map.from(json['foo1']['serializedData'])) : null, @@ -11977,11 +12001,13 @@ class Bar extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'foo1': _foo1?.toJson(), 'foo2': _foo2?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'bar1Id': _bar1Id, 'bar2Id': _bar2Id, '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, @@ -11990,6 +12016,8 @@ 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')); @@ -12002,6 +12030,18 @@ 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, @@ -12467,6 +12507,9 @@ 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; @@ -12488,6 +12531,45 @@ 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; } @@ -12500,12 +12582,15 @@ class Related extends amplify_core.Model { return _updatedAt; } - const Related._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = 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; - factory Related({String? id, String? content, Primary? primary}) { + factory Related({String? id, String? content, required String primaryTenantId, required String primaryInstanceId, required String primaryRecordId, Primary? primary}) { return Related._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, + primaryTenantId: primaryTenantId, + primaryInstanceId: primaryInstanceId, + primaryRecordId: primaryRecordId, primary: primary); } @@ -12519,6 +12604,9 @@ 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; } @@ -12532,6 +12620,9 @@ 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\\")); @@ -12540,20 +12631,29 @@ class Related extends amplify_core.Model { return buffer.toString(); } - Related copyWith({String? content, Primary? primary}) { + Related copyWith({String? content, String? primaryTenantId, String? primaryInstanceId, String? primaryRecordId, 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 ); } @@ -12561,6 +12661,9 @@ 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']?['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) : null, @@ -12568,12 +12671,15 @@ class Related extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primaryTenantId': _primaryTenantId, 'primaryInstanceId': _primaryInstanceId, 'primaryRecordId': _primaryRecordId, '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 @@ -12582,6 +12688,9 @@ 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')); @@ -12597,6 +12706,24 @@ 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, @@ -12958,6 +13085,7 @@ 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; @@ -12979,6 +13107,19 @@ 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; } @@ -12991,12 +13132,13 @@ class SqlRelated extends amplify_core.Model { return _updatedAt; } - const SqlRelated._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const SqlRelated._internal({required this.id, content, required primaryId, primary, createdAt, updatedAt}): _content = content, _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory SqlRelated({int? id, String? content, SqlPrimary? primary}) { + factory SqlRelated({int? id, String? content, required int primaryId, SqlPrimary? primary}) { return SqlRelated._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, + primaryId: primaryId, primary: primary); } @@ -13010,6 +13152,7 @@ class SqlRelated extends amplify_core.Model { return other is SqlRelated && id == other.id && _content == other._content && + _primaryId == other._primaryId && _primary == other._primary; } @@ -13023,6 +13166,7 @@ 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\\")); @@ -13031,20 +13175,23 @@ class SqlRelated extends amplify_core.Model { return buffer.toString(); } - SqlRelated copyWith({String? content, SqlPrimary? primary}) { + SqlRelated copyWith({String? content, int? primaryId, 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 ); } @@ -13052,6 +13199,7 @@ 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']?['serializedData'] != null ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) : null, @@ -13059,12 +13207,13 @@ class SqlRelated extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, + 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -13073,6 +13222,7 @@ 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')); @@ -13093,6 +13243,12 @@ 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, @@ -13457,6 +13613,7 @@ 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; @@ -13474,6 +13631,19 @@ 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; } @@ -13486,11 +13656,12 @@ class RelatedOne extends amplify_core.Model { return _updatedAt; } - const RelatedOne._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const RelatedOne._internal({required this.id, required primaryId, primary, createdAt, updatedAt}): _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory RelatedOne({String? id, Primary? primary}) { + factory RelatedOne({String? id, required String primaryId, Primary? primary}) { return RelatedOne._internal( id: id == null ? amplify_core.UUID.getUUID() : id, + primaryId: primaryId, primary: primary); } @@ -13503,6 +13674,7 @@ 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; } @@ -13515,6 +13687,7 @@ 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\\")); @@ -13523,23 +13696,27 @@ class RelatedOne extends amplify_core.Model { return buffer.toString(); } - RelatedOne copyWith({Primary? primary}) { + RelatedOne copyWith({String? primaryId, 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']?['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) : null, @@ -13547,11 +13724,12 @@ class RelatedOne extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, + 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -13559,6 +13737,7 @@ 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')); @@ -13572,6 +13751,12 @@ 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, @@ -13683,6 +13868,7 @@ 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; @@ -13700,6 +13886,19 @@ 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; } @@ -13712,11 +13911,12 @@ class RelatedMany extends amplify_core.Model { return _updatedAt; } - const RelatedMany._internal({required this.id, primary, createdAt, updatedAt}): _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const RelatedMany._internal({required this.id, required primaryId, primary, createdAt, updatedAt}): _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory RelatedMany({String? id, Primary? primary}) { + factory RelatedMany({String? id, required String primaryId, Primary? primary}) { return RelatedMany._internal( id: id == null ? amplify_core.UUID.getUUID() : id, + primaryId: primaryId, primary: primary); } @@ -13729,6 +13929,7 @@ 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; } @@ -13741,6 +13942,7 @@ 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\\")); @@ -13749,23 +13951,27 @@ class RelatedMany extends amplify_core.Model { return buffer.toString(); } - RelatedMany copyWith({Primary? primary}) { + RelatedMany copyWith({String? primaryId, 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']?['serializedData'] != null ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) : null, @@ -13773,11 +13979,12 @@ class RelatedMany extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, + 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -13785,6 +13992,7 @@ 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')); @@ -13798,6 +14006,12 @@ 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, @@ -14155,6 +14369,7 @@ 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; @@ -14176,6 +14391,19 @@ 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; } @@ -14188,12 +14416,13 @@ class SqlRelated extends amplify_core.Model { return _updatedAt; } - const SqlRelated._internal({required this.id, content, primary, createdAt, updatedAt}): _content = content, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; + const SqlRelated._internal({required this.id, content, required primaryId, primary, createdAt, updatedAt}): _content = content, _primaryId = primaryId, _primary = primary, _createdAt = createdAt, _updatedAt = updatedAt; - factory SqlRelated({int? id, String? content, SqlPrimary? primary}) { + factory SqlRelated({int? id, String? content, required int primaryId, SqlPrimary? primary}) { return SqlRelated._internal( id: id == null ? amplify_core.UUID.getUUID() : id, content: content, + primaryId: primaryId, primary: primary); } @@ -14207,6 +14436,7 @@ class SqlRelated extends amplify_core.Model { return other is SqlRelated && id == other.id && _content == other._content && + _primaryId == other._primaryId && _primary == other._primary; } @@ -14220,6 +14450,7 @@ 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\\")); @@ -14228,20 +14459,23 @@ class SqlRelated extends amplify_core.Model { return buffer.toString(); } - SqlRelated copyWith({String? content, SqlPrimary? primary}) { + SqlRelated copyWith({String? content, int? primaryId, 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 ); } @@ -14249,6 +14483,7 @@ 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']?['serializedData'] != null ? SqlPrimary.fromJson(new Map.from(json['primary']['serializedData'])) : null, @@ -14256,12 +14491,13 @@ class SqlRelated extends amplify_core.Model { _updatedAt = json['updatedAt'] != null ? amplify_core.TemporalDateTime.fromString(json['updatedAt']) : null; Map toJson() => { - 'id': id, 'content': _content, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() + 'id': id, 'content': _content, 'primaryId': _primaryId, 'primary': _primary?.toJson(), 'createdAt': _createdAt?.format(), 'updatedAt': _updatedAt?.format() }; Map toMap() => { 'id': id, 'content': _content, + 'primaryId': _primaryId, 'primary': _primary, 'createdAt': _createdAt, 'updatedAt': _updatedAt @@ -14270,6 +14506,7 @@ 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')); @@ -14290,6 +14527,12 @@ 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, 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 2ad2640f4..44cb1f4de 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 @@ -8042,9 +8042,13 @@ 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\\", \\"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 = \\"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; @@ -8059,6 +8063,14 @@ public final class Bar implements Model { return id; } + public String getBar1Id() { + return bar1Id; + } + + public String getBar2Id() { + return bar2Id; + } + public Foo getFoo1() { return foo1; } @@ -8075,8 +8087,10 @@ public final class Bar implements Model { return updatedAt; } - private Bar(String id, Foo foo1, Foo foo2) { + private Bar(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { this.id = id; + this.bar1Id = bar1Id; + this.bar2Id = bar2Id; this.foo1 = foo1; this.foo2 = foo2; } @@ -8090,6 +8104,8 @@ 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()) && @@ -8101,6 +8117,8 @@ public final class Bar implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getBar1Id()) + .append(getBar2Id()) .append(getFoo1()) .append(getFoo2()) .append(getCreatedAt()) @@ -8114,6 +8132,8 @@ 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()) + \\", \\") @@ -8138,18 +8158,24 @@ 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); } @@ -8157,14 +8183,18 @@ 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, Foo foo1, Foo foo2) { + private Builder(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { this.id = id; + this.bar1Id = bar1Id; + this.bar2Id = bar2Id; this.foo1 = foo1; this.foo2 = foo2; } @@ -8175,10 +8205,24 @@ 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; @@ -8203,11 +8247,21 @@ public final class Bar implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, Foo foo1, Foo foo2) { - super(id, foo1, foo2); + private CopyOfBuilder(String id, String bar1Id, String bar2Id, Foo foo1, Foo foo2) { + super(id, bar1Id, bar2Id, 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); @@ -8511,9 +8565,15 @@ 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\\", \\"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 = \\"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; @@ -8531,6 +8591,18 @@ 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; } @@ -8543,9 +8615,12 @@ public final class Related implements Model { return updatedAt; } - private Related(String id, String content, Primary primary) { + private Related(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { this.id = id; this.content = content; + this.primaryTenantId = primaryTenantId; + this.primaryInstanceId = primaryInstanceId; + this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -8559,6 +8634,9 @@ 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()); @@ -8570,6 +8648,9 @@ 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()) @@ -8583,6 +8664,9 @@ 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())) @@ -8590,7 +8674,7 @@ public final class Related implements Model { .toString(); } - public static BuildStep builder() { + public static PrimaryTenantIdStep builder() { return new Builder(); } @@ -8606,6 +8690,9 @@ public final class Related implements Model { return new Related( id, null, + null, + null, + null, null ); } @@ -8613,8 +8700,26 @@ 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); @@ -8623,17 +8728,23 @@ public final class Related implements Model { } - public static class Builder implements BuildStep { + public static class Builder implements PrimaryTenantIdStep, PrimaryInstanceIdStep, PrimaryRecordIdStep, 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, Primary primary) { + private Builder(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { this.id = id; this.content = content; + this.primaryTenantId = primaryTenantId; + this.primaryInstanceId = primaryInstanceId; + this.primaryRecordId = primaryRecordId; this.primary = primary; } @@ -8644,9 +8755,33 @@ 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; @@ -8671,9 +8806,26 @@ public final class Related implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, String content, Primary primary) { - super(id, content, primary); - + 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); } @Override @@ -8922,9 +9074,11 @@ 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\\", \\"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 = \\"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; @@ -8942,6 +9096,10 @@ public final class SqlRelated implements Model { return content; } + public Integer getPrimaryId() { + return primaryId; + } + public SqlPrimary getPrimary() { return primary; } @@ -8954,9 +9112,10 @@ public final class SqlRelated implements Model { return updatedAt; } - private SqlRelated(Integer id, String content, SqlPrimary primary) { + private SqlRelated(Integer id, String content, Integer primaryId, SqlPrimary primary) { this.id = id; this.content = content; + this.primaryId = primaryId; this.primary = primary; } @@ -8970,6 +9129,7 @@ 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()); @@ -8981,6 +9141,7 @@ public final class SqlRelated implements Model { return new StringBuilder() .append(getId()) .append(getContent()) + .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -8994,6 +9155,7 @@ 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())) @@ -9001,7 +9163,7 @@ public final class SqlRelated implements Model { .toString(); } - public static BuildStep builder() { + public static PrimaryIdStep builder() { return new Builder(); } @@ -9017,6 +9179,7 @@ public final class SqlRelated implements Model { return new SqlRelated( id, null, + null, null ); } @@ -9024,8 +9187,14 @@ 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); @@ -9034,17 +9203,19 @@ public final class SqlRelated implements Model { } - public static class Builder implements BuildStep { + public static class Builder implements PrimaryIdStep, BuildStep { private Integer id; + private Integer primaryId; private String content; private SqlPrimary primary; public Builder() { } - private Builder(Integer id, String content, SqlPrimary primary) { + private Builder(Integer id, String content, Integer primaryId, SqlPrimary primary) { this.id = id; this.content = content; + this.primaryId = primaryId; this.primary = primary; } @@ -9055,9 +9226,17 @@ 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; @@ -9082,9 +9261,14 @@ public final class SqlRelated implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { - super(id, content, primary); - + 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); } @Override @@ -9310,8 +9494,10 @@ 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\\", \\"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 = \\"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; @@ -9325,6 +9511,10 @@ public final class RelatedMany implements Model { return id; } + public String getPrimaryId() { + return primaryId; + } + public Primary getPrimary() { return primary; } @@ -9337,8 +9527,9 @@ public final class RelatedMany implements Model { return updatedAt; } - private RelatedMany(String id, Primary primary) { + private RelatedMany(String id, String primaryId, Primary primary) { this.id = id; + this.primaryId = primaryId; this.primary = primary; } @@ -9351,6 +9542,7 @@ 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()); @@ -9361,6 +9553,7 @@ public final class RelatedMany implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -9373,6 +9566,7 @@ 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())) @@ -9380,7 +9574,7 @@ public final class RelatedMany implements Model { .toString(); } - public static BuildStep builder() { + public static PrimaryIdStep builder() { return new Builder(); } @@ -9395,14 +9589,21 @@ 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); @@ -9410,15 +9611,17 @@ public final class RelatedMany implements Model { } - public static class Builder implements BuildStep { + public static class Builder implements PrimaryIdStep, BuildStep { private String id; + private String primaryId; private Primary primary; public Builder() { } - private Builder(String id, Primary primary) { + private Builder(String id, String primaryId, Primary primary) { this.id = id; + this.primaryId = primaryId; this.primary = primary; } @@ -9428,9 +9631,17 @@ 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; @@ -9449,9 +9660,14 @@ public final class RelatedMany implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, Primary primary) { - super(id, primary); - + 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); } @Override @@ -9499,8 +9715,10 @@ 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\\", \\"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 = \\"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; @@ -9514,6 +9732,10 @@ public final class RelatedOne implements Model { return id; } + public String getPrimaryId() { + return primaryId; + } + public Primary getPrimary() { return primary; } @@ -9526,8 +9748,9 @@ public final class RelatedOne implements Model { return updatedAt; } - private RelatedOne(String id, Primary primary) { + private RelatedOne(String id, String primaryId, Primary primary) { this.id = id; + this.primaryId = primaryId; this.primary = primary; } @@ -9540,6 +9763,7 @@ 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()); @@ -9550,6 +9774,7 @@ public final class RelatedOne implements Model { public int hashCode() { return new StringBuilder() .append(getId()) + .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -9562,6 +9787,7 @@ 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())) @@ -9569,7 +9795,7 @@ public final class RelatedOne implements Model { .toString(); } - public static BuildStep builder() { + public static PrimaryIdStep builder() { return new Builder(); } @@ -9584,14 +9810,21 @@ 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); @@ -9599,15 +9832,17 @@ public final class RelatedOne implements Model { } - public static class Builder implements BuildStep { + public static class Builder implements PrimaryIdStep, BuildStep { private String id; + private String primaryId; private Primary primary; public Builder() { } - private Builder(String id, Primary primary) { + private Builder(String id, String primaryId, Primary primary) { this.id = id; + this.primaryId = primaryId; this.primary = primary; } @@ -9617,9 +9852,17 @@ 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; @@ -9638,9 +9881,14 @@ public final class RelatedOne implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(String id, Primary primary) { - super(id, primary); - + 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); } @Override @@ -9884,9 +10132,11 @@ 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\\", \\"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 = \\"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; @@ -9904,6 +10154,10 @@ public final class SqlRelated implements Model { return content; } + public Integer getPrimaryId() { + return primaryId; + } + public SqlPrimary getPrimary() { return primary; } @@ -9916,9 +10170,10 @@ public final class SqlRelated implements Model { return updatedAt; } - private SqlRelated(Integer id, String content, SqlPrimary primary) { + private SqlRelated(Integer id, String content, Integer primaryId, SqlPrimary primary) { this.id = id; this.content = content; + this.primaryId = primaryId; this.primary = primary; } @@ -9932,6 +10187,7 @@ 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()); @@ -9943,6 +10199,7 @@ public final class SqlRelated implements Model { return new StringBuilder() .append(getId()) .append(getContent()) + .append(getPrimaryId()) .append(getPrimary()) .append(getCreatedAt()) .append(getUpdatedAt()) @@ -9956,6 +10213,7 @@ 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())) @@ -9963,7 +10221,7 @@ public final class SqlRelated implements Model { .toString(); } - public static BuildStep builder() { + public static PrimaryIdStep builder() { return new Builder(); } @@ -9979,6 +10237,7 @@ public final class SqlRelated implements Model { return new SqlRelated( id, null, + null, null ); } @@ -9986,8 +10245,14 @@ 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); @@ -9996,17 +10261,19 @@ public final class SqlRelated implements Model { } - public static class Builder implements BuildStep { + public static class Builder implements PrimaryIdStep, BuildStep { private Integer id; + private Integer primaryId; private String content; private SqlPrimary primary; public Builder() { } - private Builder(Integer id, String content, SqlPrimary primary) { + private Builder(Integer id, String content, Integer primaryId, SqlPrimary primary) { this.id = id; this.content = content; + this.primaryId = primaryId; this.primary = primary; } @@ -10017,9 +10284,17 @@ 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; @@ -10044,9 +10319,14 @@ public final class SqlRelated implements Model { public final class CopyOfBuilder extends Builder { - private CopyOfBuilder(Integer id, String content, SqlPrimary primary) { - super(id, content, primary); - + 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); } @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 e997414fc..63f68fa96 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 @@ -1429,6 +1429,8 @@ 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 { @@ -1445,20 +1447,28 @@ 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 @@ -1473,6 +1483,8 @@ 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) @@ -1481,6 +1493,8 @@ 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) @@ -1498,6 +1512,8 @@ extension Bar { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id + case bar1Id + case bar2Id case foo1 case foo2 case createdAt @@ -1519,6 +1535,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: [\\"bar1Id\\"]), .belongsTo(bar.foo2, is: .optional, ofType: Foo.self, targetNames: [\\"bar2Id\\"]), .field(bar.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), @@ -1538,6 +1556,12 @@ 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) } @@ -1689,6 +1713,9 @@ 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 { @@ -1700,20 +1727,32 @@ 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 @@ -1725,6 +1764,9 @@ 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) @@ -1733,6 +1775,9 @@ 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) @@ -1750,6 +1795,9 @@ extension Related { public enum CodingKeys: String, ModelKey { case id case content + case primaryTenantId + case primaryInstanceId + case primaryRecordId case primary case createdAt case updatedAt @@ -1771,6 +1819,9 @@ 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: [\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"]), .field(related.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(related.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) @@ -1792,6 +1843,15 @@ 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) } @@ -1912,6 +1972,7 @@ 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 { @@ -1923,20 +1984,24 @@ 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 @@ -1948,6 +2013,7 @@ 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) @@ -1956,6 +2022,7 @@ 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) @@ -1973,6 +2040,7 @@ extension SqlRelated { public enum CodingKeys: String, ModelKey { case id case content + case primaryId case primary case createdAt case updatedAt @@ -1996,6 +2064,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: [\\"primaryId\\"]), .field(sqlRelated.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(sqlRelated.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) @@ -2017,6 +2086,9 @@ 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) } @@ -2160,6 +2232,7 @@ 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 { @@ -2170,17 +2243,21 @@ 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 @@ -2191,6 +2268,7 @@ 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) @@ -2198,6 +2276,7 @@ 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) @@ -2214,6 +2293,7 @@ extension RelatedMany { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id + case primaryId case primary case createdAt case updatedAt @@ -2235,6 +2315,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: [\\"primaryId\\"]), .field(relatedMany.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(relatedMany.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) @@ -2253,6 +2334,9 @@ 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) } @@ -2272,6 +2356,7 @@ 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 { @@ -2282,17 +2367,21 @@ 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 @@ -2303,6 +2392,7 @@ 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) @@ -2310,6 +2400,7 @@ 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) @@ -2326,6 +2417,7 @@ extension RelatedOne { // MARK: - CodingKeys public enum CodingKeys: String, ModelKey { case id + case primaryId case primary case createdAt case updatedAt @@ -2347,6 +2439,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: [\\"primaryId\\"]), .field(relatedOne.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(relatedOne.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) @@ -2365,6 +2458,9 @@ 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) } @@ -2509,6 +2605,7 @@ 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 { @@ -2520,20 +2617,24 @@ 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 @@ -2545,6 +2646,7 @@ 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) @@ -2553,6 +2655,7 @@ 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) @@ -2570,6 +2673,7 @@ extension SqlRelated { public enum CodingKeys: String, ModelKey { case id case content + case primaryId case primary case createdAt case updatedAt @@ -2593,6 +2697,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: [\\"primaryId\\"]), .field(sqlRelated.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), .field(sqlRelated.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) @@ -2614,6 +2719,9 @@ 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/visitors/appsync-visitor.ts b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts index cb2cea965..3d0f626ca 100644 --- a/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts +++ b/packages/appsync-modelgen-plugin/src/visitors/appsync-visitor.ts @@ -1181,7 +1181,8 @@ export class AppSyncModelVisitor< connectionInfo.kind !== CodeGenConnectionType.HAS_MANY && connectionInfo.kind !== CodeGenConnectionType.HAS_ONE && connectionInfo.targetNames && - connectionInfo.targetName !== 'id' + connectionInfo.targetName !== 'id' && + !connectionInfo.isUsingReferences ) { // Need to remove the field that is targetName connectionInfo.targetNames.forEach(targetName => removeFieldFromModel(model, targetName)); From e6d780ca42f6d8a1ee0084fce02d56cc7126be46 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Fri, 19 Apr 2024 10:40:48 -0600 Subject: [PATCH 3/3] test: add case for hasOne with sort key fields --- .../appsync-dart-visitor.test.ts.snap | 671 ++++++++++++++++++ .../appsync-java-visitor.test.ts.snap | 566 +++++++++++++++ ...c-model-introspection-visitor.test.ts.snap | 189 +++++ .../appsync-swift-visitor.test.ts.snap | 315 ++++++++ .../visitors/appsync-dart-visitor.test.ts | 30 + .../visitors/appsync-java-visitor.test.ts | 26 + ...ppsync-model-introspection-visitor.test.ts | 22 + .../visitors/appsync-swift-visitor.test.ts | 33 + 8 files changed, 1852 insertions(+) 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 91d7eb2b5..542a3a4b8 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 @@ -12805,6 +12805,677 @@ class RelatedModelIdentifier implements amplify_core.ModelIdentifier { }" `; +exports[`AppSync Dart Visitor custom references hasOne with sortKeyFields on primary key 1`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Primary type in your schema. */ +class Primary extends amplify_core.Model { + static const classType = const _PrimaryModelType(); + final String? _tenantId; + final String? _instanceId; + final String? _recordId; + final String? _content; + final Related? _related; + final amplify_core.TemporalDateTime? _createdAt; + final amplify_core.TemporalDateTime? _updatedAt; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => modelIdentifier.serializeAsString(); + + PrimaryModelIdentifier get modelIdentifier { + try { + return PrimaryModelIdentifier( + tenantId: _tenantId!, + instanceId: _instanceId!, + recordId: _recordId! + ); + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get tenantId { + try { + return _tenantId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get instanceId { + try { + return _instanceId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String get recordId { + try { + return _recordId!; + } catch(e) { + throw amplify_core.AmplifyCodeGenModelException( + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastExceptionMessage, + recoverySuggestion: + amplify_core.AmplifyExceptionMessages.codeGenRequiredFieldForceCastRecoverySuggestion, + underlyingException: e.toString() + ); + } + } + + String? get content { + return _content; + } + + Related? get related { + return _related; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + return _updatedAt; + } + + 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}) { + return Primary._internal( + tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content, + related: related); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Primary && + _tenantId == other._tenantId && + _instanceId == other._instanceId && + _recordId == other._recordId && + _content == other._content && + _related == other._related; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + buffer.write(\\"Primary {\\"); + buffer.write(\\"tenantId=\\" + \\"$_tenantId\\" + \\", \\"); + buffer.write(\\"instanceId=\\" + \\"$_instanceId\\" + \\", \\"); + 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(\\"}\\"); + + return buffer.toString(); + } + + Primary copyWith({String? content, Related? related}) { + return Primary._internal( + tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content ?? this.content, + related: related ?? this.related); + } + + Primary copyWithModelFieldValues({ + ModelFieldValue? content, + 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 + ); + } + + Primary.fromJson(Map json) + : _tenantId = json['tenantId'], + _instanceId = json['instanceId'], + _recordId = json['recordId'], + _content = json['content'], + _related = json['related']?['serializedData'] != null + ? Related.fromJson(new Map.from(json['related']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _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() + }; + + Map toMap() => { + 'tenantId': _tenantId, + 'instanceId': _instanceId, + 'recordId': _recordId, + 'content': _content, + 'related': _related, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + static final amplify_core.QueryModelIdentifier MODEL_IDENTIFIER = amplify_core.QueryModelIdentifier(); + static final TENANTID = amplify_core.QueryField(fieldName: \\"tenantId\\"); + static final INSTANCEID = amplify_core.QueryField(fieldName: \\"instanceId\\"); + static final RECORDID = amplify_core.QueryField(fieldName: \\"recordId\\"); + static final CONTENT = amplify_core.QueryField(fieldName: \\"content\\"); + static final RELATED = amplify_core.QueryField( + fieldName: \\"related\\", + fieldType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.model, ofModelName: 'Related')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Primary\\"; + modelSchemaDefinition.pluralName = \\"Primaries\\"; + + modelSchemaDefinition.indexes = [ + amplify_core.ModelIndex(fields: const [\\"tenantId\\", \\"instanceId\\", \\"recordId\\"], name: null) + ]; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.TENANTID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.INSTANCEID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.RECORDID, + isRequired: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Primary.CONTENT, + isRequired: false, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.string) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.hasOne( + key: Primary.RELATED, + isRequired: false, + ofModelName: 'Related', + associatedKey: Related.PRIMARYTENANTID + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _PrimaryModelType extends amplify_core.ModelType { + const _PrimaryModelType(); + + @override + Primary fromJson(Map jsonData) { + return Primary.fromJson(jsonData); + } + + @override + String modelName() { + return 'Primary'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Primary] in your schema. + */ +class PrimaryModelIdentifier implements amplify_core.ModelIdentifier { + final String tenantId; + final String instanceId; + final String recordId; + + /** + * Create an instance of PrimaryModelIdentifier using [tenantId] the primary key. + * And [instanceId], [recordId] the sort keys. + */ + const PrimaryModelIdentifier({ + required this.tenantId, + required this.instanceId, + required this.recordId}); + + @override + Map serializeAsMap() => ({ + 'tenantId': tenantId, + 'instanceId': instanceId, + 'recordId': recordId + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'PrimaryModelIdentifier(tenantId: $tenantId, instanceId: $instanceId, recordId: $recordId)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is PrimaryModelIdentifier && + tenantId == other.tenantId && + instanceId == other.instanceId && + recordId == other.recordId; + } + + @override + int get hashCode => + tenantId.hashCode ^ + instanceId.hashCode ^ + recordId.hashCode; +}" +`; + +exports[`AppSync Dart Visitor custom references hasOne with sortKeyFields on primary key 2`] = ` +"/* +* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. +* +* Licensed under the Apache License, Version 2.0 (the \\"License\\"). +* You may not use this file except in compliance with the License. +* A copy of the License is located at +* +* http://aws.amazon.com/apache2.0 +* +* or in the \\"license\\" file accompanying this file. This file is distributed +* on an \\"AS IS\\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either +* express or implied. See the License for the specific language governing +* permissions and limitations under the License. +*/ + +// NOTE: This file is generated and may not follow lint rules defined in your app +// Generated files can be excluded from analysis in analysis_options.yaml +// For more info, see: https://dart.dev/guides/language/analysis-options#excluding-code-from-analysis + +// ignore_for_file: public_member_api_docs, annotate_overrides, dead_code, dead_codepublic_member_api_docs, depend_on_referenced_packages, file_names, library_private_types_in_public_api, no_leading_underscores_for_library_prefixes, no_leading_underscores_for_local_identifiers, non_constant_identifier_names, null_check_on_nullable_type_parameter, prefer_adjacent_string_concatenation, prefer_const_constructors, prefer_if_null_operators, prefer_interpolation_to_compose_strings, slash_for_doc_comments, sort_child_properties_last, unnecessary_const, unnecessary_constructor_name, unnecessary_late, unnecessary_new, unnecessary_null_aware_assignments, unnecessary_nullable_for_final_variable_declarations, unnecessary_string_interpolations, use_build_context_synchronously + +import 'ModelProvider.dart'; +import 'package:amplify_core/amplify_core.dart' as amplify_core; + + +/** This is an auto generated class representing the Related type in your schema. */ +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; + + @override + getInstanceType() => classType; + + @Deprecated('[getId] is being deprecated in favor of custom primary key feature. Use getter [modelIdentifier] to get model identifier.') + @override + String getId() => id; + + RelatedModelIdentifier get modelIdentifier { + return RelatedModelIdentifier( + id: id + ); + } + + String? get content { + 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; + } + + amplify_core.TemporalDateTime? get createdAt { + return _createdAt; + } + + amplify_core.TemporalDateTime? get updatedAt { + 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; + + factory Related({String? id, String? content, required String primaryTenantId, required String primaryInstanceId, required String primaryRecordId, Primary? primary}) { + return Related._internal( + id: id == null ? amplify_core.UUID.getUUID() : id, + content: content, + primaryTenantId: primaryTenantId, + primaryInstanceId: primaryInstanceId, + primaryRecordId: primaryRecordId, + primary: primary); + } + + bool equals(Object other) { + return this == other; + } + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is Related && + id == other.id && + _content == other._content && + _primaryTenantId == other._primaryTenantId && + _primaryInstanceId == other._primaryInstanceId && + _primaryRecordId == other._primaryRecordId && + _primary == other._primary; + } + + @override + int get hashCode => toString().hashCode; + + @override + String toString() { + var buffer = new StringBuffer(); + + 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\\")); + buffer.write(\\"}\\"); + + return buffer.toString(); + } + + Related copyWith({String? content, String? primaryTenantId, String? primaryInstanceId, String? primaryRecordId, 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 + ); + } + + Related.fromJson(Map json) + : id = json['id'], + _content = json['content'], + _primaryTenantId = json['primaryTenantId'], + _primaryInstanceId = json['primaryInstanceId'], + _primaryRecordId = json['primaryRecordId'], + _primary = json['primary']?['serializedData'] != null + ? Primary.fromJson(new Map.from(json['primary']['serializedData'])) + : null, + _createdAt = json['createdAt'] != null ? amplify_core.TemporalDateTime.fromString(json['createdAt']) : null, + _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() + }; + + Map toMap() => { + 'id': id, + 'content': _content, + 'primaryTenantId': _primaryTenantId, + 'primaryInstanceId': _primaryInstanceId, + 'primaryRecordId': _primaryRecordId, + 'primary': _primary, + 'createdAt': _createdAt, + 'updatedAt': _updatedAt + }; + + 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')); + static var schema = amplify_core.Model.defineSchema(define: (amplify_core.ModelSchemaDefinition modelSchemaDefinition) { + modelSchemaDefinition.name = \\"Related\\"; + modelSchemaDefinition.pluralName = \\"Relateds\\"; + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.id()); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.field( + key: Related.CONTENT, + isRequired: false, + 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: ['primaryTenantId', 'primaryInstanceId', 'primaryRecordId'], + ofModelName: 'Primary' + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'createdAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + + modelSchemaDefinition.addField(amplify_core.ModelFieldDefinition.nonQueryField( + fieldName: 'updatedAt', + isRequired: false, + isReadOnly: true, + ofType: amplify_core.ModelFieldType(amplify_core.ModelFieldTypeEnum.dateTime) + )); + }); +} + +class _RelatedModelType extends amplify_core.ModelType { + const _RelatedModelType(); + + @override + Related fromJson(Map jsonData) { + return Related.fromJson(jsonData); + } + + @override + String modelName() { + return 'Related'; + } +} + +/** + * This is an auto generated class representing the model identifier + * of [Related] in your schema. + */ +class RelatedModelIdentifier implements amplify_core.ModelIdentifier { + final String id; + + /** Create an instance of RelatedModelIdentifier using [id] the primary key. */ + const RelatedModelIdentifier({ + required this.id}); + + @override + Map serializeAsMap() => ({ + 'id': id + }); + + @override + List> serializeAsList() => serializeAsMap() + .entries + .map((entry) => ({ entry.key: entry.value })) + .toList(); + + @override + String serializeAsString() => serializeAsMap().values.join('#'); + + @override + String toString() => 'RelatedModelIdentifier(id: $id)'; + + @override + bool operator ==(Object other) { + if (identical(this, other)) { + return true; + } + + return other is RelatedModelIdentifier && + id == other.id; + } + + @override + int get hashCode => + id.hashCode; +}" +`; + exports[`AppSync Dart Visitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` "/* * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. 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 44cb1f4de..d82be5ff2 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 @@ -8851,6 +8851,572 @@ public final class Related implements Model { " `; +exports[`AppSyncModelVisitor custom references hasOne with sortKeyFields on primary key 1`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.HasOne; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Primary type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Primaries\\", type = Model.Type.USER, version = 1) +@Index(name = \\"undefined\\", fields = {\\"tenantId\\",\\"instanceId\\",\\"recordId\\"}) +public final class Primary implements Model { + public static final QueryField TENANT_ID = field(\\"Primary\\", \\"tenantId\\"); + 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\\"); + 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; + private final @ModelField(targetType=\\"String\\") String content; + private final @ModelField(targetType=\\"Related\\") @HasOne(associatedWith = \\"primaryTenantId\\", 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 PrimaryIdentifier primaryIdentifier; + /** @deprecated This API is internal to Amplify and should not be used. */ + @Deprecated + public PrimaryIdentifier resolveIdentifier() { + if (primaryIdentifier == null) { + this.primaryIdentifier = new PrimaryIdentifier(tenantId, instanceId, recordId); + } + return primaryIdentifier; + } + + public String getTenantId() { + return tenantId; + } + + public String getInstanceId() { + return instanceId; + } + + public String getRecordId() { + return recordId; + } + + public String getContent() { + return content; + } + + public Related getRelated() { + return related; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Primary(String tenantId, String instanceId, String recordId, String content) { + this.tenantId = tenantId; + this.instanceId = instanceId; + this.recordId = recordId; + this.content = content; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + Primary primary = (Primary) obj; + return ObjectsCompat.equals(getTenantId(), primary.getTenantId()) && + ObjectsCompat.equals(getInstanceId(), primary.getInstanceId()) && + ObjectsCompat.equals(getRecordId(), primary.getRecordId()) && + ObjectsCompat.equals(getContent(), primary.getContent()) && + ObjectsCompat.equals(getCreatedAt(), primary.getCreatedAt()) && + ObjectsCompat.equals(getUpdatedAt(), primary.getUpdatedAt()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getTenantId()) + .append(getInstanceId()) + .append(getRecordId()) + .append(getContent()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .append(\\"Primary {\\") + .append(\\"tenantId=\\" + String.valueOf(getTenantId()) + \\", \\") + .append(\\"instanceId=\\" + String.valueOf(getInstanceId()) + \\", \\") + .append(\\"recordId=\\" + String.valueOf(getRecordId()) + \\", \\") + .append(\\"content=\\" + String.valueOf(getContent()) + \\", \\") + .append(\\"createdAt=\\" + String.valueOf(getCreatedAt()) + \\", \\") + .append(\\"updatedAt=\\" + String.valueOf(getUpdatedAt())) + .append(\\"}\\") + .toString(); + } + + public static TenantIdStep builder() { + return new Builder(); + } + + public CopyOfBuilder copyOfBuilder() { + return new CopyOfBuilder(tenantId, + instanceId, + recordId, + content); + } + public interface TenantIdStep { + InstanceIdStep tenantId(String tenantId); + } + + + public interface InstanceIdStep { + RecordIdStep instanceId(String instanceId); + } + + + public interface RecordIdStep { + BuildStep recordId(String recordId); + } + + + public interface BuildStep { + Primary build(); + BuildStep content(String content); + } + + + public static class Builder implements TenantIdStep, InstanceIdStep, RecordIdStep, BuildStep { + private String tenantId; + private String instanceId; + private String recordId; + private String content; + public Builder() { + + } + + private Builder(String tenantId, String instanceId, String recordId, String content) { + this.tenantId = tenantId; + this.instanceId = instanceId; + this.recordId = recordId; + this.content = content; + } + + @Override + public Primary build() { + + return new Primary( + tenantId, + instanceId, + recordId, + content); + } + + @Override + public InstanceIdStep tenantId(String tenantId) { + Objects.requireNonNull(tenantId); + this.tenantId = tenantId; + return this; + } + + @Override + public RecordIdStep instanceId(String instanceId) { + Objects.requireNonNull(instanceId); + this.instanceId = instanceId; + return this; + } + + @Override + public BuildStep recordId(String recordId) { + Objects.requireNonNull(recordId); + this.recordId = recordId; + return this; + } + + @Override + public BuildStep content(String content) { + this.content = content; + return this; + } + } + + + public final class CopyOfBuilder extends Builder { + private CopyOfBuilder(String tenantId, String instanceId, String recordId, String content) { + super(tenantId, instanceId, recordId, content); + Objects.requireNonNull(tenantId); + Objects.requireNonNull(instanceId); + Objects.requireNonNull(recordId); + } + + @Override + public CopyOfBuilder tenantId(String tenantId) { + return (CopyOfBuilder) super.tenantId(tenantId); + } + + @Override + public CopyOfBuilder instanceId(String instanceId) { + return (CopyOfBuilder) super.instanceId(instanceId); + } + + @Override + public CopyOfBuilder recordId(String recordId) { + return (CopyOfBuilder) super.recordId(recordId); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + } + + + public static class PrimaryIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public PrimaryIdentifier(String tenantId, String instanceId, String recordId) { + super(tenantId, instanceId, recordId); + } + } + +} +" +`; + +exports[`AppSyncModelVisitor custom references hasOne with sortKeyFields on primary key 2`] = ` +"package com.amplifyframework.datastore.generated.model; + +import com.amplifyframework.core.model.annotations.BelongsTo; +import com.amplifyframework.core.model.temporal.Temporal; +import com.amplifyframework.core.model.ModelIdentifier; + +import java.util.List; +import java.util.UUID; +import java.util.Objects; + +import androidx.core.util.ObjectsCompat; + +import com.amplifyframework.core.model.Model; +import com.amplifyframework.core.model.annotations.Index; +import com.amplifyframework.core.model.annotations.ModelConfig; +import com.amplifyframework.core.model.annotations.ModelField; +import com.amplifyframework.core.model.query.predicate.QueryField; + +import static com.amplifyframework.core.model.query.predicate.QueryField.field; + +/** This is an auto generated class representing the Related type in your schema. */ +@SuppressWarnings(\\"all\\") +@ModelConfig(pluralName = \\"Relateds\\", type = Model.Type.USER, version = 1) +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\\", \\"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 = \\"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. */ + @Deprecated + public String resolveIdentifier() { + return id; + } + + public String getId() { + return id; + } + + public String getContent() { + return content; + } + + public String getPrimaryTenantId() { + return primaryTenantId; + } + + public String getPrimaryInstanceId() { + return primaryInstanceId; + } + + public String getPrimaryRecordId() { + return primaryRecordId; + } + + public Primary getPrimary() { + return primary; + } + + public Temporal.DateTime getCreatedAt() { + return createdAt; + } + + public Temporal.DateTime getUpdatedAt() { + return updatedAt; + } + + private Related(String id, String content, String primaryTenantId, String primaryInstanceId, String primaryRecordId, Primary primary) { + this.id = id; + this.content = content; + this.primaryTenantId = primaryTenantId; + this.primaryInstanceId = primaryInstanceId; + this.primaryRecordId = primaryRecordId; + this.primary = primary; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } else if(obj == null || getClass() != obj.getClass()) { + return false; + } else { + 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()); + } + } + + @Override + public int hashCode() { + return new StringBuilder() + .append(getId()) + .append(getContent()) + .append(getPrimaryTenantId()) + .append(getPrimaryInstanceId()) + .append(getPrimaryRecordId()) + .append(getPrimary()) + .append(getCreatedAt()) + .append(getUpdatedAt()) + .toString() + .hashCode(); + } + + @Override + public String toString() { + return new StringBuilder() + .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())) + .append(\\"}\\") + .toString(); + } + + public static PrimaryTenantIdStep builder() { + return new Builder(); + } + + /** + * WARNING: This method should not be used to build an instance of this object for a CREATE mutation. + * This is a convenience method to return an instance of the object with only its ID populated + * to be used in the context of a parameter in a delete mutation or referencing a foreign key + * in a relationship. + * @param id the id of the existing item this instance will represent + * @return an instance of this model with only ID populated + */ + public static Related justId(String id) { + return new Related( + id, + null, + null, + null, + null, + null + ); + } + + 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); + BuildStep content(String content); + BuildStep primary(Primary primary); + } + + + public static class Builder implements PrimaryTenantIdStep, PrimaryInstanceIdStep, PrimaryRecordIdStep, 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) { + this.id = id; + this.content = content; + this.primaryTenantId = primaryTenantId; + this.primaryInstanceId = primaryInstanceId; + this.primaryRecordId = primaryRecordId; + this.primary = primary; + } + + @Override + public Related build() { + String id = this.id != null ? this.id : UUID.randomUUID().toString(); + + 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; + return this; + } + + @Override + public BuildStep primary(Primary primary) { + this.primary = primary; + return this; + } + + /** + * @param id id + * @return Current Builder instance, for fluent method chaining + */ + public BuildStep id(String id) { + this.id = id; + return this; + } + } + + + 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); + } + + @Override + public CopyOfBuilder content(String content) { + return (CopyOfBuilder) super.content(content); + } + + @Override + public CopyOfBuilder primary(Primary primary) { + return (CopyOfBuilder) super.primary(primary); + } + } + + + public static class RelatedIdentifier extends ModelIdentifier { + private static final long serialVersionUID = 1L; + public RelatedIdentifier(String id) { + super(id); + } + } + +} +" +`; + exports[`AppSyncModelVisitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` "package com.amplifyframework.datastore.generated.model; diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap index ca3c210b7..9b7dc4dfb 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/__snapshots__/appsync-model-introspection-visitor.test.ts.snap @@ -4023,6 +4023,195 @@ exports[`custom references hasMany with sortKeyFields on primary key 1`] = ` }" `; +exports[`custom references hasOne with sortKeyFields on primary key 1`] = ` +"{ + \\"version\\": 1, + \\"models\\": { + \\"Primary\\": { + \\"name\\": \\"Primary\\", + \\"fields\\": { + \\"tenantId\\": { + \\"name\\": \\"tenantId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"instanceId\\": { + \\"name\\": \\"instanceId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"recordId\\": { + \\"name\\": \\"recordId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"related\\": { + \\"name\\": \\"related\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Related\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"HAS_ONE\\", + \\"associatedWith\\": [ + \\"primaryTenantId\\", + \\"primaryInstanceId\\", + \\"primaryRecordId\\" + ], + \\"targetNames\\": [] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Primaries\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + }, + { + \\"type\\": \\"key\\", + \\"properties\\": { + \\"fields\\": [ + \\"tenantId\\", + \\"instanceId\\", + \\"recordId\\" + ] + } + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": true, + \\"primaryKeyFieldName\\": \\"tenantId\\", + \\"sortKeyFieldNames\\": [ + \\"instanceId\\", + \\"recordId\\" + ] + } + }, + \\"Related\\": { + \\"name\\": \\"Related\\", + \\"fields\\": { + \\"id\\": { + \\"name\\": \\"id\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"content\\": { + \\"name\\": \\"content\\", + \\"isArray\\": false, + \\"type\\": \\"String\\", + \\"isRequired\\": false, + \\"attributes\\": [] + }, + \\"primaryTenantId\\": { + \\"name\\": \\"primaryTenantId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"primaryInstanceId\\": { + \\"name\\": \\"primaryInstanceId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"primaryRecordId\\": { + \\"name\\": \\"primaryRecordId\\", + \\"isArray\\": false, + \\"type\\": \\"ID\\", + \\"isRequired\\": true, + \\"attributes\\": [] + }, + \\"primary\\": { + \\"name\\": \\"primary\\", + \\"isArray\\": false, + \\"type\\": { + \\"model\\": \\"Primary\\" + }, + \\"isRequired\\": false, + \\"attributes\\": [], + \\"association\\": { + \\"connectionType\\": \\"BELONGS_TO\\", + \\"targetNames\\": [ + \\"primaryTenantId\\", + \\"primaryInstanceId\\", + \\"primaryRecordId\\" + ] + } + }, + \\"createdAt\\": { + \\"name\\": \\"createdAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + }, + \\"updatedAt\\": { + \\"name\\": \\"updatedAt\\", + \\"isArray\\": false, + \\"type\\": \\"AWSDateTime\\", + \\"isRequired\\": false, + \\"attributes\\": [], + \\"isReadOnly\\": true + } + }, + \\"syncable\\": true, + \\"pluralName\\": \\"Relateds\\", + \\"attributes\\": [ + { + \\"type\\": \\"model\\", + \\"properties\\": {} + } + ], + \\"primaryKeyInfo\\": { + \\"isCustomPrimaryKey\\": false, + \\"primaryKeyFieldName\\": \\"id\\", + \\"sortKeyFieldNames\\": [] + } + } + }, + \\"enums\\": {}, + \\"nonModels\\": {} +}" +`; + exports[`custom references sets the association to the references field for hasMany/belongsTo 1`] = ` "{ \\"version\\": 1, 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 63f68fa96..dfc173c83 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 @@ -1864,6 +1864,321 @@ extension ModelPath where ModelType == Related { }" `; +exports[`AppSyncSwiftVisitor custom references hasOne with sortKeyFields on primary key 1`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +public struct Primary: Model { + public let tenantId: String + public let instanceId: String + public let recordId: String + public var content: String? + internal var _related: LazyReference + public var related: Related? { + get async throws { + try await _related.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(tenantId: String, + instanceId: String, + recordId: String, + content: String? = nil, + related: Related? = nil) { + self.init(tenantId: tenantId, + instanceId: instanceId, + recordId: recordId, + content: content, + related: related, + createdAt: nil, + updatedAt: nil) + } + internal init(tenantId: String, + instanceId: String, + recordId: String, + content: String? = nil, + related: Related? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.tenantId = tenantId + self.instanceId = instanceId + self.recordId = recordId + self.content = content + self._related = LazyReference(related) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setRelated(_ related: Related? = nil) { + self._related = LazyReference(related) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + tenantId = try values.decode(String.self, forKey: .tenantId) + instanceId = try values.decode(String.self, forKey: .instanceId) + recordId = try values.decode(String.self, forKey: .recordId) + content = try? values.decode(String?.self, forKey: .content) + _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) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(tenantId, forKey: .tenantId) + try container.encode(instanceId, forKey: .instanceId) + try container.encode(recordId, forKey: .recordId) + try container.encode(content, forKey: .content) + try container.encode(_related, forKey: .related) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasOne with sortKeyFields on primary key 2`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Primary { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case tenantId + case instanceId + case recordId + case content + case related + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let primary = Primary.keys + + model.listPluralName = \\"Primaries\\" + model.syncPluralName = \\"Primaries\\" + + model.attributes( + .index(fields: [\\"tenantId\\", \\"instanceId\\", \\"recordId\\"], name: nil), + .primaryKey(fields: [primary.tenantId, primary.instanceId, primary.recordId]) + ) + + model.fields( + .field(primary.tenantId, is: .required, ofType: .string), + .field(primary.instanceId, is: .required, ofType: .string), + .field(primary.recordId, is: .required, ofType: .string), + .field(primary.content, is: .optional, ofType: .string), + .field(primary.related, is: .optional, ofType: .model(Related.self)), + .field(primary.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(primary.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Primary: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Custom + public typealias IdentifierProtocol = ModelIdentifier +} + +extension Primary.IdentifierProtocol { + public static func identifier(tenantId: String, + instanceId: String, + recordId: String) -> Self { + .make(fields:[(name: \\"tenantId\\", value: tenantId), (name: \\"instanceId\\", value: instanceId), (name: \\"recordId\\", value: recordId)]) + } +} +extension ModelPath where ModelType == Primary { + public var tenantId: FieldPath { + string(\\"tenantId\\") + } + public var instanceId: FieldPath { + string(\\"instanceId\\") + } + public var recordId: FieldPath { + string(\\"recordId\\") + } + public var content: FieldPath { + string(\\"content\\") + } + public var related: ModelPath { + Related.Path(name: \\"related\\", parent: self) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasOne with sortKeyFields on primary key 3`] = ` +"// swiftlint:disable all +import Amplify +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 { + try await _primary.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + 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 + } + public mutating func setPrimary(_ primary: Primary? = nil) { + self._primary = LazyReference(primary) + } + public init(from decoder: Decoder) throws { + 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) + } + public func encode(to encoder: Encoder) throws { + 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) + } +}" +`; + +exports[`AppSyncSwiftVisitor custom references hasOne with sortKeyFields on primary key 4`] = ` +"// swiftlint:disable all +import Amplify +import Foundation + +extension Related { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case primaryTenantId + case primaryInstanceId + case primaryRecordId + case primary + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let related = Related.keys + + model.listPluralName = \\"Relateds\\" + model.syncPluralName = \\"Relateds\\" + + model.attributes( + .primaryKey(fields: [related.id]) + ) + + 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: [\\"primaryTenantId\\", \\"primaryInstanceId\\", \\"primaryRecordId\\"]), + .field(related.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(related.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Related: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Related { + public var id: FieldPath { + string(\\"id\\") + } + 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) + } + public var createdAt: FieldPath { + datetime(\\"createdAt\\") + } + public var updatedAt: FieldPath { + datetime(\\"updatedAt\\") + } +}" +`; + exports[`AppSyncSwiftVisitor custom references sets the association to the references field for hasMany/belongsTo 1`] = ` "// swiftlint:disable all import Amplify diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts index 96ef18d2d..2f697e489 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-dart-visitor.test.ts @@ -945,5 +945,35 @@ describe('AppSync Dart Visitor', () => { expect(generatedCode).toMatchSnapshot(); }); }); + + test('hasOne with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: Related @hasOne(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + ['Primary', 'Related'].forEach(modelName => { + const generatedCode = getVisitor({ + schema, + selectedType: modelName, + isTimestampFieldsAdded: true, + respectPrimaryKeyAttributesOnConnectionField: true, + transformerVersion: 2, + }).generate(); + expect(generatedCode).toMatchSnapshot(); + }); + }); }); }); diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts index 1b5bf455a..9946c53f5 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-java-visitor.test.ts @@ -910,5 +910,31 @@ describe('AppSyncModelVisitor', () => { respectPrimaryKeyAttributesOnConnectionField: true, }).generate()).toMatchSnapshot(); }); + + test('hasOne with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: Related @hasOne(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + expect(getVisitorPipelinedTransformer(schema, 'Primary', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); }); }); 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 329276ecf..179f33afb 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 @@ -615,6 +615,28 @@ describe('custom references', () => { expect(visitor.generate()).toMatchSnapshot(); }); + test('hasOne with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: Related @hasOne(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + const visitor: AppSyncModelIntrospectionVisitor = getVisitor(schema); + expect(visitor.generate()).toMatchSnapshot(); + }); + test('throws error when using fields and references on hasMany', () => { const schema = /* GraphQL */ ` type SqlPrimary @refersTo(name: "sql_primary") @model { diff --git a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts index 3bb624acb..2ee5581ff 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/visitors/appsync-swift-visitor.test.ts @@ -3138,5 +3138,38 @@ describe('AppSyncSwiftVisitor', () => { respectPrimaryKeyAttributesOnConnectionField: true, }).generate()).toMatchSnapshot(); }); + + test('hasOne with sortKeyFields on primary key', () => { + const schema = /* GraphQL */ ` + type Primary @model { + tenantId: ID! @primaryKey(sortKeyFields: ["instanceId", "recordId"]) + instanceId: ID! + recordId: ID! + content: String + related: Related @hasOne(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + + type Related @model { + content: String + primaryTenantId: ID! + primaryInstanceId: ID! + primaryRecordId: ID! + primary: Primary @belongsTo(references: ["primaryTenantId", "primaryInstanceId", "primaryRecordId"]) + } + `; + + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Primary', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', CodeGenGenerateEnum.code, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + expect(getVisitorPipelinedTransformer(schema, 'Related', CodeGenGenerateEnum.metadata, { + respectPrimaryKeyAttributesOnConnectionField: true, + }).generate()).toMatchSnapshot(); + }); }); });