![]() * move to Sources and Tests for API * update Package.swift * Add APIHostApp, rename to drop Category naming * APIHostApp compiling with AmplifyTestCommon files * APIFunctional tets working * add additional schemas * Remove AWSPluginCore dependency * revert unintended changes * remove unintended changes * remove unintented changes * fix unintended changes * fix unintended changes |
||
---|---|---|
.. | ||
GraphQLAuthDirectiveIntegrationTests+Auth.swift | ||
GraphQLAuthDirectiveIntegrationTests+Support.swift | ||
GraphQLAuthDirectiveIntegrationTests.swift | ||
README.md | ||
SocialNote.swift |
README.md
GraphQL with UserPool Auth Integration Tests
The following steps demonstrate how to set up an GraphQL endpoint with AppSync. The auth configured will be Cognito UserPools. This set up is used to run the tests in GraphQLAuthDirectiveIntegrationTests.swift
.
Set-up
-
amplify init
-
amplify add api
? Please select from one of the below mentioned services: GraphQL
? Provide API name: `<APIName>`
? Choose the default authorization type for the API `Amazon Cognito User Pool`
? Do you want to use the default authentication and security configuration? `Default configuration`
? How do you want users to be able to sign in? `Email`
? Do you want to configure advanced settings? `No, I am done.`
? Do you want to configure advanced settings for the GraphQL API `No, I am done.`
? Do you have an annotated GraphQL schema? `No`
? Do you want a guided schema creation? `Yes`
? What best describes your project: `Single object with fields (e.g., “Todo” with ID, name, description)`
? Do you want to edit the schema now? `No`
The guided schema provided should look like this:
type SocialNote
@model
@auth(rules: [
{ allow: owner, ownerField: "owner", operations: [create, update, delete] },
]) {
id: ID!
content: String!
owner: String
}
-
amplify update api
? Please select from one of the below mentioned services:GraphQL
? Select from the options belowEnable DataStore for entire API
-
amplify push
? Are you sure you want to continue? `Yes`
? Do you want to generate code for your newly created GraphQL API `No`
- Copy
amplifyconfiguration.json
over asGraphQLAuthDirectiveIntegrationTests-amplifyconfiguration.json
to~/.aws-amplify/amplify-ios/testconfiguration/
- Create
GraphQLAuthDirectiveIntegrationTests-credentials.json
inside~/.aws-amplify/amplify-ios/testconfiguration/
with a json object containinguser1
, andpassword
, used to create the cognito user in the userpool. In step 2, the cognito userpool is configured to allow users to sign up with their email as the username.
{
"user1": "[USER EMAIL]",
"passwordUser1": "[PASSWORD]"
"user2": "[USER2 EMAIL]",
"passwordUser2": "[PASSWORD]"
}
- Create a two new users in the userpool. First, retrieve the Cognito User Pool's Pool Id, you can find this in
amplifyconfiguration.json
under
"CognitoUserPool": {
"Default": {
"PoolId": "[POOL_ID]",
Run the admin-create-user
command to create a new user
aws cognito-idp admin-create-user --user-pool-id [POOL_ID] --username [USER EMAIL]
Run the admin-set-user-password
command to confirm the user
aws cognito-idp admin-set-user-password --user-pool-id [POOL_ID] --username [USER EMAIL] --password [PASSWORD] --permanent
See https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/index.html#cli-aws-cognito-idp for more details using AWS CLI
You can now run the tests!