From d2454d8f0f58a59b99014eb3762208dcf45e0ed9 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:34:37 -0400 Subject: [PATCH 1/2] test(data): Gen2 data customize data model doc example testing (#3699) --- .../APIHostApp.xcodeproj/project.pbxproj | 276 +++++++++++++++++- .../GraphQLLocationPostUser1Tests.swift | 45 +++ .../Gen2_1/Location1+Schema.swift | 26 ++ .../Gen2_1/Location1.swift | 8 + .../Gen2_1/Post1+Schema.swift | 62 ++++ .../Gen2_1/Post1.swift | 32 ++ .../Gen2_1/User1+Schema.swift | 57 ++++ .../Gen2_1/User1.swift | 27 ++ .../Gen2_10/Customer10+Schema.swift | 71 +++++ .../Gen2_10/Customer10.swift | 37 +++ .../Gen2_10/GraphQLCustomer10Tests.swift | 73 +++++ ...GraphQLPostVideoPrivacySetting2Tests.swift | 43 +++ .../Gen2_2/Post2+Schema.swift | 62 ++++ .../Gen2_2/Post2.swift | 32 ++ .../Gen2_2/PrivacySetting2.swift | 9 + .../Gen2_2/Video2+Schema.swift | 57 ++++ .../Gen2_2/Video2.swift | 27 ++ .../Gen2_3/GraphQLTeamMember3Tests.swift | 187 ++++++++++++ .../Gen2_3/Member3+Schema.swift | 65 +++++ .../Gen2_3/Member3.swift | 56 ++++ .../Gen2_3/Team3+Schema.swift | 65 +++++ .../Gen2_3/Team3.swift | 32 ++ .../Gen2_4/Cart4+Schema.swift | 65 +++++ .../Gen2_4/Cart4.swift | 56 ++++ .../Gen2_4/Customer4+Schema.swift | 65 +++++ .../Gen2_4/Customer4.swift | 56 ++++ .../Gen2_4/GraphQLCartCustomer4Tests.swift | 151 ++++++++++ .../Gen2_41/GraphQLPostPerson41Tests.swift | 71 +++++ .../Gen2_41/Person41+Schema.swift | 70 +++++ .../Gen2_41/Person41.swift | 37 +++ .../Gen2_41/Post41+Schema.swift | 75 +++++ .../Gen2_41/Post41.swift | 78 +++++ .../Gen2_5/GraphQLTodo5Tests.swift | 42 +++ .../Gen2_5/Todo5+Schema.swift | 65 +++++ .../Gen2_5/Todo5.swift | 32 ++ .../Gen2_6/GraphQLTodo6Tests.swift | 44 +++ .../Gen2_6/Todo6+Schema.swift | 72 +++++ .../Gen2_6/Todo6.swift | 32 ++ .../Gen2_7/GraphQLStoreBranch7Tests.swift | 43 +++ .../Gen2_7/StoreBranch7+Schema.swift | 93 ++++++ .../Gen2_7/StoreBranch7.swift | 52 ++++ .../Gen2_8/Customer8+Schema.swift | 71 +++++ .../Gen2_8/Customer8.swift | 37 +++ .../Gen2_8/GraphQLCustomer8Tests.swift | 69 +++++ .../Gen2_9/Customer9+Schema.swift | 71 +++++ .../Gen2_9/Customer9.swift | 37 +++ .../Gen2_9/GraphQLCustomer9Tests.swift | 69 +++++ .../AWSAPIPluginGen2GraphQLTests/README.md | 155 +++++++++- 48 files changed, 3051 insertions(+), 6 deletions(-) create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/GraphQLLocationPostUser1Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/GraphQLCustomer10Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/GraphQLPostVideoPrivacySetting2Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/PrivacySetting2.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/GraphQLTeamMember3Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/GraphQLCartCustomer4Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/GraphQLTodo5Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/GraphQLTodo6Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/GraphQLStoreBranch7Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/GraphQLCustomer8Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/GraphQLCustomer9Tests.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj index d8901be09c..c91d094012 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj +++ b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj @@ -56,6 +56,52 @@ 2126275E289ABFEB003788E3 /* NestedTypeTestModel+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2126272F289ABFEB003788E3 /* NestedTypeTestModel+Schema.swift */; }; 2126275F289ABFEB003788E3 /* Post3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21262730289ABFEB003788E3 /* Post3.swift */; }; 2136C8B32926A509002CC005 /* GraphQLLazyLoadBlogPostComment8V2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2136C8B22926A509002CC005 /* GraphQLLazyLoadBlogPostComment8V2Tests.swift */; }; + 213B969E2BF3B65800DE74AB /* Post2+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96992BF3B65800DE74AB /* Post2+Schema.swift */; }; + 213B969F2BF3B65800DE74AB /* Video2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B969A2BF3B65800DE74AB /* Video2.swift */; }; + 213B96A02BF3B65800DE74AB /* PrivacySetting2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B969B2BF3B65800DE74AB /* PrivacySetting2.swift */; }; + 213B96A12BF3B65800DE74AB /* Post2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B969C2BF3B65800DE74AB /* Post2.swift */; }; + 213B96A22BF3B65800DE74AB /* Video2+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B969D2BF3B65800DE74AB /* Video2+Schema.swift */; }; + 213B96A92BF3B67500DE74AB /* Location1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A32BF3B67500DE74AB /* Location1.swift */; }; + 213B96AA2BF3B67500DE74AB /* User1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A42BF3B67500DE74AB /* User1.swift */; }; + 213B96AB2BF3B67500DE74AB /* Post1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A52BF3B67500DE74AB /* Post1.swift */; }; + 213B96AC2BF3B67500DE74AB /* User1+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A62BF3B67500DE74AB /* User1+Schema.swift */; }; + 213B96AD2BF3B67500DE74AB /* Location1+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A72BF3B67500DE74AB /* Location1+Schema.swift */; }; + 213B96AE2BF3B67500DE74AB /* Post1+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96A82BF3B67500DE74AB /* Post1+Schema.swift */; }; + 213B96B32BF3B6C100DE74AB /* Team3+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96AF2BF3B6C100DE74AB /* Team3+Schema.swift */; }; + 213B96B42BF3B6C100DE74AB /* Member3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B02BF3B6C100DE74AB /* Member3.swift */; }; + 213B96B52BF3B6C100DE74AB /* Member3+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B12BF3B6C100DE74AB /* Member3+Schema.swift */; }; + 213B96B62BF3B6C100DE74AB /* Team3.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B22BF3B6C100DE74AB /* Team3.swift */; }; + 213B96BB2BF3B6D400DE74AB /* Customer4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B72BF3B6D400DE74AB /* Customer4.swift */; }; + 213B96BC2BF3B6D400DE74AB /* Cart4.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B82BF3B6D400DE74AB /* Cart4.swift */; }; + 213B96BD2BF3B6D400DE74AB /* Cart4+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96B92BF3B6D400DE74AB /* Cart4+Schema.swift */; }; + 213B96BE2BF3B6D400DE74AB /* Customer4+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96BA2BF3B6D400DE74AB /* Customer4+Schema.swift */; }; + 213B96CC2BF3BA2300DE74AB /* GraphQLLocationPostUser1Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96CB2BF3BA2300DE74AB /* GraphQLLocationPostUser1Tests.swift */; }; + 213B96CE2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96CD2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift */; }; + 213B96D02BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96CF2BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift */; }; + 213B96D22BF3EFD000DE74AB /* GraphQLCartCustomer4Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96D12BF3EFD000DE74AB /* GraphQLCartCustomer4Tests.swift */; }; + 213B96D52BF4480900DE74AB /* Todo5.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96D32BF4480900DE74AB /* Todo5.swift */; }; + 213B96D62BF4480900DE74AB /* Todo5+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96D42BF4480900DE74AB /* Todo5+Schema.swift */; }; + 213B96DA2BF4481F00DE74AB /* Todo6+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96D82BF4481F00DE74AB /* Todo6+Schema.swift */; }; + 213B96DB2BF4481F00DE74AB /* Todo6.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96D92BF4481F00DE74AB /* Todo6.swift */; }; + 213B96DF2BF4484700DE74AB /* StoreBranch7.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96DD2BF4484700DE74AB /* StoreBranch7.swift */; }; + 213B96E02BF4484700DE74AB /* StoreBranch7+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96DE2BF4484700DE74AB /* StoreBranch7+Schema.swift */; }; + 213B96E22BF4486900DE74AB /* GraphQLTodo5Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96E12BF4486900DE74AB /* GraphQLTodo5Tests.swift */; }; + 213B96E42BF4492400DE74AB /* GraphQLTodo6Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96E32BF4492400DE74AB /* GraphQLTodo6Tests.swift */; }; + 213B96E62BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96E52BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift */; }; + 213B96E92BF44DE600DE74AB /* GraphQLCustomer8Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96E82BF44DE600DE74AB /* GraphQLCustomer8Tests.swift */; }; + 213B96ED2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96EC2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift */; }; + 213B96EF2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96EE2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift */; }; + 213B96F22BF4500200DE74AB /* Customer8.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F02BF4500200DE74AB /* Customer8.swift */; }; + 213B96F32BF4500200DE74AB /* Customer8+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F12BF4500200DE74AB /* Customer8+Schema.swift */; }; + 213B96F62BF4500D00DE74AB /* Customer9.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F42BF4500D00DE74AB /* Customer9.swift */; }; + 213B96F72BF4500D00DE74AB /* Customer9+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F52BF4500D00DE74AB /* Customer9+Schema.swift */; }; + 213B96FA2BF4501B00DE74AB /* Customer10.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F82BF4501B00DE74AB /* Customer10.swift */; }; + 213B96FB2BF4501B00DE74AB /* Customer10+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96F92BF4501B00DE74AB /* Customer10+Schema.swift */; }; + 213B96FE2BF4533500DE74AB /* GraphQLPostPerson41Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B96FD2BF4533500DE74AB /* GraphQLPostPerson41Tests.swift */; }; + 213B970F2BF4F1E800DE74AB /* Post41+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970B2BF4F1E800DE74AB /* Post41+Schema.swift */; }; + 213B97102BF4F1E800DE74AB /* Person41.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970C2BF4F1E800DE74AB /* Person41.swift */; }; + 213B97112BF4F1E800DE74AB /* Person41+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970D2BF4F1E800DE74AB /* Person41+Schema.swift */; }; + 213B97122BF4F1E800DE74AB /* Post41.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970E2BF4F1E800DE74AB /* Post41.swift */; }; 213DBC8128A6C4FB00B30280 /* TestConfigHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213DBC8028A6C4FB00B30280 /* TestConfigHelper.swift */; }; 213DBC8528A6CE9800B30280 /* GraphQLWithLambdaAuthIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21698BA328899B3F004BD994 /* GraphQLWithLambdaAuthIntegrationTests.swift */; }; 213DBC8728A6CEDD00B30280 /* Todo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213DBC8628A6CEDD00B30280 /* Todo.swift */; }; @@ -516,6 +562,52 @@ 2126272F289ABFEB003788E3 /* NestedTypeTestModel+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NestedTypeTestModel+Schema.swift"; sourceTree = ""; }; 21262730289ABFEB003788E3 /* Post3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post3.swift; sourceTree = ""; }; 2136C8B22926A509002CC005 /* GraphQLLazyLoadBlogPostComment8V2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLLazyLoadBlogPostComment8V2Tests.swift; sourceTree = ""; }; + 213B96992BF3B65800DE74AB /* Post2+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Post2+Schema.swift"; sourceTree = ""; }; + 213B969A2BF3B65800DE74AB /* Video2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Video2.swift; sourceTree = ""; }; + 213B969B2BF3B65800DE74AB /* PrivacySetting2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrivacySetting2.swift; sourceTree = ""; }; + 213B969C2BF3B65800DE74AB /* Post2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post2.swift; sourceTree = ""; }; + 213B969D2BF3B65800DE74AB /* Video2+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Video2+Schema.swift"; sourceTree = ""; }; + 213B96A32BF3B67500DE74AB /* Location1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Location1.swift; sourceTree = ""; }; + 213B96A42BF3B67500DE74AB /* User1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User1.swift; sourceTree = ""; }; + 213B96A52BF3B67500DE74AB /* Post1.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post1.swift; sourceTree = ""; }; + 213B96A62BF3B67500DE74AB /* User1+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "User1+Schema.swift"; sourceTree = ""; }; + 213B96A72BF3B67500DE74AB /* Location1+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Location1+Schema.swift"; sourceTree = ""; }; + 213B96A82BF3B67500DE74AB /* Post1+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Post1+Schema.swift"; sourceTree = ""; }; + 213B96AF2BF3B6C100DE74AB /* Team3+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Team3+Schema.swift"; sourceTree = ""; }; + 213B96B02BF3B6C100DE74AB /* Member3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Member3.swift; sourceTree = ""; }; + 213B96B12BF3B6C100DE74AB /* Member3+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Member3+Schema.swift"; sourceTree = ""; }; + 213B96B22BF3B6C100DE74AB /* Team3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Team3.swift; sourceTree = ""; }; + 213B96B72BF3B6D400DE74AB /* Customer4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Customer4.swift; sourceTree = ""; }; + 213B96B82BF3B6D400DE74AB /* Cart4.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cart4.swift; sourceTree = ""; }; + 213B96B92BF3B6D400DE74AB /* Cart4+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Cart4+Schema.swift"; sourceTree = ""; }; + 213B96BA2BF3B6D400DE74AB /* Customer4+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Customer4+Schema.swift"; sourceTree = ""; }; + 213B96CB2BF3BA2300DE74AB /* GraphQLLocationPostUser1Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLLocationPostUser1Tests.swift; sourceTree = ""; }; + 213B96CD2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLPostVideoPrivacySetting2Tests.swift; sourceTree = ""; }; + 213B96CF2BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTeamMember3Tests.swift; sourceTree = ""; }; + 213B96D12BF3EFD000DE74AB /* GraphQLCartCustomer4Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLCartCustomer4Tests.swift; sourceTree = ""; }; + 213B96D32BF4480900DE74AB /* Todo5.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo5.swift; sourceTree = ""; }; + 213B96D42BF4480900DE74AB /* Todo5+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo5+Schema.swift"; sourceTree = ""; }; + 213B96D82BF4481F00DE74AB /* Todo6+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo6+Schema.swift"; sourceTree = ""; }; + 213B96D92BF4481F00DE74AB /* Todo6.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo6.swift; sourceTree = ""; }; + 213B96DD2BF4484700DE74AB /* StoreBranch7.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoreBranch7.swift; sourceTree = ""; }; + 213B96DE2BF4484700DE74AB /* StoreBranch7+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StoreBranch7+Schema.swift"; sourceTree = ""; }; + 213B96E12BF4486900DE74AB /* GraphQLTodo5Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo5Tests.swift; sourceTree = ""; }; + 213B96E32BF4492400DE74AB /* GraphQLTodo6Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo6Tests.swift; sourceTree = ""; }; + 213B96E52BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLStoreBranch7Tests.swift; sourceTree = ""; }; + 213B96E82BF44DE600DE74AB /* GraphQLCustomer8Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLCustomer8Tests.swift; sourceTree = ""; }; + 213B96EC2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLCustomer9Tests.swift; sourceTree = ""; }; + 213B96EE2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLCustomer10Tests.swift; sourceTree = ""; }; + 213B96F02BF4500200DE74AB /* Customer8.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Customer8.swift; sourceTree = ""; }; + 213B96F12BF4500200DE74AB /* Customer8+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Customer8+Schema.swift"; sourceTree = ""; }; + 213B96F42BF4500D00DE74AB /* Customer9.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Customer9.swift; sourceTree = ""; }; + 213B96F52BF4500D00DE74AB /* Customer9+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Customer9+Schema.swift"; sourceTree = ""; }; + 213B96F82BF4501B00DE74AB /* Customer10.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Customer10.swift; sourceTree = ""; }; + 213B96F92BF4501B00DE74AB /* Customer10+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Customer10+Schema.swift"; sourceTree = ""; }; + 213B96FD2BF4533500DE74AB /* GraphQLPostPerson41Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLPostPerson41Tests.swift; sourceTree = ""; }; + 213B970B2BF4F1E800DE74AB /* Post41+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Post41+Schema.swift"; sourceTree = ""; }; + 213B970C2BF4F1E800DE74AB /* Person41.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person41.swift; sourceTree = ""; }; + 213B970D2BF4F1E800DE74AB /* Person41+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Person41+Schema.swift"; sourceTree = ""; }; + 213B970E2BF4F1E800DE74AB /* Post41.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post41.swift; sourceTree = ""; }; 213DBB6028A40DAE00B30280 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 213DBC7528A6C47000B30280 /* AWSAPIPluginGraphQLLambdaAuthTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AWSAPIPluginGraphQLLambdaAuthTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 213DBC8028A6C4FB00B30280 /* TestConfigHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConfigHelper.swift; sourceTree = ""; }; @@ -912,6 +1004,129 @@ path = Models; sourceTree = ""; }; + 213B96942BF3B5EA00DE74AB /* Gen2_2 */ = { + isa = PBXGroup; + children = ( + 213B969C2BF3B65800DE74AB /* Post2.swift */, + 213B96992BF3B65800DE74AB /* Post2+Schema.swift */, + 213B969B2BF3B65800DE74AB /* PrivacySetting2.swift */, + 213B969A2BF3B65800DE74AB /* Video2.swift */, + 213B969D2BF3B65800DE74AB /* Video2+Schema.swift */, + 213B96CD2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift */, + ); + path = Gen2_2; + sourceTree = ""; + }; + 213B96952BF3B62200DE74AB /* Gen2_3 */ = { + isa = PBXGroup; + children = ( + 213B96B02BF3B6C100DE74AB /* Member3.swift */, + 213B96B12BF3B6C100DE74AB /* Member3+Schema.swift */, + 213B96B22BF3B6C100DE74AB /* Team3.swift */, + 213B96AF2BF3B6C100DE74AB /* Team3+Schema.swift */, + 213B96CF2BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift */, + ); + path = Gen2_3; + sourceTree = ""; + }; + 213B96962BF3B62C00DE74AB /* Gen2_1 */ = { + isa = PBXGroup; + children = ( + 213B96A32BF3B67500DE74AB /* Location1.swift */, + 213B96A72BF3B67500DE74AB /* Location1+Schema.swift */, + 213B96A52BF3B67500DE74AB /* Post1.swift */, + 213B96A82BF3B67500DE74AB /* Post1+Schema.swift */, + 213B96A42BF3B67500DE74AB /* User1.swift */, + 213B96A62BF3B67500DE74AB /* User1+Schema.swift */, + 213B96CB2BF3BA2300DE74AB /* GraphQLLocationPostUser1Tests.swift */, + ); + path = Gen2_1; + sourceTree = ""; + }; + 213B96972BF3B63600DE74AB /* Gen2_4 */ = { + isa = PBXGroup; + children = ( + 213B96B82BF3B6D400DE74AB /* Cart4.swift */, + 213B96B92BF3B6D400DE74AB /* Cart4+Schema.swift */, + 213B96B72BF3B6D400DE74AB /* Customer4.swift */, + 213B96BA2BF3B6D400DE74AB /* Customer4+Schema.swift */, + 213B96D12BF3EFD000DE74AB /* GraphQLCartCustomer4Tests.swift */, + ); + path = Gen2_4; + sourceTree = ""; + }; + 213B96982BF3B63E00DE74AB /* Gen2_5 */ = { + isa = PBXGroup; + children = ( + 213B96D32BF4480900DE74AB /* Todo5.swift */, + 213B96D42BF4480900DE74AB /* Todo5+Schema.swift */, + 213B96E12BF4486900DE74AB /* GraphQLTodo5Tests.swift */, + ); + path = Gen2_5; + sourceTree = ""; + }; + 213B96D72BF4480E00DE74AB /* Gen2_6 */ = { + isa = PBXGroup; + children = ( + 213B96D92BF4481F00DE74AB /* Todo6.swift */, + 213B96D82BF4481F00DE74AB /* Todo6+Schema.swift */, + 213B96E32BF4492400DE74AB /* GraphQLTodo6Tests.swift */, + ); + path = Gen2_6; + sourceTree = ""; + }; + 213B96DC2BF4482D00DE74AB /* Gen2_7 */ = { + isa = PBXGroup; + children = ( + 213B96DD2BF4484700DE74AB /* StoreBranch7.swift */, + 213B96DE2BF4484700DE74AB /* StoreBranch7+Schema.swift */, + 213B96E52BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift */, + ); + path = Gen2_7; + sourceTree = ""; + }; + 213B96E72BF44DCD00DE74AB /* Gen2_8 */ = { + isa = PBXGroup; + children = ( + 213B96F02BF4500200DE74AB /* Customer8.swift */, + 213B96F12BF4500200DE74AB /* Customer8+Schema.swift */, + 213B96E82BF44DE600DE74AB /* GraphQLCustomer8Tests.swift */, + ); + path = Gen2_8; + sourceTree = ""; + }; + 213B96EA2BF44F2800DE74AB /* Gen2_9 */ = { + isa = PBXGroup; + children = ( + 213B96F42BF4500D00DE74AB /* Customer9.swift */, + 213B96F52BF4500D00DE74AB /* Customer9+Schema.swift */, + 213B96EC2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift */, + ); + path = Gen2_9; + sourceTree = ""; + }; + 213B96EB2BF44F3400DE74AB /* Gen2_10 */ = { + isa = PBXGroup; + children = ( + 213B96F82BF4501B00DE74AB /* Customer10.swift */, + 213B96F92BF4501B00DE74AB /* Customer10+Schema.swift */, + 213B96EE2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift */, + ); + path = Gen2_10; + sourceTree = ""; + }; + 213B96FC2BF4531100DE74AB /* Gen2_41 */ = { + isa = PBXGroup; + children = ( + 213B970C2BF4F1E800DE74AB /* Person41.swift */, + 213B970D2BF4F1E800DE74AB /* Person41+Schema.swift */, + 213B970E2BF4F1E800DE74AB /* Post41.swift */, + 213B970B2BF4F1E800DE74AB /* Post41+Schema.swift */, + 213B96FD2BF4533500DE74AB /* GraphQLPostPerson41Tests.swift */, + ); + path = Gen2_41; + sourceTree = ""; + }; 213DBC7628A6C47000B30280 /* AWSAPIPluginGraphQLLambdaAuthTests */ = { isa = PBXGroup; children = ( @@ -934,9 +1149,20 @@ 2163D60D2BE96C90009689B1 /* AWSAPIPluginGen2GraphQLTests */ = { isa = PBXGroup; children = ( - 2163D6192BE97476009689B1 /* LL3 */, - 2163D6182BE9740B009689B1 /* LL1 */, 2163D60E2BE96C90009689B1 /* AWSAPIPluginGen2GraphQLBaseTest.swift */, + 213B96962BF3B62C00DE74AB /* Gen2_1 */, + 213B96942BF3B5EA00DE74AB /* Gen2_2 */, + 213B96952BF3B62200DE74AB /* Gen2_3 */, + 213B96972BF3B63600DE74AB /* Gen2_4 */, + 213B96FC2BF4531100DE74AB /* Gen2_41 */, + 213B96982BF3B63E00DE74AB /* Gen2_5 */, + 213B96D72BF4480E00DE74AB /* Gen2_6 */, + 213B96DC2BF4482D00DE74AB /* Gen2_7 */, + 213B96E72BF44DCD00DE74AB /* Gen2_8 */, + 213B96EA2BF44F2800DE74AB /* Gen2_9 */, + 213B96EB2BF44F3400DE74AB /* Gen2_10 */, + 2163D6182BE9740B009689B1 /* LL1 */, + 2163D6192BE97476009689B1 /* LL3 */, 2163D6152BE96D12009689B1 /* README.md */, 2163D6162BE96E3D009689B1 /* TestConfigHelper.swift */, ); @@ -2249,18 +2475,64 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 213B96AE2BF3B67500DE74AB /* Post1+Schema.swift in Sources */, + 213B970F2BF4F1E800DE74AB /* Post41+Schema.swift in Sources */, + 213B96D52BF4480900DE74AB /* Todo5.swift in Sources */, + 213B96F72BF4500D00DE74AB /* Customer9+Schema.swift in Sources */, + 213B969F2BF3B65800DE74AB /* Video2.swift in Sources */, + 213B96CE2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift in Sources */, + 213B96F22BF4500200DE74AB /* Customer8.swift in Sources */, 2163D61B2BE97494009689B1 /* GraphQLLazyLoadPostComment4V2Tests.swift in Sources */, + 213B96E92BF44DE600DE74AB /* GraphQLCustomer8Tests.swift in Sources */, + 213B96D02BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift in Sources */, + 213B97112BF4F1E800DE74AB /* Person41+Schema.swift in Sources */, + 213B96B32BF3B6C100DE74AB /* Team3+Schema.swift in Sources */, + 213B96F62BF4500D00DE74AB /* Customer9.swift in Sources */, + 213B96DF2BF4484700DE74AB /* StoreBranch7.swift in Sources */, + 213B97122BF4F1E800DE74AB /* Post41.swift in Sources */, + 213B97102BF4F1E800DE74AB /* Person41.swift in Sources */, + 213B96D62BF4480900DE74AB /* Todo5+Schema.swift in Sources */, 2163D60F2BE96C90009689B1 /* AWSAPIPluginGen2GraphQLBaseTest.swift in Sources */, 2163D62D2BE974E6009689B1 /* PostWithCompositeKey+Schema.swift in Sources */, + 213B96FB2BF4501B00DE74AB /* Customer10+Schema.swift in Sources */, + 213B96A92BF3B67500DE74AB /* Location1.swift in Sources */, + 213B96BC2BF3B6D400DE74AB /* Cart4.swift in Sources */, 2163D6252BE974D8009689B1 /* Comment4V2.swift in Sources */, + 213B96BD2BF3B6D400DE74AB /* Cart4+Schema.swift in Sources */, 2163D6242BE974D8009689B1 /* Post4V2.swift in Sources */, + 213B96AD2BF3B67500DE74AB /* Location1+Schema.swift in Sources */, + 213B96BE2BF3B6D400DE74AB /* Customer4+Schema.swift in Sources */, + 213B96ED2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift in Sources */, 2163D6172BE96E3D009689B1 /* TestConfigHelper.swift in Sources */, + 213B96B42BF3B6C100DE74AB /* Member3.swift in Sources */, 2163D62A2BE974E6009689B1 /* PostWithCompositeKey.swift in Sources */, + 213B96E62BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift in Sources */, + 213B969E2BF3B65800DE74AB /* Post2+Schema.swift in Sources */, 2163D61D2BE974B0009689B1 /* GraphQLLazyLoadPostCommentWithCompositeKeyTests.swift in Sources */, + 213B96F32BF4500200DE74AB /* Customer8+Schema.swift in Sources */, + 213B96DB2BF4481F00DE74AB /* Todo6.swift in Sources */, + 213B96E42BF4492400DE74AB /* GraphQLTodo6Tests.swift in Sources */, 2163D62C2BE974E6009689B1 /* CommentWithCompositeKey+Schema.swift in Sources */, + 213B96BB2BF3B6D400DE74AB /* Customer4.swift in Sources */, + 213B96FE2BF4533500DE74AB /* GraphQLPostPerson41Tests.swift in Sources */, + 213B96CC2BF3BA2300DE74AB /* GraphQLLocationPostUser1Tests.swift in Sources */, + 213B96E22BF4486900DE74AB /* GraphQLTodo5Tests.swift in Sources */, + 213B96DA2BF4481F00DE74AB /* Todo6+Schema.swift in Sources */, + 213B96D22BF3EFD000DE74AB /* GraphQLCartCustomer4Tests.swift in Sources */, 2163D62B2BE974E6009689B1 /* CommentWithCompositeKey.swift in Sources */, + 213B96B62BF3B6C100DE74AB /* Team3.swift in Sources */, + 213B96AB2BF3B67500DE74AB /* Post1.swift in Sources */, + 213B96B52BF3B6C100DE74AB /* Member3+Schema.swift in Sources */, + 213B96FA2BF4501B00DE74AB /* Customer10.swift in Sources */, + 213B96E02BF4484700DE74AB /* StoreBranch7+Schema.swift in Sources */, + 213B96AA2BF3B67500DE74AB /* User1.swift in Sources */, 2163D6222BE974D8009689B1 /* Comment4V2+Schema.swift in Sources */, + 213B96A02BF3B65800DE74AB /* PrivacySetting2.swift in Sources */, + 213B96A22BF3B65800DE74AB /* Video2+Schema.swift in Sources */, + 213B96A12BF3B65800DE74AB /* Post2.swift in Sources */, 2163D6232BE974D8009689B1 /* Post4V2+Schema.swift in Sources */, + 213B96AC2BF3B67500DE74AB /* User1+Schema.swift in Sources */, + 213B96EF2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/GraphQLLocationPostUser1Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/GraphQLLocationPostUser1Tests.swift new file mode 100644 index 0000000000..65fdc898ab --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/GraphQLLocationPostUser1Tests.swift @@ -0,0 +1,45 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLLocationPostUser1Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-an-enum-field-type + func testCodeSnippet() async throws { + await setup(withModels: PostUserLocation1Models()) + + let post = Post( + location: .init( + lat: 48.837006, + long: 8.28245)) + let createdPost = try await Amplify.API.mutate(request: .create(post)).get() + print("\(createdPost)") + + XCTAssertEqual(createdPost.location?.lat, 48.837006) + XCTAssertEqual(createdPost.location?.long, 8.28245) + } +} + +extension GraphQLLocationPostUser1Tests: DefaultLogger { } + +extension GraphQLLocationPostUser1Tests { + typealias Post = Post1 + typealias User = User1 + typealias Location = Location1 + + struct PostUserLocation1Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Post1.self) + ModelRegistry.register(modelType: User1.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1+Schema.swift new file mode 100644 index 0000000000..c3ecfd312c --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1+Schema.swift @@ -0,0 +1,26 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Location1 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case lat + case long + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let location1 = Location1.keys + + model.listPluralName = "Location1s" + model.syncPluralName = "Location1s" + + model.fields( + .field(location1.lat, is: .optional, ofType: .double), + .field(location1.long, is: .optional, ofType: .double) + ) + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1.swift new file mode 100644 index 0000000000..c7bb5ace84 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Location1.swift @@ -0,0 +1,8 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Location1: Embeddable { + var lat: Double? + var long: Double? +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1+Schema.swift new file mode 100644 index 0000000000..d6d325cb6d --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1+Schema.swift @@ -0,0 +1,62 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Post1 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case location + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post1 = Post1.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Post1s" + model.syncPluralName = "Post1s" + + model.attributes( + .primaryKey(fields: [post1.id]) + ) + + model.fields( + .field(post1.id, is: .required, ofType: .string), + .field(post1.location, is: .optional, ofType: .embedded(type: Location1.self)), + .field(post1.content, is: .optional, ofType: .string), + .field(post1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post1: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post1 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1.swift new file mode 100644 index 0000000000..49096a3269 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/Post1.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Post1: Model { + public let id: String + public var location: Location1? + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + location: Location1? = nil, + content: String? = nil) { + self.init(id: id, + location: location, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + location: Location1? = nil, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.location = location + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1+Schema.swift new file mode 100644 index 0000000000..cf451f68a5 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1+Schema.swift @@ -0,0 +1,57 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension User1 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case lastKnownLocation + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let user1 = User1.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "User1s" + model.syncPluralName = "User1s" + + model.attributes( + .primaryKey(fields: [user1.id]) + ) + + model.fields( + .field(user1.id, is: .required, ofType: .string), + .field(user1.lastKnownLocation, is: .optional, ofType: .embedded(type: Location1.self)), + .field(user1.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(user1.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension User1: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == User1 { + public var id: FieldPath { + string("id") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1.swift new file mode 100644 index 0000000000..fffb5a42e5 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_1/User1.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct User1: Model { + public let id: String + public var lastKnownLocation: Location1? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + lastKnownLocation: Location1? = nil) { + self.init(id: id, + lastKnownLocation: lastKnownLocation, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + lastKnownLocation: Location1? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.lastKnownLocation = lastKnownLocation + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10+Schema.swift new file mode 100644 index 0000000000..089a6a3d61 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10+Schema.swift @@ -0,0 +1,71 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Customer10 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case phoneNumber + case accountRepresentativeId + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let customer10 = Customer10.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Customer10s" + model.syncPluralName = "Customer10s" + + model.attributes( + .index(fields: ["accountRepresentativeId"], name: "customer10sByAccountRepresentativeId"), + .primaryKey(fields: [customer10.id]) + ) + + model.fields( + .field(customer10.id, is: .required, ofType: .string), + .field(customer10.name, is: .optional, ofType: .string), + .field(customer10.phoneNumber, is: .optional, ofType: .string), + .field(customer10.accountRepresentativeId, is: .required, ofType: .string), + .field(customer10.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(customer10.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Customer10: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Customer10 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var phoneNumber: FieldPath { + string("phoneNumber") + } + public var accountRepresentativeId: FieldPath { + string("accountRepresentativeId") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10.swift new file mode 100644 index 0000000000..5d5d2a959b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/Customer10.swift @@ -0,0 +1,37 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Customer10: Model { + public let id: String + public var name: String? + public var phoneNumber: String? + public var accountRepresentativeId: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String) { + self.init(id: id, + name: name, + phoneNumber: phoneNumber, + accountRepresentativeId: accountRepresentativeId, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.phoneNumber = phoneNumber + self.accountRepresentativeId = accountRepresentativeId + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/GraphQLCustomer10Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/GraphQLCustomer10Tests.swift new file mode 100644 index 0000000000..80cacd0df2 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_10/GraphQLCustomer10Tests.swift @@ -0,0 +1,73 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + + +import Foundation +import Combine +import XCTest + +@testable import Amplify +import AWSPluginsCore + +final class GraphQLCustomer10Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/ + func testCodeSnippet() async throws { + await setup(withModels: Customer10Models()) + + let accountRepresentativeId = UUID().uuidString + let customer = Customer(accountRepresentativeId: accountRepresentativeId) + _ = try await Amplify.API.mutate(request: .create(customer)) + + // Code Snippet Begins + struct PaginatedList: Decodable { + let items: [ModelType] + let nextToken: String? + } + let operationName = "listByRep" + let document = """ + query ListByRep { + \(operationName)(accountRepresentativeId: "\(accountRepresentativeId)") { + items { + accountRepresentativeId + createdAt + id + name + phoneNumber + updatedAt + } + nextToken + } + } + """ + + let request = GraphQLRequest>( + document: document, + responseType: PaginatedList.self, + decodePath: operationName) + + let queriedCustomers = try await Amplify.API.query( + request: request).get() + + // Code Snippet Ends + XCTAssertTrue(queriedCustomers.items.count != 0 || queriedCustomers.nextToken != nil) + } +} + +extension GraphQLCustomer10Tests: DefaultLogger { } + +extension GraphQLCustomer10Tests { + typealias Customer = Customer10 + + struct Customer10Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Customer10.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/GraphQLPostVideoPrivacySetting2Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/GraphQLPostVideoPrivacySetting2Tests.swift new file mode 100644 index 0000000000..45d7c66a1b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/GraphQLPostVideoPrivacySetting2Tests.swift @@ -0,0 +1,43 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLPostVideoPrivacySettings2Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type + func testCreate() async throws { + await setup(withModels: PostVideoPrivacySettings2Models()) + + // Code Snippet Begins + let post = Post( + content: "hello", + privacySetting: .private) + let createdPost = try await Amplify.API.mutate(request: .create(post)).get() + + // Code Snippet Ends + XCTAssertEqual(createdPost.id, post.id) + } +} + +extension GraphQLPostVideoPrivacySettings2Tests: DefaultLogger { } + +extension GraphQLPostVideoPrivacySettings2Tests { + typealias Post = Post2 + typealias Video = Video2 + + struct PostVideoPrivacySettings2Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Post2.self) + ModelRegistry.register(modelType: Video2.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2+Schema.swift new file mode 100644 index 0000000000..f8aaae10fc --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2+Schema.swift @@ -0,0 +1,62 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Post2 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case privacySetting + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post2 = Post2.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Post2s" + model.syncPluralName = "Post2s" + + model.attributes( + .primaryKey(fields: [post2.id]) + ) + + model.fields( + .field(post2.id, is: .required, ofType: .string), + .field(post2.content, is: .optional, ofType: .string), + .field(post2.privacySetting, is: .optional, ofType: .enum(type: PrivacySetting2.self)), + .field(post2.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post2.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post2: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post2 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2.swift new file mode 100644 index 0000000000..9ed7b58d6b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Post2.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Post2: Model { + public let id: String + public var content: String? + public var privacySetting: PrivacySetting2? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil, + privacySetting: PrivacySetting2? = nil) { + self.init(id: id, + content: content, + privacySetting: privacySetting, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + privacySetting: PrivacySetting2? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.privacySetting = privacySetting + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/PrivacySetting2.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/PrivacySetting2.swift new file mode 100644 index 0000000000..a3cbe56cc4 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/PrivacySetting2.swift @@ -0,0 +1,9 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public enum PrivacySetting2: String, EnumPersistable { + case `private` = "PRIVATE" + case friendsOnly = "FRIENDS_ONLY" + case `public` = "PUBLIC" +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2+Schema.swift new file mode 100644 index 0000000000..ae333846a0 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2+Schema.swift @@ -0,0 +1,57 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Video2 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case privacySetting + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let video2 = Video2.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Video2s" + model.syncPluralName = "Video2s" + + model.attributes( + .primaryKey(fields: [video2.id]) + ) + + model.fields( + .field(video2.id, is: .required, ofType: .string), + .field(video2.privacySetting, is: .optional, ofType: .enum(type: PrivacySetting2.self)), + .field(video2.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(video2.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Video2: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Video2 { + public var id: FieldPath { + string("id") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2.swift new file mode 100644 index 0000000000..c066eefa31 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_2/Video2.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Video2: Model { + public let id: String + public var privacySetting: PrivacySetting2? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + privacySetting: PrivacySetting2? = nil) { + self.init(id: id, + privacySetting: privacySetting, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + privacySetting: PrivacySetting2? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.privacySetting = privacySetting + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/GraphQLTeamMember3Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/GraphQLTeamMember3Tests.swift new file mode 100644 index 0000000000..1ae35afd0d --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/GraphQLTeamMember3Tests.swift @@ -0,0 +1,187 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest + +@testable import Amplify + +final class GraphQLTeamMember3Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#create-a-has-many-relationship-between-records + func testCreate() async throws { + await setup(withModels: TeamMember3Models()) + + // Code Snippet Begins + do { + let team = Team(mantra: "Go Frontend!") + let createdTeam = try await Amplify.API.mutate(request: .create(team)).get() + + let member = Member( + name: "Tim", + team: createdTeam) // Directly pass in the team instance + let createdMember = try await Amplify.API.mutate(request: .create(member)) + } catch { + print("Create team or member failed", error) + + // Code Snippet Ends + XCTFail("Failed to create team or member, error: \(error)") + // Code Snippet Begins + } + + } + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#update-a-has-many-relationship-between-records + func testUpdate() async throws { + await setup(withModels: TeamMember3Models()) + + let oldTeam = Team(mantra: "Go Frontend!") + let oldTeamCreated = try await Amplify.API.mutate(request: .create(oldTeam)).get() + let member = Member( + name: "Tim", + team: oldTeamCreated) // Directly pass in the post instance + var existingMember = try await Amplify.API.mutate(request: .create(member)).get() + + // Code Snippet Begins + do { + let newTeam = Team(mantra: "Go Fullstack!") + let createdNewTeam = try await Amplify.API.mutate(request: .create(newTeam)).get() + + existingMember.setTeam(createdNewTeam) + let updatedMember = try await Amplify.API.mutate(request: .update(existingMember)).get() + + // Code Snippet Ends + guard let loadedTeam = try await updatedMember.team else { + XCTFail("Could not get team from member") + return + } + XCTAssertEqual(loadedTeam.id, newTeam.id) + // Code Snippet Begins + } catch { + print("Create team or update member failed", error) + + // Code Snippet Ends + XCTFail("Failed to create team or update member to new team, error: \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#delete-a-has-many-relationship-between-records + func testDelete() async throws { + await setup(withModels: TeamMember3Models()) + let team = Team(mantra: "Go Frontend!") + let teamCreated = try await Amplify.API.mutate(request: .create(team)).get() + let member = Member( + name: "Tim", + team: teamCreated) // Directly pass in the post instance + var existingMember = try await Amplify.API.mutate(request: .create(member)).get() + + // Code Snippet Begins + do { + existingMember.setTeam(nil) + _ = try await Amplify.API.mutate(request: .update(existingMember)).get() + } catch { + print("Failed to remove team from member", error) + // Code Snippet Ends + XCTFail("Failed to remove team from member \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#lazy-load-a-has-many-relationship + func testLazyLoadHasMany() async throws { + await setup(withModels: TeamMember3Models()) + let team = Team(mantra: "Go Frontend!") + let teamCreated = try await Amplify.API.mutate(request: .create(team)).get() + let member = Member( + name: "Tim", + team: teamCreated) // Directly pass in the post instance + _ = try await Amplify.API.mutate(request: .create(member)).get() + + // Code Snippet Begins + do { + let queriedTeam = try await Amplify.API.query( + request: .get( + Team.self, + byIdentifier: team.identifier)).get() + + guard let queriedTeam, let members = queriedTeam.members else { + print("Missing team or members") + // Code Snippet Ends + XCTFail("Missing team or its members") + // Code Snippet Begins + return + } + try await members.fetch() + print("Number of members: \(members.count)") + // Code Snippet Ends + XCTAssertTrue(members.count > 0) + // Code Snippet Begins + } catch { + print("Failed to fetch team or members", error) + // Code Snippet Ends + XCTFail("Failed to fetch team or members \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#eagerly-load-a-has-many-relationship + func testEagerLoadHasMany() async throws { + await setup(withModels: TeamMember3Models()) + let team = Team(mantra: "Go Frontend!") + let teamCreated = try await Amplify.API.mutate(request: .create(team)).get() + let member = Member( + name: "Tim", + team: teamCreated) // Directly pass in the post instance + _ = try await Amplify.API.mutate(request: .create(member)).get() + + // Code Snippet Begins + do { + let queriedTeamWithMembers = try await Amplify.API.query( + request: .get( + Team.self, + byIdentifier: team.identifier, + includes: { team in [team.members]})) + .get() + guard let queriedTeamWithMembers, let members = queriedTeamWithMembers.members else { + print("Missing team or members") + // Code Snippet Ends + XCTFail("Missing team or its members") + // Code Snippet Begins + return + } + print("Number of members: \(members.count)") + // Code Snippet Ends + XCTAssertTrue(members.count > 0) + // Code Snippet Begins + } catch { + print("Failed to fetch team with members", error) + // Code Snippet Ends + XCTFail("Failed to fetch team with members \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTeamMember3Tests: DefaultLogger { } + +extension GraphQLTeamMember3Tests { + typealias Team = Team3 + typealias Member = Member3 + + struct TeamMember3Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Team3.self) + ModelRegistry.register(modelType: Member3.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3+Schema.swift new file mode 100644 index 0000000000..e288a808c0 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Member3 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case team + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let member3 = Member3.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Member3s" + model.syncPluralName = "Member3s" + + model.attributes( + .primaryKey(fields: [member3.id]) + ) + + model.fields( + .field(member3.id, is: .required, ofType: .string), + .field(member3.name, is: .required, ofType: .string), + .belongsTo(member3.team, is: .optional, ofType: Team3.self, targetNames: ["teamId"]), + .field(member3.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(member3.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Member3: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Member3 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var team: ModelPath { + Team3.Path(name: "team", parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3.swift new file mode 100644 index 0000000000..10f6c94442 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Member3.swift @@ -0,0 +1,56 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Member3: Model { + public let id: String + public var name: String + internal var _team: LazyReference + public var team: Team3? { + get async throws { + try await _team.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String, + team: Team3? = nil) { + self.init(id: id, + name: name, + team: team, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String, + team: Team3? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self._team = LazyReference(team) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setTeam(_ team: Team3? = nil) { + self._team = LazyReference(team) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + name = try values.decode(String.self, forKey: .name) + _team = try values.decodeIfPresent(LazyReference.self, forKey: .team) ?? 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(name, forKey: .name) + try container.encode(_team, forKey: .team) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3+Schema.swift new file mode 100644 index 0000000000..b09f9b50ea --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Team3 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case mantra + case members + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let team3 = Team3.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Team3s" + model.syncPluralName = "Team3s" + + model.attributes( + .primaryKey(fields: [team3.id]) + ) + + model.fields( + .field(team3.id, is: .required, ofType: .string), + .field(team3.mantra, is: .required, ofType: .string), + .hasMany(team3.members, is: .optional, ofType: Member3.self, associatedFields: [Member3.keys.team]), + .field(team3.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(team3.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Team3: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Team3 { + public var id: FieldPath { + string("id") + } + public var mantra: FieldPath { + string("mantra") + } + public var members: ModelPath { + Member3.Path(name: "members", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3.swift new file mode 100644 index 0000000000..2cf2dba585 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_3/Team3.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Team3: Model { + public let id: String + public var mantra: String + public var members: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + mantra: String, + members: List? = []) { + self.init(id: id, + mantra: mantra, + members: members, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + mantra: String, + members: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.mantra = mantra + self.members = members + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4+Schema.swift new file mode 100644 index 0000000000..f524ceab99 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Cart4 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case items + case customer + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let cart4 = Cart4.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Cart4s" + model.syncPluralName = "Cart4s" + + model.attributes( + .primaryKey(fields: [cart4.id]) + ) + + model.fields( + .field(cart4.id, is: .required, ofType: .string), + .field(cart4.items, is: .optional, ofType: .embeddedCollection(of: String.self)), + .belongsTo(cart4.customer, is: .optional, ofType: Customer4.self, targetNames: ["customerId"]), + .field(cart4.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(cart4.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Cart4: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Cart4 { + public var id: FieldPath { + string("id") + } + public var items: FieldPath { + string("items") + } + public var customer: ModelPath { + Customer4.Path(name: "customer", parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4.swift new file mode 100644 index 0000000000..31d636fd1e --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Cart4.swift @@ -0,0 +1,56 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Cart4: Model { + public let id: String + public var items: [String]? + internal var _customer: LazyReference + public var customer: Customer4? { + get async throws { + try await _customer.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + items: [String]? = nil, + customer: Customer4? = nil) { + self.init(id: id, + items: items, + customer: customer, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + items: [String]? = nil, + customer: Customer4? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.items = items + self._customer = LazyReference(customer) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setCustomer(_ customer: Customer4? = nil) { + self._customer = LazyReference(customer) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + items = try values.decode([String].self, forKey: .items) + _customer = try values.decodeIfPresent(LazyReference.self, forKey: .customer) ?? 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(items, forKey: .items) + try container.encode(_customer, forKey: .customer) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4+Schema.swift new file mode 100644 index 0000000000..b153fe844f --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Customer4 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case activeCart + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let customer4 = Customer4.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Customer4s" + model.syncPluralName = "Customer4s" + + model.attributes( + .primaryKey(fields: [customer4.id]) + ) + + model.fields( + .field(customer4.id, is: .required, ofType: .string), + .field(customer4.name, is: .optional, ofType: .string), + .hasOne(customer4.activeCart, is: .optional, ofType: Cart4.self, associatedWith: Cart4.keys.customer), + .field(customer4.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(customer4.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Customer4: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Customer4 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var activeCart: ModelPath { + Cart4.Path(name: "activeCart", parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4.swift new file mode 100644 index 0000000000..13ee66321a --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Customer4.swift @@ -0,0 +1,56 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Customer4: Model { + public let id: String + public var name: String? + internal var _activeCart: LazyReference + public var activeCart: Cart4? { + get async throws { + try await _activeCart.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String? = nil, + activeCart: Cart4? = nil) { + self.init(id: id, + name: name, + activeCart: activeCart, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String? = nil, + activeCart: Cart4? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self._activeCart = LazyReference(activeCart) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setActiveCart(_ activeCart: Cart4? = nil) { + self._activeCart = LazyReference(activeCart) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + name = try? values.decode(String?.self, forKey: .name) + _activeCart = try values.decodeIfPresent(LazyReference.self, forKey: .activeCart) ?? 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(name, forKey: .name) + try container.encode(_activeCart, forKey: .activeCart) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/GraphQLCartCustomer4Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/GraphQLCartCustomer4Tests.swift new file mode 100644 index 0000000000..da49e94714 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/GraphQLCartCustomer4Tests.swift @@ -0,0 +1,151 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLCartCustomer4Tests: AWSAPIPluginGen2GraphQLBaseTest { + + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#create-a-has-one-relationship-between-records + func testCreate() async throws { + await setup(withModels: CartCustomer4Models()) + + // Code Snippet Begins + do { + let customer = Customer(name: "Rene") + let createdCustomer = try await Amplify.API.mutate(request: .create(customer)).get() + + let cart = Cart( + items: ["Tomato", "Ice", "Mint"], + customer: createdCustomer) + let createdCart = try await Amplify.API.mutate(request: .create(cart)).get() + + // Code Snippet Ends + let loadedCustomer = try await createdCart.customer + XCTAssertEqual(loadedCustomer?.id, customer.id) + // Code Snippet Begins + } catch { + print("Create customer or cart failed", error) + // Code Snippet Ends + XCTFail("Create customer or cart failed \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#update-a-has-one-relationship-between-records + func testUpdate() async throws { + await setup(withModels: CartCustomer4Models()) + let customer = Customer(name: "Rene") + let createdCustomer = try await Amplify.API.mutate(request: .create(customer)).get() + let cart = Cart( + items: ["Tomato", "Ice", "Mint"], + customer: createdCustomer) + var existingCart = try await Amplify.API.mutate(request: .create(cart)).get() + + // Code Snippet Begins + do { + let newCustomer = Customer(name: "Rene") + let newCustomerCreated = try await Amplify.API.mutate(request: .create(newCustomer)).get() + existingCart.setCustomer(newCustomerCreated) + let updatedCart = try await Amplify.API.mutate(request: .update(existingCart)).get() + + // Code Snippet Ends + let loadedCustomer = try await updatedCart.customer + XCTAssertEqual(loadedCustomer?.id, newCustomerCreated.id) + // Code Snippet Begins + } catch { + print("Create customer or cart failed", error) + // Code Snippet Ends + XCTFail("Create customer or cart failed \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#delete-a-has-one-relationship-between-records + func testDelete() async throws { + await setup(withModels: CartCustomer4Models()) + let customer = Customer(name: "Rene") + let createdCustomer = try await Amplify.API.mutate(request: .create(customer)).get() + let cart = Cart( + items: ["Tomato", "Ice", "Mint"], + customer: createdCustomer) + var existingCart = try await Amplify.API.mutate(request: .create(cart)).get() + + // Code Snippet Begins + do { + existingCart.setCustomer(nil) + let cartWithCustomerRemoved = try await Amplify.API.mutate(request: .update(existingCart)).get() + + // Code Snippet Ends + let loadedCustomer = try await cartWithCustomerRemoved.customer + XCTAssertNil(loadedCustomer) + // Code Snippet Begins + } catch { + print("Failed to remove customer from cart", error) + // Code Snippet Ends + XCTFail("Failed to remove customer from cart \(error)") + // Code Snippet Begins + } + } + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#delete-a-has-one-relationship-between-records + func testLoadHasOne() async throws { + await setup(withModels: CartCustomer4Models()) + let customer = Customer(name: "Rene") + let createdCustomer = try await Amplify.API.mutate(request: .create(customer)).get() + let cart = Cart( + items: ["Tomato", "Ice", "Mint"], + customer: createdCustomer) + var existingCart = try await Amplify.API.mutate(request: .create(cart)).get() + + // Code Snippet Begins + do { + guard let queriedCart = try await Amplify.API.query( + request: .get( + Cart.self, + byIdentifier: existingCart.identifier)).get() else { + print("Missing cart") + // Code Snippet Ends + XCTFail("Missing cart") + // Code Snippet Begins + return + } + + let customer = try await queriedCart.customer + + // Code Snippet Ends + XCTAssertNotNil(customer) + // Code Snippet Begins + } catch { + print("Failed to fetch cart or customer", error) + // Code Snippet Ends + XCTFail("Failed to fetch cart or customer \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLCartCustomer4Tests: DefaultLogger { } + +extension GraphQLCartCustomer4Tests { + typealias Cart = Cart4 + typealias Customer = Customer4 + + struct CartCustomer4Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Cart4.self) + ModelRegistry.register(modelType: Customer4.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift new file mode 100644 index 0000000000..603ad7a259 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift @@ -0,0 +1,71 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLPostPerson41Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/ + func testCodeSnippet() async throws { + await setup(withModels: PostPerson41Models()) + + let author = Person() + _ = try await Amplify.API.mutate(request: .create(author)) + let editor = Person() + _ = try await Amplify.API.mutate(request: .create(editor)) + let post = Post( + title: "title", + content: "content", + author: author, + editor: editor) + _ = try await Amplify.API.mutate(request: .create(post)) + + // Code Snippet Begins + do { + guard let queriedPost = try await Amplify.API.query( + request: .get( + Post.self, + byIdentifier: post.identifier)).get() else { + print("Missing post") + // Code Snippet Ends + XCTFail("Missing post") + // Code Snippet Begins + return + } + + let loadedAuthor = try await queriedPost.author + let loadedEditor = try await queriedPost.editor + // Code Snippet Ends + XCTAssertEqual(loadedAuthor?.id, author.id) + XCTAssertEqual(loadedEditor?.id, editor.id) + // Code Snippet Begins + } catch { + print("Failed to fetch post, author, or editor", error) + // Code Snippet Ends + XCTFail("Failed to fetch post, author, or editor \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLPostPerson41Tests: DefaultLogger { } + +extension GraphQLPostPerson41Tests { + typealias Post = Post41 + typealias Person = Person41 + + struct PostPerson41Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Post41.self) + ModelRegistry.register(modelType: Person41.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift new file mode 100644 index 0000000000..67f028ed2e --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift @@ -0,0 +1,70 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Person41 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case editedPosts + case authoredPosts + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let person41 = Person41.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Person41s" + model.syncPluralName = "Person41s" + + model.attributes( + .primaryKey(fields: [person41.id]) + ) + + model.fields( + .field(person41.id, is: .required, ofType: .string), + .field(person41.name, is: .optional, ofType: .string), + .hasMany(person41.editedPosts, is: .optional, ofType: Post41.self, associatedFields: [Post41.keys.editor]), + .hasMany(person41.authoredPosts, is: .optional, ofType: Post41.self, associatedFields: [Post41.keys.author]), + .field(person41.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(person41.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Person41: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Person41 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var editedPosts: ModelPath { + Post41.Path(name: "editedPosts", isCollection: true, parent: self) + } + public var authoredPosts: ModelPath { + Post41.Path(name: "authoredPosts", isCollection: true, parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift new file mode 100644 index 0000000000..4c7858347c --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift @@ -0,0 +1,37 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Person41: Model { + public let id: String + public var name: String? + public var editedPosts: List? + public var authoredPosts: List? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String? = nil, + editedPosts: List? = [], + authoredPosts: List? = []) { + self.init(id: id, + name: name, + editedPosts: editedPosts, + authoredPosts: authoredPosts, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String? = nil, + editedPosts: List? = [], + authoredPosts: List? = [], + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.editedPosts = editedPosts + self.authoredPosts = authoredPosts + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift new file mode 100644 index 0000000000..4fb0d7e363 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift @@ -0,0 +1,75 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Post41 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case content + case author + case editor + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post41 = Post41.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Post41s" + model.syncPluralName = "Post41s" + + model.attributes( + .primaryKey(fields: [post41.id]) + ) + + model.fields( + .field(post41.id, is: .required, ofType: .string), + .field(post41.title, is: .required, ofType: .string), + .field(post41.content, is: .required, ofType: .string), + .belongsTo(post41.author, is: .optional, ofType: Person41.self, targetNames: ["authorId"]), + .belongsTo(post41.editor, is: .optional, ofType: Person41.self, targetNames: ["editorId"]), + .field(post41.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post41.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post41: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post41 { + public var id: FieldPath { + string("id") + } + public var title: FieldPath { + string("title") + } + public var content: FieldPath { + string("content") + } + public var author: ModelPath { + Person41.Path(name: "author", parent: self) + } + public var editor: ModelPath { + Person41.Path(name: "editor", parent: self) + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift new file mode 100644 index 0000000000..f81d4ebb4c --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift @@ -0,0 +1,78 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Post41: Model { + public let id: String + public var title: String + public var content: String + internal var _author: LazyReference + public var author: Person41? { + get async throws { + try await _author.get() + } + } + internal var _editor: LazyReference + public var editor: Person41? { + get async throws { + try await _editor.get() + } + } + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String, + content: String, + author: Person41? = nil, + editor: Person41? = nil) { + self.init(id: id, + title: title, + content: content, + author: author, + editor: editor, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String, + content: String, + author: Person41? = nil, + editor: Person41? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self.content = content + self._author = LazyReference(author) + self._editor = LazyReference(editor) + self.createdAt = createdAt + self.updatedAt = updatedAt + } + public mutating func setAuthor(_ author: Person41? = nil) { + self._author = LazyReference(author) + } + public mutating func setEditor(_ editor: Person41? = nil) { + self._editor = LazyReference(editor) + } + public init(from decoder: Decoder) throws { + let values = try decoder.container(keyedBy: CodingKeys.self) + id = try values.decode(String.self, forKey: .id) + title = try values.decode(String.self, forKey: .title) + content = try values.decode(String.self, forKey: .content) + _author = try values.decodeIfPresent(LazyReference.self, forKey: .author) ?? LazyReference(identifiers: nil) + _editor = try values.decodeIfPresent(LazyReference.self, forKey: .editor) ?? 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(title, forKey: .title) + try container.encode(content, forKey: .content) + try container.encode(_author, forKey: .author) + try container.encode(_editor, forKey: .editor) + try container.encode(createdAt, forKey: .createdAt) + try container.encode(updatedAt, forKey: .updatedAt) + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/GraphQLTodo5Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/GraphQLTodo5Tests.swift new file mode 100644 index 0000000000..24213e89e3 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/GraphQLTodo5Tests.swift @@ -0,0 +1,42 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest + +@testable import Amplify + +final class GraphQLTodo5Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/ + func testCodeSnippet() async throws { + await setup(withModels: Todo5Models()) + + // Code Snippet Begins + let todo = Todo( + content: "Buy Milk", + completed: false) + let createdTodo = try await Amplify.API.mutate(request: .create(todo)).get() + print("New Todo created: \(createdTodo)") + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + } +} + +extension GraphQLTodo5Tests: DefaultLogger { } + +extension GraphQLTodo5Tests { + typealias Todo = Todo5 + + struct Todo5Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo5.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5+Schema.swift new file mode 100644 index 0000000000..74023717f2 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo5 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case completed + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo5 = Todo5.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo5s" + model.syncPluralName = "Todo5s" + + model.attributes( + .primaryKey(fields: [todo5.id]) + ) + + model.fields( + .field(todo5.id, is: .required, ofType: .string), + .field(todo5.content, is: .optional, ofType: .string), + .field(todo5.completed, is: .optional, ofType: .bool), + .field(todo5.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo5.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo5: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo5 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var completed: FieldPath { + bool("completed") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5.swift new file mode 100644 index 0000000000..d10de7e4e0 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_5/Todo5.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo5: Model { + public let id: String + public var content: String? + public var completed: Bool? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil, + completed: Bool? = nil) { + self.init(id: id, + content: content, + completed: completed, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + completed: Bool? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.completed = completed + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/GraphQLTodo6Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/GraphQLTodo6Tests.swift new file mode 100644 index 0000000000..82b8c32ca1 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/GraphQLTodo6Tests.swift @@ -0,0 +1,44 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo6Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/#single-field-identifier + func testCodeSnippet() async throws { + await setup(withModels: Todo6Models()) + + do { + // Code Snippet Begins + let todo = Todo( + todoId: "MyUniqueTodoId", + content: "Buy Milk", + completed: false) + let createdTodo = try await Amplify.API.mutate(request: .create(todo)).get() + print("New Todo created: \(createdTodo)") + // Code Snippet Ends + } catch { + } + } +} + +extension GraphQLTodo6Tests: DefaultLogger { } + +extension GraphQLTodo6Tests { + typealias Todo = Todo6 + + struct Todo6Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo6.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6+Schema.swift new file mode 100644 index 0000000000..6e92724406 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6+Schema.swift @@ -0,0 +1,72 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo6 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case todoId + case content + case completed + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo6 = Todo6.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo6s" + model.syncPluralName = "Todo6s" + + model.attributes( + .index(fields: ["todoId"], name: nil), + .primaryKey(fields: [todo6.todoId]) + ) + + model.fields( + .field(todo6.todoId, is: .required, ofType: .string), + .field(todo6.content, is: .optional, ofType: .string), + .field(todo6.completed, is: .optional, ofType: .bool), + .field(todo6.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo6.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo6: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Custom + public typealias IdentifierProtocol = ModelIdentifier +} + +extension Todo6.IdentifierProtocol { + public static func identifier(todoId: String) -> Self { + .make(fields:[(name: "todoId", value: todoId)]) + } +} +extension ModelPath where ModelType == Todo6 { + public var todoId: FieldPath { + string("todoId") + } + public var content: FieldPath { + string("content") + } + public var completed: FieldPath { + bool("completed") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6.swift new file mode 100644 index 0000000000..04c2eea180 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_6/Todo6.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo6: Model { + public let todoId: String + public var content: String? + public var completed: Bool? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(todoId: String, + content: String? = nil, + completed: Bool? = nil) { + self.init(todoId: todoId, + content: content, + completed: completed, + createdAt: nil, + updatedAt: nil) + } + internal init(todoId: String, + content: String? = nil, + completed: Bool? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.todoId = todoId + self.content = content + self.completed = completed + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/GraphQLStoreBranch7Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/GraphQLStoreBranch7Tests.swift new file mode 100644 index 0000000000..7b5456085e --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/GraphQLStoreBranch7Tests.swift @@ -0,0 +1,43 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + + +import Foundation +import Combine +import XCTest + +@testable import Amplify +import AWSPluginsCore + +final class GraphQLStoreBranch7Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/#composite-identifier + func testCodeSnippet() async throws { + await setup(withModels: StoreBranch7Models()) + + let queriedStoreBranch = try await Amplify.API.query( + request: .get( + StoreBranch.self, + byIdentifier: .identifier( + tenantId: "123", + name: "Downtown"))) + } +} + +extension GraphQLStoreBranch7Tests: DefaultLogger { } + +extension GraphQLStoreBranch7Tests { + typealias StoreBranch = StoreBranch7 + + struct StoreBranch7Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: StoreBranch7.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7+Schema.swift new file mode 100644 index 0000000000..9ef1b980a9 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7+Schema.swift @@ -0,0 +1,93 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension StoreBranch7 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case tenantId + case name + case country + case state + case city + case zipCode + case streetAddress + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let storeBranch7 = StoreBranch7.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "StoreBranch7s" + model.syncPluralName = "StoreBranch7s" + + model.attributes( + .index(fields: ["tenantId", "name"], name: nil), + .primaryKey(fields: [storeBranch7.tenantId, storeBranch7.name]) + ) + + model.fields( + .field(storeBranch7.tenantId, is: .required, ofType: .string), + .field(storeBranch7.name, is: .required, ofType: .string), + .field(storeBranch7.country, is: .optional, ofType: .string), + .field(storeBranch7.state, is: .optional, ofType: .string), + .field(storeBranch7.city, is: .optional, ofType: .string), + .field(storeBranch7.zipCode, is: .optional, ofType: .string), + .field(storeBranch7.streetAddress, is: .optional, ofType: .string), + .field(storeBranch7.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(storeBranch7.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension StoreBranch7: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Custom + public typealias IdentifierProtocol = ModelIdentifier +} + +extension StoreBranch7.IdentifierProtocol { + public static func identifier(tenantId: String, + name: String) -> Self { + .make(fields:[(name: "tenantId", value: tenantId), (name: "name", value: name)]) + } +} +extension ModelPath where ModelType == StoreBranch7 { + public var tenantId: FieldPath { + string("tenantId") + } + public var name: FieldPath { + string("name") + } + public var country: FieldPath { + string("country") + } + public var state: FieldPath { + string("state") + } + public var city: FieldPath { + string("city") + } + public var zipCode: FieldPath { + string("zipCode") + } + public var streetAddress: FieldPath { + string("streetAddress") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7.swift new file mode 100644 index 0000000000..5dd00d59a1 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_7/StoreBranch7.swift @@ -0,0 +1,52 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct StoreBranch7: Model { + public let tenantId: String + public let name: String + public var country: String? + public var state: String? + public var city: String? + public var zipCode: String? + public var streetAddress: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(tenantId: String, + name: String, + country: String? = nil, + state: String? = nil, + city: String? = nil, + zipCode: String? = nil, + streetAddress: String? = nil) { + self.init(tenantId: tenantId, + name: name, + country: country, + state: state, + city: city, + zipCode: zipCode, + streetAddress: streetAddress, + createdAt: nil, + updatedAt: nil) + } + internal init(tenantId: String, + name: String, + country: String? = nil, + state: String? = nil, + city: String? = nil, + zipCode: String? = nil, + streetAddress: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.tenantId = tenantId + self.name = name + self.country = country + self.state = state + self.city = city + self.zipCode = zipCode + self.streetAddress = streetAddress + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8+Schema.swift new file mode 100644 index 0000000000..be4fe91412 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8+Schema.swift @@ -0,0 +1,71 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Customer8 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case phoneNumber + case accountRepresentativeId + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let customer8 = Customer8.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Customer8s" + model.syncPluralName = "Customer8s" + + model.attributes( + .index(fields: ["accountRepresentativeId"], name: "customer8sByAccountRepresentativeId"), + .primaryKey(fields: [customer8.id]) + ) + + model.fields( + .field(customer8.id, is: .required, ofType: .string), + .field(customer8.name, is: .optional, ofType: .string), + .field(customer8.phoneNumber, is: .optional, ofType: .string), + .field(customer8.accountRepresentativeId, is: .required, ofType: .string), + .field(customer8.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(customer8.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Customer8: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Customer8 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var phoneNumber: FieldPath { + string("phoneNumber") + } + public var accountRepresentativeId: FieldPath { + string("accountRepresentativeId") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8.swift new file mode 100644 index 0000000000..a944b2c99b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/Customer8.swift @@ -0,0 +1,37 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Customer8: Model { + public let id: String + public var name: String? + public var phoneNumber: String? + public var accountRepresentativeId: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String) { + self.init(id: id, + name: name, + phoneNumber: phoneNumber, + accountRepresentativeId: accountRepresentativeId, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.phoneNumber = phoneNumber + self.accountRepresentativeId = accountRepresentativeId + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/GraphQLCustomer8Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/GraphQLCustomer8Tests.swift new file mode 100644 index 0000000000..affb93019f --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_8/GraphQLCustomer8Tests.swift @@ -0,0 +1,69 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLCustomer8Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/ + func testCodeSnippet() async throws { + await setup(withModels: Customer8Models()) + + let accountRepresentativeId = UUID().uuidString + let customer = Customer(accountRepresentativeId: accountRepresentativeId) + _ = try await Amplify.API.mutate(request: .create(customer)) + + // Code Snippet Begins + struct PaginatedList: Decodable { + let items: [ModelType] + let nextToken: String? + } + let operationName = "listCustomer8ByAccountRepresentativeId" + let document = """ + query ListCustomer8ByAccountRepresentativeId { + \(operationName)(accountRepresentativeId: "\(accountRepresentativeId)") { + items { + createdAt + accountRepresentativeId + id + name + phoneNumber + updatedAt + } + nextToken + } + } + """ + + let request = GraphQLRequest>( + document: document, + responseType: PaginatedList.self, + decodePath: operationName) + + let queriedCustomers = try await Amplify.API.query( + request: request).get() + + // Code Snippet Ends + XCTAssertTrue(queriedCustomers.items.count != 0 || queriedCustomers.nextToken != nil) + } +} + +extension GraphQLCustomer8Tests: DefaultLogger { } + +extension GraphQLCustomer8Tests { + typealias Customer = Customer8 + + struct Customer8Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Customer8.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9+Schema.swift new file mode 100644 index 0000000000..57489c5117 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9+Schema.swift @@ -0,0 +1,71 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Customer9 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case name + case phoneNumber + case accountRepresentativeId + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let customer9 = Customer9.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Customer9s" + model.syncPluralName = "Customer9s" + + model.attributes( + .index(fields: ["accountRepresentativeId", "name"], name: "customer9sByAccountRepresentativeIdAndName"), + .primaryKey(fields: [customer9.id]) + ) + + model.fields( + .field(customer9.id, is: .required, ofType: .string), + .field(customer9.name, is: .optional, ofType: .string), + .field(customer9.phoneNumber, is: .optional, ofType: .string), + .field(customer9.accountRepresentativeId, is: .required, ofType: .string), + .field(customer9.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(customer9.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Customer9: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Customer9 { + public var id: FieldPath { + string("id") + } + public var name: FieldPath { + string("name") + } + public var phoneNumber: FieldPath { + string("phoneNumber") + } + public var accountRepresentativeId: FieldPath { + string("accountRepresentativeId") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9.swift new file mode 100644 index 0000000000..8154a90db0 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/Customer9.swift @@ -0,0 +1,37 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Customer9: Model { + public let id: String + public var name: String? + public var phoneNumber: String? + public var accountRepresentativeId: String + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String) { + self.init(id: id, + name: name, + phoneNumber: phoneNumber, + accountRepresentativeId: accountRepresentativeId, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + name: String? = nil, + phoneNumber: String? = nil, + accountRepresentativeId: String, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.name = name + self.phoneNumber = phoneNumber + self.accountRepresentativeId = accountRepresentativeId + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/GraphQLCustomer9Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/GraphQLCustomer9Tests.swift new file mode 100644 index 0000000000..ee4420f122 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_9/GraphQLCustomer9Tests.swift @@ -0,0 +1,69 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLCustomer9Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/ + func testCodeSnippet() async throws { + await setup(withModels: Customer9Models()) + + let accountRepresentativeId = UUID().uuidString + let name = "Rene" + let customer = Customer(name: name, accountRepresentativeId: accountRepresentativeId) + let createdCustomer = try await Amplify.API.mutate(request: .create(customer)) + + // Code Snippet Begins + struct PaginatedList: Decodable { + let items: [ModelType] + let nextToken: String? + } + let operationName = "listCustomer9ByAccountRepresentativeIdAndName" + let document = """ + query ListCustomer8ByAccountRepresentativeId { + \(operationName)(accountRepresentativeId: "\(accountRepresentativeId)", name: {beginsWith: "\(name)"}) { + items { + accountRepresentativeId + createdAt + id + name + phoneNumber + updatedAt + } + nextToken + } + } + """ + var request = GraphQLRequest>( + document: document, + responseType: PaginatedList.self, + decodePath: operationName) + + let queriedCustomers = try await Amplify.API.query( + request: request).get() + + // Code Snippet Ends + XCTAssertTrue(queriedCustomers.items.count != 0 || queriedCustomers.nextToken != nil) + } +} + +extension GraphQLCustomer9Tests: DefaultLogger { } + +extension GraphQLCustomer9Tests { + typealias Customer = Customer9 + + struct Customer9Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Customer9.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md index 033e2c4ea2..d2854a9fbf 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md @@ -12,8 +12,8 @@ At the time this was written, it follows the steps from here https://docs.amplif { ... "devDependencies": { - "@aws-amplify/backend": "^0.15.0", - "@aws-amplify/backend-cli": "^0.15.0", + "@aws-amplify/backend": "^1.0.1", + "@aws-amplify/backend-cli": "^1.0.1", "aws-cdk": "^2.139.0", "aws-cdk-lib": "^2.139.0", "constructs": "^10.3.0", @@ -67,7 +67,154 @@ const schema = a.schema({ }) .identifier(["id", "content"]) .authorization((allow) => [allow.publicApiKey()]), -}); + + // Gen2_1 + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-a-custom-field-type + Location1: a.customType({ + lat: a.float(), + long: a.float(), + }), + Post1: a.model({ + location: a.ref('Location1'), + content: a.string(), + }), + User1: a.model({ + lastKnownLocation: a.ref('Location1'), + }), + + // Gen2_2 + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-an-enum-field-type + PrivacySetting2: a.enum([ + 'PRIVATE', + 'FRIENDS_ONLY', + 'PUBLIC' + ]), + Post2: a.model({ + content: a.string(), + privacySetting: a.ref('PrivacySetting2'), + }), + Video2: a.model({ + privacySetting: a.ref('PrivacySetting2'), + }), + + // Gen2_3 + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships + Member3: a.model({ + name: a.string().required(), + // 1. Create a reference field + teamId: a.id(), + // 2. Create a belongsTo relationship with the reference field + team: a.belongsTo('Team3', 'teamId'), + }) + .authorization(allow => [allow.publicApiKey()]), + + Team3: a.model({ + mantra: a.string().required(), + // 3. Create a hasMany relationship with the reference field + // from the `Member`s model. + members: a.hasMany('Member3', 'teamId'), + }) + .authorization(allow => [allow.publicApiKey()]), + + // Gen2_4 - Model a "one-to-one" relationship + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship + Cart4: a.model({ + items: a.string().required().array(), + // 1. Create reference field + customerId: a.id(), + // 2. Create relationship field with the reference field + customer: a.belongsTo('Customer4', 'customerId'), + }), + Customer4: a.model({ + name: a.string(), + // 3. Create relationship field with the reference field + // from the Cart model + activeCart: a.hasOne('Cart4', 'customerId') + }), + + // Gen2_41 -Model multiple relationships between two models + // http://localhost:3000/swift/build-a-backend/data/data-modeling/relationships/#model-multiple-relationships-between-two-models + Post41: a.model({ + title: a.string().required(), + content: a.string().required(), + + authorId: a.id(), + author: a.belongsTo('Person41', 'authorId'), + editorId: a.id(), + editor: a.belongsTo('Person41', 'editorId'), + }), + Person41: a.model({ + name: a.string(), + editedPosts: a.hasMany('Post41', 'editorId'), + authoredPosts: a.hasMany('Post41', 'authorId'), + }), + + // Gen2_5 - Customize data model identifiers + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/ + Todo5: a.model({ + content: a.string(), + completed: a.boolean(), + }), + + // Gen2_6 - Single-field identifier + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/#single-field-identifier + Todo6: a.model({ + todoId: a.id().required(), + content: a.string(), + completed: a.boolean(), + }) + .identifier(['todoId']), + + // Gen2_7 - Composite identifier + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/#composite-identifier + StoreBranch7: a.model({ + tenantId: a.id().required(), + name: a.string().required(), + country: a.string(), + state: a.string(), + city: a.string(), + zipCode: a.string(), + streetAddress: a.string(), + }) + .identifier(['tenantId', 'name']), + + // Gen2_8 - Customize secondary indexes + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/ + Customer8: a + .model({ + name: a.string(), + phoneNumber: a.phone(), + accountRepresentativeId: a.id().required(), + }) + .secondaryIndexes((index) => [index("accountRepresentativeId")]), + + // Gen2_9 + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/#add-sort-keys-to-secondary-indexes + Customer9: a + .model({ + name: a.string(), + phoneNumber: a.phone(), + accountRepresentativeId: a.id().required(), + }) + .secondaryIndexes((index) => [ + index("accountRepresentativeId") + .sortKeys(["name"]), + ]), + + // Gen2_10 + // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/secondary-index/#customize-the-query-field-for-secondary-indexes + Customer10: a + .model({ + name: a.string(), + phoneNumber: a.phone(), + accountRepresentativeId: a.id().required(), + }) + .secondaryIndexes((index) => [ + index("accountRepresentativeId") + .queryField("listByRep"), + ]), + +}).authorization(allow => [allow.publicApiKey()]); ``` @@ -105,7 +252,7 @@ cp amplify_outputs.json ~/.aws-amplify/amplify-ios/testconfiguration/Gen2GraphQL 6. (Optional) The code generated model files are already checked into the tests so you will only have to re-generate them if you are expecting modifications to them and replace the existing ones checked in. ``` -npx amplify generate graphql-client-code --format=modelgen --model-target=swift --out=models --profile lawmicha +npx ampx generate graphql-client-code --format=modelgen --model-target=swift --profile [PROFILE] --out=models ``` From d6583e6999a545c299518cf81600b0b8504325c2 Mon Sep 17 00:00:00 2001 From: Michael Law <1365977+lawmicha@users.noreply.github.com> Date: Mon, 3 Jun 2024 14:29:12 -0400 Subject: [PATCH 2/2] test(data): Gen2 data customize auth doc example testing (#3705) * test(data): Gen2 data customize auth doc example testing * address PR comments --- .../APIHostApp.xcodeproj/project.pbxproj | 166 +++++++++++++++++- .../AWSAPIPluginGen2GraphQLBaseTest.swift | 9 +- .../AuthSignInHelper.swift | 61 +++++++ .../Gen2_11/GraphQLPost11Tests.swift | 75 ++++++++ .../Gen2_11/Post11+Schema.swift | 66 +++++++ .../Gen2_11/Post11.swift | 32 ++++ .../Gen2_12/GraphQLTodo12Tests.swift | 45 +++++ .../Gen2_12/Todo12+Schema.swift | 60 +++++++ .../Gen2_12/Todo12.swift | 27 +++ .../Gen2_13/GraphQLTodo13Tests.swift | 48 +++++ .../Gen2_13/Todo13+Schema.swift | 60 +++++++ .../Gen2_13/Todo13.swift | 27 +++ .../Gen2_14/GraphQLTodo14Tests.swift | 58 ++++++ .../Gen2_14/Todo14+Schema.swift | 60 +++++++ .../Gen2_14/Todo14.swift | 27 +++ .../Gen2_15/GraphQLTodo15Tests.swift | 94 ++++++++++ .../Gen2_15/Todo15+Schema.swift | 65 +++++++ .../Gen2_15/Todo15.swift | 32 ++++ .../Gen2_16/GraphQLTodo16Tests.swift | 58 ++++++ .../Gen2_16/Todo16+Schema.swift | 60 +++++++ .../Gen2_16/Todo16.swift | 27 +++ .../Gen2_17/GraphQLTodo17Tests.swift | 58 ++++++ .../Gen2_17/Todo17+Schema.swift | 60 +++++++ .../Gen2_17/Todo17.swift | 27 +++ .../Gen2_18/GraphQLSalary18Tests.swift | 60 +++++++ .../Gen2_18/Salary18+Schema.swift | 65 +++++++ .../Gen2_18/Salary18.swift | 32 ++++ .../Gen2_41/GraphQLPostPerson41Tests.swift | 0 .../Gen2_41/Person41+Schema.swift | 0 .../{ => Gen2_4}/Gen2_41/Person41.swift | 0 .../{ => Gen2_4}/Gen2_41/Post41+Schema.swift | 0 .../{ => Gen2_4}/Gen2_41/Post41.swift | 0 .../AWSAPIPluginGen2GraphQLTests/README.md | 161 +++++++++++++++-- 33 files changed, 1601 insertions(+), 19 deletions(-) create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AuthSignInHelper.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/GraphQLPost11Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/GraphQLTodo12Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/GraphQLTodo13Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/GraphQLTodo14Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/GraphQLTodo15Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/GraphQLTodo16Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/GraphQLTodo17Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/GraphQLSalary18Tests.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18+Schema.swift create mode 100644 AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18.swift rename AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/{ => Gen2_4}/Gen2_41/GraphQLPostPerson41Tests.swift (100%) rename AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/{ => Gen2_4}/Gen2_41/Person41+Schema.swift (100%) rename AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/{ => Gen2_4}/Gen2_41/Person41.swift (100%) rename AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/{ => Gen2_4}/Gen2_41/Post41+Schema.swift (100%) rename AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/{ => Gen2_4}/Gen2_41/Post41.swift (100%) diff --git a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj index c91d094012..0180b47473 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj +++ b/AmplifyPlugins/API/Tests/APIHostApp/APIHostApp.xcodeproj/project.pbxproj @@ -102,6 +102,30 @@ 213B97102BF4F1E800DE74AB /* Person41.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970C2BF4F1E800DE74AB /* Person41.swift */; }; 213B97112BF4F1E800DE74AB /* Person41+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970D2BF4F1E800DE74AB /* Person41+Schema.swift */; }; 213B97122BF4F1E800DE74AB /* Post41.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B970E2BF4F1E800DE74AB /* Post41.swift */; }; + 213B971E2BF544D500DE74AB /* Post11.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B971C2BF544D500DE74AB /* Post11.swift */; }; + 213B971F2BF544D500DE74AB /* Post11+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B971D2BF544D500DE74AB /* Post11+Schema.swift */; }; + 213B97222BF544E800DE74AB /* Todo12+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97202BF544E800DE74AB /* Todo12+Schema.swift */; }; + 213B97232BF544E800DE74AB /* Todo12.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97212BF544E800DE74AB /* Todo12.swift */; }; + 213B97262BF544F700DE74AB /* Todo13+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97242BF544F700DE74AB /* Todo13+Schema.swift */; }; + 213B97272BF544F700DE74AB /* Todo13.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97252BF544F700DE74AB /* Todo13.swift */; }; + 213B972A2BF5450D00DE74AB /* Todo14+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97282BF5450D00DE74AB /* Todo14+Schema.swift */; }; + 213B972B2BF5450D00DE74AB /* Todo14.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97292BF5450D00DE74AB /* Todo14.swift */; }; + 213B972E2BF5451800DE74AB /* Todo15+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B972C2BF5451800DE74AB /* Todo15+Schema.swift */; }; + 213B972F2BF5451800DE74AB /* Todo15.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B972D2BF5451800DE74AB /* Todo15.swift */; }; + 213B97322BF5452300DE74AB /* Todo16.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97302BF5452300DE74AB /* Todo16.swift */; }; + 213B97332BF5452300DE74AB /* Todo16+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97312BF5452300DE74AB /* Todo16+Schema.swift */; }; + 213B97362BF5453300DE74AB /* Todo17.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97342BF5453300DE74AB /* Todo17.swift */; }; + 213B97372BF5453300DE74AB /* Todo17+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97352BF5453300DE74AB /* Todo17+Schema.swift */; }; + 213B973A2BF5455000DE74AB /* Salary18.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97382BF5455000DE74AB /* Salary18.swift */; }; + 213B973B2BF5455000DE74AB /* Salary18+Schema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97392BF5455000DE74AB /* Salary18+Schema.swift */; }; + 213B97412BF54B7100DE74AB /* GraphQLPost11Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97402BF54B7100DE74AB /* GraphQLPost11Tests.swift */; }; + 213B97432BF54B7B00DE74AB /* GraphQLTodo12Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97422BF54B7B00DE74AB /* GraphQLTodo12Tests.swift */; }; + 213B97452BF54B8500DE74AB /* GraphQLTodo13Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97442BF54B8500DE74AB /* GraphQLTodo13Tests.swift */; }; + 213B97472BF54B9100DE74AB /* GraphQLTodo14Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97462BF54B9100DE74AB /* GraphQLTodo14Tests.swift */; }; + 213B97492BF54B9D00DE74AB /* GraphQLTodo15Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B97482BF54B9D00DE74AB /* GraphQLTodo15Tests.swift */; }; + 213B974B2BF54BA700DE74AB /* GraphQLTodo16Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B974A2BF54BA700DE74AB /* GraphQLTodo16Tests.swift */; }; + 213B974D2BF54BB300DE74AB /* GraphQLTodo17Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B974C2BF54BB300DE74AB /* GraphQLTodo17Tests.swift */; }; + 213B974F2BF54BBC00DE74AB /* GraphQLSalary18Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213B974E2BF54BBC00DE74AB /* GraphQLSalary18Tests.swift */; }; 213DBC8128A6C4FB00B30280 /* TestConfigHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213DBC8028A6C4FB00B30280 /* TestConfigHelper.swift */; }; 213DBC8528A6CE9800B30280 /* GraphQLWithLambdaAuthIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21698BA328899B3F004BD994 /* GraphQLWithLambdaAuthIntegrationTests.swift */; }; 213DBC8728A6CEDD00B30280 /* Todo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 213DBC8628A6CEDD00B30280 /* Todo.swift */; }; @@ -272,6 +296,7 @@ 21EA887F28F9BCC30000BA75 /* AsyncExpectation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681DFE7028E7451D0000C36A /* AsyncExpectation.swift */; }; 21EA888028F9BCC50000BA75 /* XCTestCase+AsyncTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681DFE7128E7451D0000C36A /* XCTestCase+AsyncTesting.swift */; }; 21EA888228F9BCD90000BA75 /* TestConfigHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EA888128F9BCD90000BA75 /* TestConfigHelper.swift */; }; + 21FA745C2BF6713900F2C9AA /* AuthSignInHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA745B2BF6713900F2C9AA /* AuthSignInHelper.swift */; }; 21FA8EF7295C9609009F6A07 /* GraphQLLazyLoadHasOneTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8EF6295C9609009F6A07 /* GraphQLLazyLoadHasOneTests.swift */; }; 21FA8EF9295C962E009F6A07 /* GraphQLLazyLoadDefaultPKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8EF8295C962E009F6A07 /* GraphQLLazyLoadDefaultPKTests.swift */; }; 21FA8EFB295C9647009F6A07 /* GraphQLLazyLoadCompositePKTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21FA8EFA295C9647009F6A07 /* GraphQLLazyLoadCompositePKTests.swift */; }; @@ -608,6 +633,30 @@ 213B970C2BF4F1E800DE74AB /* Person41.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person41.swift; sourceTree = ""; }; 213B970D2BF4F1E800DE74AB /* Person41+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Person41+Schema.swift"; sourceTree = ""; }; 213B970E2BF4F1E800DE74AB /* Post41.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post41.swift; sourceTree = ""; }; + 213B971C2BF544D500DE74AB /* Post11.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post11.swift; sourceTree = ""; }; + 213B971D2BF544D500DE74AB /* Post11+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Post11+Schema.swift"; sourceTree = ""; }; + 213B97202BF544E800DE74AB /* Todo12+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo12+Schema.swift"; sourceTree = ""; }; + 213B97212BF544E800DE74AB /* Todo12.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo12.swift; sourceTree = ""; }; + 213B97242BF544F700DE74AB /* Todo13+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo13+Schema.swift"; sourceTree = ""; }; + 213B97252BF544F700DE74AB /* Todo13.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo13.swift; sourceTree = ""; }; + 213B97282BF5450D00DE74AB /* Todo14+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo14+Schema.swift"; sourceTree = ""; }; + 213B97292BF5450D00DE74AB /* Todo14.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo14.swift; sourceTree = ""; }; + 213B972C2BF5451800DE74AB /* Todo15+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo15+Schema.swift"; sourceTree = ""; }; + 213B972D2BF5451800DE74AB /* Todo15.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo15.swift; sourceTree = ""; }; + 213B97302BF5452300DE74AB /* Todo16.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo16.swift; sourceTree = ""; }; + 213B97312BF5452300DE74AB /* Todo16+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo16+Schema.swift"; sourceTree = ""; }; + 213B97342BF5453300DE74AB /* Todo17.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Todo17.swift; sourceTree = ""; }; + 213B97352BF5453300DE74AB /* Todo17+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Todo17+Schema.swift"; sourceTree = ""; }; + 213B97382BF5455000DE74AB /* Salary18.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Salary18.swift; sourceTree = ""; }; + 213B97392BF5455000DE74AB /* Salary18+Schema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Salary18+Schema.swift"; sourceTree = ""; }; + 213B97402BF54B7100DE74AB /* GraphQLPost11Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLPost11Tests.swift; sourceTree = ""; }; + 213B97422BF54B7B00DE74AB /* GraphQLTodo12Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo12Tests.swift; sourceTree = ""; }; + 213B97442BF54B8500DE74AB /* GraphQLTodo13Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo13Tests.swift; sourceTree = ""; }; + 213B97462BF54B9100DE74AB /* GraphQLTodo14Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo14Tests.swift; sourceTree = ""; }; + 213B97482BF54B9D00DE74AB /* GraphQLTodo15Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo15Tests.swift; sourceTree = ""; }; + 213B974A2BF54BA700DE74AB /* GraphQLTodo16Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo16Tests.swift; sourceTree = ""; }; + 213B974C2BF54BB300DE74AB /* GraphQLTodo17Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLTodo17Tests.swift; sourceTree = ""; }; + 213B974E2BF54BBC00DE74AB /* GraphQLSalary18Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLSalary18Tests.swift; sourceTree = ""; }; 213DBB6028A40DAE00B30280 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 213DBC7528A6C47000B30280 /* AWSAPIPluginGraphQLLambdaAuthTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AWSAPIPluginGraphQLLambdaAuthTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 213DBC8028A6C4FB00B30280 /* TestConfigHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestConfigHelper.swift; sourceTree = ""; }; @@ -794,6 +843,7 @@ 21EA887D28F9BCBB0000BA75 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 21EA888128F9BCD90000BA75 /* TestConfigHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestConfigHelper.swift; sourceTree = ""; }; 21EA888328F9BD2D0000BA75 /* lazyload-schema.graphql */ = {isa = PBXFileReference; lastKnownFileType = text; path = "lazyload-schema.graphql"; sourceTree = ""; }; + 21FA745B2BF6713900F2C9AA /* AuthSignInHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthSignInHelper.swift; sourceTree = ""; }; 21FA8EF6295C9609009F6A07 /* GraphQLLazyLoadHasOneTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLLazyLoadHasOneTests.swift; sourceTree = ""; }; 21FA8EF8295C962E009F6A07 /* GraphQLLazyLoadDefaultPKTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLLazyLoadDefaultPKTests.swift; sourceTree = ""; }; 21FA8EFA295C9647009F6A07 /* GraphQLLazyLoadCompositePKTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphQLLazyLoadCompositePKTests.swift; sourceTree = ""; }; @@ -1046,6 +1096,7 @@ 213B96972BF3B63600DE74AB /* Gen2_4 */ = { isa = PBXGroup; children = ( + 213B96FC2BF4531100DE74AB /* Gen2_41 */, 213B96B82BF3B6D400DE74AB /* Cart4.swift */, 213B96B92BF3B6D400DE74AB /* Cart4+Schema.swift */, 213B96B72BF3B6D400DE74AB /* Customer4.swift */, @@ -1127,6 +1178,86 @@ path = Gen2_41; sourceTree = ""; }; + 213B97132BF5444A00DE74AB /* Gen2_11 */ = { + isa = PBXGroup; + children = ( + 213B971C2BF544D500DE74AB /* Post11.swift */, + 213B971D2BF544D500DE74AB /* Post11+Schema.swift */, + 213B97402BF54B7100DE74AB /* GraphQLPost11Tests.swift */, + ); + path = Gen2_11; + sourceTree = ""; + }; + 213B97142BF5445100DE74AB /* Gen2_12 */ = { + isa = PBXGroup; + children = ( + 213B97212BF544E800DE74AB /* Todo12.swift */, + 213B97202BF544E800DE74AB /* Todo12+Schema.swift */, + 213B97422BF54B7B00DE74AB /* GraphQLTodo12Tests.swift */, + ); + path = Gen2_12; + sourceTree = ""; + }; + 213B97152BF5445600DE74AB /* Gen2_13 */ = { + isa = PBXGroup; + children = ( + 213B97252BF544F700DE74AB /* Todo13.swift */, + 213B97242BF544F700DE74AB /* Todo13+Schema.swift */, + 213B97442BF54B8500DE74AB /* GraphQLTodo13Tests.swift */, + ); + path = Gen2_13; + sourceTree = ""; + }; + 213B97162BF5446300DE74AB /* Gen2_14 */ = { + isa = PBXGroup; + children = ( + 213B97292BF5450D00DE74AB /* Todo14.swift */, + 213B97282BF5450D00DE74AB /* Todo14+Schema.swift */, + 213B97462BF54B9100DE74AB /* GraphQLTodo14Tests.swift */, + ); + path = Gen2_14; + sourceTree = ""; + }; + 213B97172BF5446A00DE74AB /* Gen2_15 */ = { + isa = PBXGroup; + children = ( + 213B972D2BF5451800DE74AB /* Todo15.swift */, + 213B972C2BF5451800DE74AB /* Todo15+Schema.swift */, + 213B97482BF54B9D00DE74AB /* GraphQLTodo15Tests.swift */, + ); + path = Gen2_15; + sourceTree = ""; + }; + 213B97182BF5447A00DE74AB /* Gen2_16 */ = { + isa = PBXGroup; + children = ( + 213B97302BF5452300DE74AB /* Todo16.swift */, + 213B97312BF5452300DE74AB /* Todo16+Schema.swift */, + 213B974A2BF54BA700DE74AB /* GraphQLTodo16Tests.swift */, + ); + path = Gen2_16; + sourceTree = ""; + }; + 213B97192BF5448000DE74AB /* Gen2_17 */ = { + isa = PBXGroup; + children = ( + 213B97342BF5453300DE74AB /* Todo17.swift */, + 213B97352BF5453300DE74AB /* Todo17+Schema.swift */, + 213B974C2BF54BB300DE74AB /* GraphQLTodo17Tests.swift */, + ); + path = Gen2_17; + sourceTree = ""; + }; + 213B971A2BF5448700DE74AB /* Gen2_18 */ = { + isa = PBXGroup; + children = ( + 213B97382BF5455000DE74AB /* Salary18.swift */, + 213B97392BF5455000DE74AB /* Salary18+Schema.swift */, + 213B974E2BF54BBC00DE74AB /* GraphQLSalary18Tests.swift */, + ); + path = Gen2_18; + sourceTree = ""; + }; 213DBC7628A6C47000B30280 /* AWSAPIPluginGraphQLLambdaAuthTests */ = { isa = PBXGroup; children = ( @@ -1154,17 +1285,25 @@ 213B96942BF3B5EA00DE74AB /* Gen2_2 */, 213B96952BF3B62200DE74AB /* Gen2_3 */, 213B96972BF3B63600DE74AB /* Gen2_4 */, - 213B96FC2BF4531100DE74AB /* Gen2_41 */, 213B96982BF3B63E00DE74AB /* Gen2_5 */, 213B96D72BF4480E00DE74AB /* Gen2_6 */, 213B96DC2BF4482D00DE74AB /* Gen2_7 */, 213B96E72BF44DCD00DE74AB /* Gen2_8 */, 213B96EA2BF44F2800DE74AB /* Gen2_9 */, 213B96EB2BF44F3400DE74AB /* Gen2_10 */, + 213B97132BF5444A00DE74AB /* Gen2_11 */, + 213B97142BF5445100DE74AB /* Gen2_12 */, + 213B97152BF5445600DE74AB /* Gen2_13 */, + 213B97162BF5446300DE74AB /* Gen2_14 */, + 213B97172BF5446A00DE74AB /* Gen2_15 */, + 213B97182BF5447A00DE74AB /* Gen2_16 */, + 213B97192BF5448000DE74AB /* Gen2_17 */, + 213B971A2BF5448700DE74AB /* Gen2_18 */, 2163D6182BE9740B009689B1 /* LL1 */, 2163D6192BE97476009689B1 /* LL3 */, 2163D6152BE96D12009689B1 /* README.md */, 2163D6162BE96E3D009689B1 /* TestConfigHelper.swift */, + 21FA745B2BF6713900F2C9AA /* AuthSignInHelper.swift */, ); path = AWSAPIPluginGen2GraphQLTests; sourceTree = ""; @@ -2475,25 +2614,36 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 213B97472BF54B9100DE74AB /* GraphQLTodo14Tests.swift in Sources */, 213B96AE2BF3B67500DE74AB /* Post1+Schema.swift in Sources */, 213B970F2BF4F1E800DE74AB /* Post41+Schema.swift in Sources */, 213B96D52BF4480900DE74AB /* Todo5.swift in Sources */, 213B96F72BF4500D00DE74AB /* Customer9+Schema.swift in Sources */, 213B969F2BF3B65800DE74AB /* Video2.swift in Sources */, 213B96CE2BF3E3D000DE74AB /* GraphQLPostVideoPrivacySetting2Tests.swift in Sources */, + 213B974F2BF54BBC00DE74AB /* GraphQLSalary18Tests.swift in Sources */, + 21FA745C2BF6713900F2C9AA /* AuthSignInHelper.swift in Sources */, 213B96F22BF4500200DE74AB /* Customer8.swift in Sources */, 2163D61B2BE97494009689B1 /* GraphQLLazyLoadPostComment4V2Tests.swift in Sources */, + 213B97452BF54B8500DE74AB /* GraphQLTodo13Tests.swift in Sources */, 213B96E92BF44DE600DE74AB /* GraphQLCustomer8Tests.swift in Sources */, 213B96D02BF3E64C00DE74AB /* GraphQLTeamMember3Tests.swift in Sources */, + 213B97232BF544E800DE74AB /* Todo12.swift in Sources */, 213B97112BF4F1E800DE74AB /* Person41+Schema.swift in Sources */, 213B96B32BF3B6C100DE74AB /* Team3+Schema.swift in Sources */, 213B96F62BF4500D00DE74AB /* Customer9.swift in Sources */, 213B96DF2BF4484700DE74AB /* StoreBranch7.swift in Sources */, 213B97122BF4F1E800DE74AB /* Post41.swift in Sources */, + 213B973A2BF5455000DE74AB /* Salary18.swift in Sources */, + 213B972B2BF5450D00DE74AB /* Todo14.swift in Sources */, 213B97102BF4F1E800DE74AB /* Person41.swift in Sources */, 213B96D62BF4480900DE74AB /* Todo5+Schema.swift in Sources */, + 213B97492BF54B9D00DE74AB /* GraphQLTodo15Tests.swift in Sources */, + 213B974D2BF54BB300DE74AB /* GraphQLTodo17Tests.swift in Sources */, + 213B972F2BF5451800DE74AB /* Todo15.swift in Sources */, 2163D60F2BE96C90009689B1 /* AWSAPIPluginGen2GraphQLBaseTest.swift in Sources */, 2163D62D2BE974E6009689B1 /* PostWithCompositeKey+Schema.swift in Sources */, + 213B971E2BF544D500DE74AB /* Post11.swift in Sources */, 213B96FB2BF4501B00DE74AB /* Customer10+Schema.swift in Sources */, 213B96A92BF3B67500DE74AB /* Location1.swift in Sources */, 213B96BC2BF3B6D400DE74AB /* Cart4.swift in Sources */, @@ -2501,10 +2651,16 @@ 213B96BD2BF3B6D400DE74AB /* Cart4+Schema.swift in Sources */, 2163D6242BE974D8009689B1 /* Post4V2.swift in Sources */, 213B96AD2BF3B67500DE74AB /* Location1+Schema.swift in Sources */, + 213B973B2BF5455000DE74AB /* Salary18+Schema.swift in Sources */, 213B96BE2BF3B6D400DE74AB /* Customer4+Schema.swift in Sources */, + 213B972A2BF5450D00DE74AB /* Todo14+Schema.swift in Sources */, + 213B97372BF5453300DE74AB /* Todo17+Schema.swift in Sources */, 213B96ED2BF44F4D00DE74AB /* GraphQLCustomer9Tests.swift in Sources */, 2163D6172BE96E3D009689B1 /* TestConfigHelper.swift in Sources */, 213B96B42BF3B6C100DE74AB /* Member3.swift in Sources */, + 213B97262BF544F700DE74AB /* Todo13+Schema.swift in Sources */, + 213B97272BF544F700DE74AB /* Todo13.swift in Sources */, + 213B97322BF5452300DE74AB /* Todo16.swift in Sources */, 2163D62A2BE974E6009689B1 /* PostWithCompositeKey.swift in Sources */, 213B96E62BF4493300DE74AB /* GraphQLStoreBranch7Tests.swift in Sources */, 213B969E2BF3B65800DE74AB /* Post2+Schema.swift in Sources */, @@ -2523,15 +2679,23 @@ 213B96B62BF3B6C100DE74AB /* Team3.swift in Sources */, 213B96AB2BF3B67500DE74AB /* Post1.swift in Sources */, 213B96B52BF3B6C100DE74AB /* Member3+Schema.swift in Sources */, + 213B97222BF544E800DE74AB /* Todo12+Schema.swift in Sources */, + 213B97332BF5452300DE74AB /* Todo16+Schema.swift in Sources */, + 213B974B2BF54BA700DE74AB /* GraphQLTodo16Tests.swift in Sources */, 213B96FA2BF4501B00DE74AB /* Customer10.swift in Sources */, + 213B97362BF5453300DE74AB /* Todo17.swift in Sources */, + 213B97412BF54B7100DE74AB /* GraphQLPost11Tests.swift in Sources */, 213B96E02BF4484700DE74AB /* StoreBranch7+Schema.swift in Sources */, 213B96AA2BF3B67500DE74AB /* User1.swift in Sources */, 2163D6222BE974D8009689B1 /* Comment4V2+Schema.swift in Sources */, 213B96A02BF3B65800DE74AB /* PrivacySetting2.swift in Sources */, 213B96A22BF3B65800DE74AB /* Video2+Schema.swift in Sources */, 213B96A12BF3B65800DE74AB /* Post2.swift in Sources */, + 213B97432BF54B7B00DE74AB /* GraphQLTodo12Tests.swift in Sources */, 2163D6232BE974D8009689B1 /* Post4V2+Schema.swift in Sources */, 213B96AC2BF3B67500DE74AB /* User1+Schema.swift in Sources */, + 213B972E2BF5451800DE74AB /* Todo15+Schema.swift in Sources */, + 213B971F2BF544D500DE74AB /* Post11+Schema.swift in Sources */, 213B96EF2BF44F6D00DE74AB /* GraphQLCustomer10Tests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AWSAPIPluginGen2GraphQLBaseTest.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AWSAPIPluginGen2GraphQLBaseTest.swift index b8fb23a94a..b3ae499f53 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AWSAPIPluginGen2GraphQLBaseTest.swift +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AWSAPIPluginGen2GraphQLBaseTest.swift @@ -10,9 +10,12 @@ import XCTest @_spi(InternalAmplifyConfiguration) @testable import Amplify @testable import APIHostApp @testable import AWSPluginsCore +import AWSCognitoAuthPlugin class AWSAPIPluginGen2GraphQLBaseTest: XCTestCase { + var defaultTestEmail = "test-\(UUID().uuidString)@amazon.com" + var amplifyConfig: AmplifyOutputsData! override func setUp() { @@ -39,11 +42,15 @@ class AWSAPIPluginGen2GraphQLBaseTest: XCTestCase { /// Setup API with given models /// - Parameter models: DataStore models func setup(withModels models: AmplifyModelRegistration, - logLevel: LogLevel = .verbose) async { + logLevel: LogLevel = .verbose, + withAuthPlugin: Bool = false) async { do { setupConfig() Amplify.Logging.logLevel = logLevel try Amplify.add(plugin: AWSAPIPlugin(modelRegistration: models)) + if withAuthPlugin { + try Amplify.add(plugin: AWSCognitoAuthPlugin()) + } try Amplify.configure(amplifyConfig) } catch { diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AuthSignInHelper.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AuthSignInHelper.swift new file mode 100644 index 0000000000..768145ee0b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/AuthSignInHelper.swift @@ -0,0 +1,61 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Amplify +import XCTest + +enum AuthSignInHelper { + + static func signOut() async { + let session = try? await Amplify.Auth.fetchAuthSession() + if session?.isSignedIn ?? false { + _ = await Amplify.Auth.signOut() + } + } + + static func signUpUser( + username: String, + password: String, + email: String, + phoneNumber: String? = nil) async throws -> Bool { + + var userAttributes = [ + AuthUserAttribute(.email, value: email) + ] + + if let phoneNumber = phoneNumber { + userAttributes.append(AuthUserAttribute(.phoneNumber, value: phoneNumber)) + } + + let options = AuthSignUpRequest.Options( + userAttributes: userAttributes) + let result = try await Amplify.Auth.signUp(username: username, password: password, options: options) + return result.isSignUpComplete + } + + static func signInUser(username: String, password: String) async throws -> AuthSignInResult { + return try await Amplify.Auth.signIn(username: username, password: password, options: nil) + } + + static func registerAndSignInUser( + username: String, + password: String, + email: String, + phoneNumber: String? = nil) async throws -> Bool { + await signOut() + let signedUp = try await AuthSignInHelper.signUpUser( + username: username, + password: password, + email: email, + phoneNumber: phoneNumber) + guard signedUp else { + throw AuthError.invalidState("Auth sign up failed", "", nil) + } + let result = try await AuthSignInHelper.signInUser(username: username, password: password) + return result.isSignedIn + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/GraphQLPost11Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/GraphQLPost11Tests.swift new file mode 100644 index 0000000000..f8960e9fb0 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/GraphQLPost11Tests.swift @@ -0,0 +1,75 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLPost11Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/#configure-multiple-authorization-rules + func testCodeSnippet() async throws { + await setup(withModels: Post11Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let post = Post(title: "Hello World") + let createdTodo = try await Amplify.API.mutate(request: .create( + post, + authMode: .amazonCognitoUserPools)).get() + } catch { + print("Failed to create post", error) + // Code Snippet Ends + XCTFail("Failed to create post \(error)") + // Code Snippet Begins + } + + // Code Snippet ends + await AuthSignInHelper.signOut() + // Code Snippet begins + + do { + let queriedPosts = try await Amplify.API.query(request: .list( + Post.self, + authMode: .awsIAM)).get() + print("Number of posts:", queriedPosts.count) + + // Code Snippet Ends + XCTAssertTrue(queriedPosts.count > 0 || queriedPosts.hasNextPage()) + // Code Snippet Begins + } catch { + print("Failed to list posts", error) + // Code Snippet Ends + XCTFail("Failed to list posts \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLPost11Tests: DefaultLogger { } + +extension GraphQLPost11Tests { + typealias Post = Post11 + + struct Post11Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Post11.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11+Schema.swift new file mode 100644 index 0000000000..874efebc20 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11+Schema.swift @@ -0,0 +1,66 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Post11 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case title + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let post11 = Post11.keys + + model.authRules = [ + rule(allow: .public, provider: .iam, operations: [.read]), + rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Post11s" + model.syncPluralName = "Post11s" + + model.attributes( + .primaryKey(fields: [post11.id]) + ) + + model.fields( + .field(post11.id, is: .required, ofType: .string), + .field(post11.title, is: .optional, ofType: .string), + .field(post11.content, is: .optional, ofType: .string), + .field(post11.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(post11.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Post11: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Post11 { + public var id: FieldPath { + string("id") + } + public var title: FieldPath { + string("title") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11.swift new file mode 100644 index 0000000000..11b513d670 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_11/Post11.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Post11: Model { + public let id: String + public var title: String? + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + title: String? = nil, + content: String? = nil) { + self.init(id: id, + title: title, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + title: String? = nil, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.title = title + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/GraphQLTodo12Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/GraphQLTodo12Tests.swift new file mode 100644 index 0000000000..60faaadefa --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/GraphQLTodo12Tests.swift @@ -0,0 +1,45 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo12Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/react/build-a-backend/data/customize-authz/public-data-access/#add-public-authorization-rule-using-api-key-based-authentication + func testCodeSnippet() async throws { + await setup(withModels: Todo12Models()) + + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .apiKey)).get() + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo12Tests: DefaultLogger { } + +extension GraphQLTodo12Tests { + typealias Todo = Todo12 + + struct Todo12Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo12.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12+Schema.swift new file mode 100644 index 0000000000..a9ded86979 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12+Schema.swift @@ -0,0 +1,60 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo12 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo12 = Todo12.keys + + model.authRules = [ + rule(allow: .public, provider: .apiKey, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo12s" + model.syncPluralName = "Todo12s" + + model.attributes( + .primaryKey(fields: [todo12.id]) + ) + + model.fields( + .field(todo12.id, is: .required, ofType: .string), + .field(todo12.content, is: .optional, ofType: .string), + .field(todo12.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo12.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo12: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo12 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12.swift new file mode 100644 index 0000000000..34639f2153 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_12/Todo12.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo12: Model { + public let id: String + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil) { + self.init(id: id, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/GraphQLTodo13Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/GraphQLTodo13Tests.swift new file mode 100644 index 0000000000..dc81e3aecd --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/GraphQLTodo13Tests.swift @@ -0,0 +1,48 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo13Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/public-data-access/#add-public-authorization-rule-using-amazon-cognito-identity-pools-unauthenticated-role + func testCodeSnippet() async throws { + await setup(withModels: Todo13Models(), withAuthPlugin: true) + await AuthSignInHelper.signOut() + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .awsIAM)).get() + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + // Code Snippet Begins + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo13Tests: DefaultLogger { } + +extension GraphQLTodo13Tests { + typealias Todo = Todo13 + + struct Todo13Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo13.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13+Schema.swift new file mode 100644 index 0000000000..f8646c9a76 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13+Schema.swift @@ -0,0 +1,60 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo13 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo13 = Todo13.keys + + model.authRules = [ + rule(allow: .public, provider: .iam, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo13s" + model.syncPluralName = "Todo13s" + + model.attributes( + .primaryKey(fields: [todo13.id]) + ) + + model.fields( + .field(todo13.id, is: .required, ofType: .string), + .field(todo13.content, is: .optional, ofType: .string), + .field(todo13.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo13.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo13: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo13 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13.swift new file mode 100644 index 0000000000..cce0e45d70 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_13/Todo13.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo13: Model { + public let id: String + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil) { + self.init(id: id, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/GraphQLTodo14Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/GraphQLTodo14Tests.swift new file mode 100644 index 0000000000..dcb9fa2e6d --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/GraphQLTodo14Tests.swift @@ -0,0 +1,58 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo14Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/per-user-per-owner-data-access/#add-per-userper-owner-authorization-rule + func testCodeSnippet() async throws { + await setup(withModels: Todo14Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .amazonCognitoUserPools)).get() + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + // Code Snippet Begins + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo14Tests: DefaultLogger { } + +extension GraphQLTodo14Tests { + typealias Todo = Todo14 + + struct Todo14Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo14.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14+Schema.swift new file mode 100644 index 0000000000..c7b1cb8a9a --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14+Schema.swift @@ -0,0 +1,60 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo14 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo14 = Todo14.keys + + model.authRules = [ + rule(allow: .owner, ownerField: "owner", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .read, .update]) + ] + + model.listPluralName = "Todo14s" + model.syncPluralName = "Todo14s" + + model.attributes( + .primaryKey(fields: [todo14.id]) + ) + + model.fields( + .field(todo14.id, is: .required, ofType: .string), + .field(todo14.content, is: .optional, ofType: .string), + .field(todo14.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo14.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo14: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo14 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14.swift new file mode 100644 index 0000000000..27d172c39b --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_14/Todo14.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo14: Model { + public let id: String + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil) { + self.init(id: id, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/GraphQLTodo15Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/GraphQLTodo15Tests.swift new file mode 100644 index 0000000000..d7cd68305f --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/GraphQLTodo15Tests.swift @@ -0,0 +1,94 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo15Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/multi-user-data-access/#add-multi-user-authorization-rule + func testCodeSnippet() async throws { + await setup(withModels: Todo15Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .amazonCognitoUserPools)).get() + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + // Code Snippet Begins + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } + + func testAddAnotherUserAsAnOwner() async throws { + await setup(withModels: Todo15Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + let todo = Todo(content: "My new todo") + var createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .amazonCognitoUserPools)).get() + let otherUserId = "otherUserId" + + // Code Snippet begins + do { + createdTodo.owners?.append(otherUserId) + let updatedTodo = try await Amplify.API.mutate(request: .update( + createdTodo, + authMode: .amazonCognitoUserPools)).get() + // Code Snippet Ends + XCTAssertEqual(updatedTodo.id, todo.id) + XCTAssertEqual(updatedTodo.owners?.count, 2) + // Code Snippet Begins + } catch { + print("Failed to update todo", error) + // Code Snippet Ends + XCTFail("Failed to update todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo15Tests: DefaultLogger { } + +extension GraphQLTodo15Tests { + typealias Todo = Todo15 + + struct Todo15Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo15.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15+Schema.swift new file mode 100644 index 0000000000..8b271ff315 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo15 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case owners + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo15 = Todo15.keys + + model.authRules = [ + rule(allow: .owner, ownerField: "owners", identityClaim: "cognito:username", provider: .userPools, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo15s" + model.syncPluralName = "Todo15s" + + model.attributes( + .primaryKey(fields: [todo15.id]) + ) + + model.fields( + .field(todo15.id, is: .required, ofType: .string), + .field(todo15.content, is: .optional, ofType: .string), + .field(todo15.owners, is: .optional, ofType: .embeddedCollection(of: String.self)), + .field(todo15.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo15.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo15: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo15 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var owners: FieldPath { + string("owners") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15.swift new file mode 100644 index 0000000000..4e68848094 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_15/Todo15.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo15: Model { + public let id: String + public var content: String? + public var owners: [String?]? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil, + owners: [String?]? = nil) { + self.init(id: id, + content: content, + owners: owners, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + owners: [String?]? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.owners = owners + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/GraphQLTodo16Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/GraphQLTodo16Tests.swift new file mode 100644 index 0000000000..5ccc18db98 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/GraphQLTodo16Tests.swift @@ -0,0 +1,58 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo16Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/signed-in-user-data-access/#add-signed-in-user-authorization-rule + func testCodeSnippet() async throws { + await setup(withModels: Todo16Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .amazonCognitoUserPools)).get() + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + // Code Snippet Begins + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo16Tests: DefaultLogger { } + +extension GraphQLTodo16Tests { + typealias Todo = Todo16 + + struct Todo16Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo16.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16+Schema.swift new file mode 100644 index 0000000000..f7cc2e55f8 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16+Schema.swift @@ -0,0 +1,60 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo16 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo16 = Todo16.keys + + model.authRules = [ + rule(allow: .private, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo16s" + model.syncPluralName = "Todo16s" + + model.attributes( + .primaryKey(fields: [todo16.id]) + ) + + model.fields( + .field(todo16.id, is: .required, ofType: .string), + .field(todo16.content, is: .optional, ofType: .string), + .field(todo16.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo16.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo16: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo16 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16.swift new file mode 100644 index 0000000000..11fc206310 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_16/Todo16.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo16: Model { + public let id: String + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil) { + self.init(id: id, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/GraphQLTodo17Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/GraphQLTodo17Tests.swift new file mode 100644 index 0000000000..c1199f82a8 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/GraphQLTodo17Tests.swift @@ -0,0 +1,58 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLTodo17Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/signed-in-user-data-access/#use-identity-pool-for-signed-in-user-authentication + func testCodeSnippet() async throws { + await setup(withModels: Todo17Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let todo = Todo(content: "My new todo") + let createdTodo = try await Amplify.API.mutate(request: .create( + todo, + authMode: .awsIAM)).get() + // Code Snippet Ends + XCTAssertEqual(createdTodo.id, todo.id) + // Code Snippet Begins + } catch { + print("Failed to create todo", error) + // Code Snippet Ends + XCTFail("Failed to create todo \(error)") + // Code Snippet Begins + } + } +} + +extension GraphQLTodo17Tests: DefaultLogger { } + +extension GraphQLTodo17Tests { + typealias Todo = Todo17 + + struct Todo17Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Todo17.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17+Schema.swift new file mode 100644 index 0000000000..49fc0d8cf8 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17+Schema.swift @@ -0,0 +1,60 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Todo17 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case content + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let todo17 = Todo17.keys + + model.authRules = [ + rule(allow: .private, provider: .iam, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Todo17s" + model.syncPluralName = "Todo17s" + + model.attributes( + .primaryKey(fields: [todo17.id]) + ) + + model.fields( + .field(todo17.id, is: .required, ofType: .string), + .field(todo17.content, is: .optional, ofType: .string), + .field(todo17.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(todo17.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Todo17: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Todo17 { + public var id: FieldPath { + string("id") + } + public var content: FieldPath { + string("content") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17.swift new file mode 100644 index 0000000000..5e7f05fb8f --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_17/Todo17.swift @@ -0,0 +1,27 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Todo17: Model { + public let id: String + public var content: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + content: String? = nil) { + self.init(id: id, + content: content, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + content: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.content = content + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/GraphQLSalary18Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/GraphQLSalary18Tests.swift new file mode 100644 index 0000000000..83fd00da50 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/GraphQLSalary18Tests.swift @@ -0,0 +1,60 @@ +// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. +// +// SPDX-License-Identifier: Apache-2.0 +// + +import Foundation +import XCTest +@testable import Amplify + +final class GraphQLSalary18Tests: AWSAPIPluginGen2GraphQLBaseTest { + + // Code Snippet for + func testCodeSnippet() async throws { + await setup(withModels: Salary18Models(), withAuthPlugin: true) + let username = "integTest\(UUID().uuidString)" + let password = "P123@\(UUID().uuidString)" + do { + _ = try await AuthSignInHelper.registerAndSignInUser( + username: username, + password: password, + email: defaultTestEmail) + } catch { + XCTFail("Could not sign up and sign in user \(error)") + } + + // Code Snippet begins + do { + let salary = Salary( + wage: 50.25, + currency: "USD") + let createdSalary = try await Amplify.API.mutate(request: .create( + salary, + authMode: .amazonCognitoUserPools)).get() + // Code Snippet Ends + XCTFail("Should not make it to here. Expected to catch failure since user is not in the Admin group.") + // Code Snippet begins + } catch { + print("Failed to create salary", error) + // Code Snippet Ends + // Expected to catch failure since the user is not in the Admin group. + XCTAssertNotNil(error) + // Code Snippet begins + } + } +} + +extension GraphQLSalary18Tests: DefaultLogger { } + +extension GraphQLSalary18Tests { + typealias Salary = Salary18 + + struct Salary18Models: AmplifyModelRegistration { + public let version: String = "version" + func registerModels(registry: ModelRegistry.Type) { + ModelRegistry.register(modelType: Salary18.self) + } + } +} diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18+Schema.swift new file mode 100644 index 0000000000..c38405bfa8 --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18+Schema.swift @@ -0,0 +1,65 @@ +// swiftlint:disable all +import Amplify +import Foundation + +extension Salary18 { + // MARK: - CodingKeys + public enum CodingKeys: String, ModelKey { + case id + case wage + case currency + case createdAt + case updatedAt + } + + public static let keys = CodingKeys.self + // MARK: - ModelSchema + + public static let schema = defineSchema { model in + let salary18 = Salary18.keys + + model.authRules = [ + rule(allow: .groups, groupClaim: "cognito:groups", groups: ["Admin"], provider: .userPools, operations: [.create, .update, .delete, .read]) + ] + + model.listPluralName = "Salary18s" + model.syncPluralName = "Salary18s" + + model.attributes( + .primaryKey(fields: [salary18.id]) + ) + + model.fields( + .field(salary18.id, is: .required, ofType: .string), + .field(salary18.wage, is: .optional, ofType: .double), + .field(salary18.currency, is: .optional, ofType: .string), + .field(salary18.createdAt, is: .optional, isReadOnly: true, ofType: .dateTime), + .field(salary18.updatedAt, is: .optional, isReadOnly: true, ofType: .dateTime) + ) + } + public class Path: ModelPath { } + + public static var rootPath: PropertyContainerPath? { Path() } +} + +extension Salary18: ModelIdentifiable { + public typealias IdentifierFormat = ModelIdentifierFormat.Default + public typealias IdentifierProtocol = DefaultModelIdentifier +} +extension ModelPath where ModelType == Salary18 { + public var id: FieldPath { + string("id") + } + public var wage: FieldPath { + double("wage") + } + public var currency: FieldPath { + string("currency") + } + public var createdAt: FieldPath { + datetime("createdAt") + } + public var updatedAt: FieldPath { + datetime("updatedAt") + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18.swift new file mode 100644 index 0000000000..041e8faaea --- /dev/null +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_18/Salary18.swift @@ -0,0 +1,32 @@ +// swiftlint:disable all +import Amplify +import Foundation + +public struct Salary18: Model { + public let id: String + public var wage: Double? + public var currency: String? + public var createdAt: Temporal.DateTime? + public var updatedAt: Temporal.DateTime? + + public init(id: String = UUID().uuidString, + wage: Double? = nil, + currency: String? = nil) { + self.init(id: id, + wage: wage, + currency: currency, + createdAt: nil, + updatedAt: nil) + } + internal init(id: String = UUID().uuidString, + wage: Double? = nil, + currency: String? = nil, + createdAt: Temporal.DateTime? = nil, + updatedAt: Temporal.DateTime? = nil) { + self.id = id + self.wage = wage + self.currency = currency + self.createdAt = createdAt + self.updatedAt = updatedAt + } +} \ No newline at end of file diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/GraphQLPostPerson41Tests.swift similarity index 100% rename from AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/GraphQLPostPerson41Tests.swift rename to AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/GraphQLPostPerson41Tests.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Person41+Schema.swift similarity index 100% rename from AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41+Schema.swift rename to AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Person41+Schema.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Person41.swift similarity index 100% rename from AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Person41.swift rename to AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Person41.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Post41+Schema.swift similarity index 100% rename from AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41+Schema.swift rename to AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Post41+Schema.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Post41.swift similarity index 100% rename from AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_41/Post41.swift rename to AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/Gen2_4/Gen2_41/Post41.swift diff --git a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md index d2854a9fbf..f23f0706c9 100644 --- a/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md +++ b/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGen2GraphQLTests/README.md @@ -77,10 +77,10 @@ const schema = a.schema({ Post1: a.model({ location: a.ref('Location1'), content: a.string(), - }), + }).authorization(allow => [allow.publicApiKey()]), User1: a.model({ lastKnownLocation: a.ref('Location1'), - }), + }).authorization(allow => [allow.publicApiKey()]), // Gen2_2 // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/add-fields/#specify-an-enum-field-type @@ -92,10 +92,10 @@ const schema = a.schema({ Post2: a.model({ content: a.string(), privacySetting: a.ref('PrivacySetting2'), - }), + }).authorization(allow => [allow.publicApiKey()]), Video2: a.model({ privacySetting: a.ref('PrivacySetting2'), - }), + }).authorization(allow => [allow.publicApiKey()]), // Gen2_3 // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-one-to-many-relationships @@ -124,16 +124,16 @@ const schema = a.schema({ customerId: a.id(), // 2. Create relationship field with the reference field customer: a.belongsTo('Customer4', 'customerId'), - }), + }).authorization(allow => [allow.publicApiKey()]), Customer4: a.model({ name: a.string(), // 3. Create relationship field with the reference field // from the Cart model activeCart: a.hasOne('Cart4', 'customerId') - }), + }).authorization(allow => [allow.publicApiKey()]), // Gen2_41 -Model multiple relationships between two models - // http://localhost:3000/swift/build-a-backend/data/data-modeling/relationships/#model-multiple-relationships-between-two-models + // http://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-multiple-relationships-between-two-models Post41: a.model({ title: a.string().required(), content: a.string().required(), @@ -142,19 +142,19 @@ const schema = a.schema({ author: a.belongsTo('Person41', 'authorId'), editorId: a.id(), editor: a.belongsTo('Person41', 'editorId'), - }), + }).authorization(allow => [allow.publicApiKey()]), Person41: a.model({ name: a.string(), editedPosts: a.hasMany('Post41', 'editorId'), authoredPosts: a.hasMany('Post41', 'authorId'), - }), + }).authorization(allow => [allow.publicApiKey()]), // Gen2_5 - Customize data model identifiers // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/ Todo5: a.model({ content: a.string(), completed: a.boolean(), - }), + }).authorization(allow => [allow.publicApiKey()]), // Gen2_6 - Single-field identifier // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/identifiers/#single-field-identifier @@ -162,7 +162,7 @@ const schema = a.schema({ todoId: a.id().required(), content: a.string(), completed: a.boolean(), - }) + }).authorization(allow => [allow.publicApiKey()]) .identifier(['todoId']), // Gen2_7 - Composite identifier @@ -175,7 +175,7 @@ const schema = a.schema({ city: a.string(), zipCode: a.string(), streetAddress: a.string(), - }) + }).authorization(allow => [allow.publicApiKey()]) .identifier(['tenantId', 'name']), // Gen2_8 - Customize secondary indexes @@ -185,7 +185,7 @@ const schema = a.schema({ name: a.string(), phoneNumber: a.phone(), accountRepresentativeId: a.id().required(), - }) + }).authorization(allow => [allow.publicApiKey()]) .secondaryIndexes((index) => [index("accountRepresentativeId")]), // Gen2_9 @@ -195,7 +195,7 @@ const schema = a.schema({ name: a.string(), phoneNumber: a.phone(), accountRepresentativeId: a.id().required(), - }) + }).authorization(allow => [allow.publicApiKey()]) .secondaryIndexes((index) => [ index("accountRepresentativeId") .sortKeys(["name"]), @@ -208,13 +208,73 @@ const schema = a.schema({ name: a.string(), phoneNumber: a.phone(), accountRepresentativeId: a.id().required(), - }) + }).authorization(allow => [allow.publicApiKey()]) .secondaryIndexes((index) => [ index("accountRepresentativeId") .queryField("listByRep"), ]), -}).authorization(allow => [allow.publicApiKey()]); + // Gen2_11 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/#configure-multiple-authorization-rules + Post11: a.model({ + title: a.string(), + content: a.string() + }).authorization(allow => [ + allow.guest().to(["read"]), + allow.owner() + ]), + + // Gen2_12 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/public-data-access/#add-public-authorization-rule-using-api-key-based-authentication + Todo12: a + .model({ + content: a.string(), + }).authorization(allow => [allow.publicApiKey()]), + + // Gen2_13 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/public-data-access/#add-public-authorization-rule-using-amazon-cognito-identity-pools-unauthenticated-role + Todo13: a + .model({ + content: a.string(), + }).authorization(allow => [allow.guest()]), + + // Gen2_14 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/per-user-per-owner-data-access/#add-per-userper-owner-authorization-rule + Todo14: a + .model({ + content: a.string(), + }).authorization(allow => [allow.owner().to(['create', 'read', 'update'])]), + + // Gen2_15 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/multi-user-data-access/#add-multi-user-authorization-rule + Todo15: a + .model({ + content: a.string(), + owners: a.string().array(), + }).authorization(allow => [allow.ownersDefinedIn('owners')]), + + // Gen2_16 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/signed-in-user-data-access/#use-identity-pool-for-signed-in-user-authentication + Todo16: a + .model({ + content: a.string(), + }).authorization(allow => [allow.authenticated()]), + + // Gen2_17 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/signed-in-user-data-access/#use-identity-pool-for-signed-in-user-authentication + Todo17: a + .model({ + content: a.string(), + }).authorization(allow => [allow.authenticated('identityPool')]), + + // Gen2_18 + // https://docs.amplify.aws/swift/build-a-backend/data/customize-authz/user-group-based-data-access/#add-authorization-rules-for-specific-user-groups + Salary18: a + .model({ + wage: a.float(), + currency: a.string(), + }).authorization(allow => [allow.group('Admin')]), +}); ``` @@ -225,7 +285,6 @@ export const data = defineData({ schema, authorizationModes: { defaultAuthorizationMode: 'apiKey', - // API Key is used for a.allow.public() rules apiKeyAuthorizationMode: { expiresInDays: 365, }, @@ -233,6 +292,74 @@ export const data = defineData({ }); ``` + +auth +``` +import { defineAuth, defineFunction } from '@aws-amplify/backend'; + +/** + * Define and configure your auth resource + * @see https://docs.amplify.aws/gen2/build-a-backend/auth + */ +export const auth = defineAuth({ + loginWith: { + email: true + }, + triggers: { + // configure a trigger to point to a function definition + preSignUp: defineFunction({ + entry: './pre-sign-up-handler.ts' + }) + } +}); +``` + +`amplify/auth/pre-sign-up-handler.ts` +``` +import type { PreSignUpTriggerHandler } from 'aws-lambda'; + +export const handler: PreSignUpTriggerHandler = async (event) => { + // your code here + event.response.autoConfirmUser = true + return event; +}; +``` + +backend.ts +``` +import { defineBackend } from '@aws-amplify/backend'; +import { auth } from './auth/resource'; +import { data } from './data/resource'; + + +const backend = defineBackend({ + auth, + data, + //storage + // additional resource +}); + + +// Override sign in with username as the username + +const { cfnUserPool } = backend.auth.resources.cfnResources +cfnUserPool.usernameAttributes = [] + +cfnUserPool.addPropertyOverride( + "Policies", + { + PasswordPolicy: { + MinimumLength: 10, + RequireLowercase: false, + RequireNumbers: true, + RequireSymbols: true, + RequireUppercase: true, + TemporaryPasswordValidityDays: 20, + }, + } +); +``` + 4. Deploy the backend with npx amplify sandbox For example, this deploys to a sandbox env and generates the amplify_outputs.json file.