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] 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.