amplify-swift/AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginIntegrationTests/GraphQL/GraphQLWithUserPoolIntegrat.../AuthDirective
Michael Law 6d5a290cac
chore: APIHostApp for running APIPlugin integration tests (#2029)
* 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
2022-07-21 17:43:54 -04:00
..
GraphQLAuthDirectiveIntegrationTests+Auth.swift chore: APIHostApp for running APIPlugin integration tests (#2029) 2022-07-21 17:43:54 -04:00
GraphQLAuthDirectiveIntegrationTests+Support.swift chore: APIHostApp for running APIPlugin integration tests (#2029) 2022-07-21 17:43:54 -04:00
GraphQLAuthDirectiveIntegrationTests.swift chore: APIHostApp for running APIPlugin integration tests (#2029) 2022-07-21 17:43:54 -04:00
README.md chore: APIHostApp for running APIPlugin integration tests (#2029) 2022-07-21 17:43:54 -04:00
SocialNote.swift chore: APIHostApp for running APIPlugin integration tests (#2029) 2022-07-21 17:43:54 -04:00

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

  1. amplify init

  2. 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
}
  1. amplify update api ? Please select from one of the below mentioned services: GraphQL ? Select from the options below Enable DataStore for entire API

  2. amplify push

? Are you sure you want to continue? `Yes`
? Do you want to generate code for your newly created GraphQL API `No`
  1. Copy amplifyconfiguration.json over as GraphQLAuthDirectiveIntegrationTests-amplifyconfiguration.json to ~/.aws-amplify/amplify-ios/testconfiguration/
  2. Create GraphQLAuthDirectiveIntegrationTests-credentials.json inside ~/.aws-amplify/amplify-ios/testconfiguration/ with a json object containing user1, and password, 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]"
}

  1. 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!