![]() * chore(api): update graphql lambda auth integ test to async * chore(api): add new target - failing * working target * working tests |
||
---|---|---|
.. | ||
Base | ||
GraphQLWithLambdaAuthIntegrationTests.swift | ||
README.md | ||
Todo.swift |
README.md
GraphQL with Lambda Auth Integration Tests
The following steps demonstrate how to set up an GraphQL endpoint with AppSync. The auth configured will be IAM. This set up is used to run the tests in GraphQLWithLambdaAuthIntegrationTests.swift
.
Set-up
Latest tested with amplify CLI version 9.1.0 amplify -v
-
amplify init
-
amplify add api
? Please select from one of the below mentioned services: `GraphQL`
? Provide API name: graphqlmodelapitests
? Choose the default authorization type for the API `API KEY`
? Do you want to configure advanced settings for the GraphQL API `No, I am done.`
? Do you have an annotated GraphQL schema? `No`
? Choose a schema template: `Single object with fields (e.g., “Todo” with ID, name, description)`
-
If you are using the latest CLI, update cli.json to include
"useExperimentalPipelinedTransformer": false
and"transformerversion": 1
to ensure that it will use the v1 transformer and thenamplify push
? Do you want to generate code for your newly created GraphQL API (Y/n)n
-
Copy
amplifyconfiguration.json
over asGraphQLWithLambdaAuthIntegrationTests-amplifyconfiguration.json
inside~/.aws-amplify/amplify-ios/testconfiguration/
cp amplifyconfiguration.json ~/.aws-amplify/amplify-ios/testconfiguration/GraphQLWithLambdaAuthIntegrationTests-amplifyconfiguration.json
-
Replace the authorization type
API_KEY
withAWS_LAMBDA
inGraphQLWithLambdaAuthIntegrationTests-amplifyconfiguration.json
-
Run
amplify console
to open the AWS Console -
Select
AWS Lambda
and create a new Lambda function called "AuthorizerLambda" with the following content
exports.handler = async (event) => {
console.log(`auth event >`, JSON.stringify(event, null, 2))
const {
authorizationToken,
requestContext: { apiId, accountId },
} = event
const response = {
isAuthorized: authorizationToken === 'custom-lambda-token',
ttlOverride: 10,
}
console.log(`response >`, JSON.stringify(response, null, 2))
return response
};
- still in the AWSConsole, navigate to
AWS AppSync
and select the app you've created before - In the "Settings" panel under "Default authorization mode", set the authorization type as
AWS Lambda
and select the newly created Lambda function
Note: steps 4..9 should be updated when the CLI supports this new authorization type.
You can now run the tests!