-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(graphql-model-transformer): minimal provider framework and inlin…
…e policies (#2490)
- Loading branch information
Showing
18 changed files
with
1,825 additions
and
625 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
768 changes: 292 additions & 476 deletions
768
...ests__/graphql-transformer/override/__snapshots__/model-transformer-override.test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/amplify-graphql-model-transformer/src/__tests__/provider.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Stack, aws_iam, aws_lambda } from 'aws-cdk-lib'; | ||
import { Template } from 'aws-cdk-lib/assertions'; | ||
import path from 'path'; | ||
import { Provider } from '../resources/amplify-dynamodb-table/provider'; | ||
|
||
test('if isComplete is specified, the isComplete framework handler is also included', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const lambdaCode = aws_lambda.Code.fromAsset( | ||
path.join(__dirname, '..', '..', 'lib', 'resources', 'amplify-dynamodb-table', 'amplify-table-manager-lambda'), | ||
{ exclude: ['*.ts'] }, | ||
); | ||
|
||
const onEventRole = new aws_iam.Role(stack, 'OnEventRole', { | ||
assumedBy: new aws_iam.ServicePrincipal('lambda.amazonaws.com'), | ||
managedPolicies: [aws_iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')], | ||
}); | ||
|
||
const isCompleteRole = new aws_iam.Role(stack, 'IsCompleteRole', { | ||
assumedBy: new aws_iam.ServicePrincipal('lambda.amazonaws.com'), | ||
managedPolicies: [aws_iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')], | ||
}); | ||
|
||
// WHEN | ||
new Provider(stack, 'MyProvider', { | ||
lambdaCode, | ||
onEventHandlerName: 'amplify-table-manager-handler.onEvent', | ||
onEventRole, | ||
isCompleteHandlerName: 'amplify-table-manager-handler.isComplete', | ||
isCompleteRole, | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { | ||
Handler: 'amplify-table-manager-handler.onEvent', | ||
Timeout: 840, | ||
Role: { 'Fn::GetAtt': ['OnEventRole56094035', 'Arn'] }, | ||
}); | ||
|
||
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { | ||
Handler: 'amplify-table-manager-handler.isComplete', | ||
Timeout: 840, | ||
Role: { 'Fn::GetAtt': ['IsCompleteRole3501BB5A', 'Arn'] }, | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
packages/amplify-graphql-model-transformer/src/__tests__/util.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { getEnv, log, withRetries } from '../resources/amplify-dynamodb-table/amplify-table-manager-lambda/util'; | ||
|
||
test('withRetries() will invoke a throwing function multiple times', async () => { | ||
let invocations = 0; | ||
const retryOptions = { | ||
attempts: 3, | ||
sleep: 0, | ||
}; | ||
|
||
await expect(() => | ||
withRetries(retryOptions, async () => { | ||
invocations += 1; | ||
throw new Error('Ruh roh!'); | ||
})(), | ||
).rejects.toThrow(/Ruh roh!/); | ||
|
||
expect(invocations).toBeGreaterThan(1); | ||
}); | ||
|
||
test('getEnv succeeds with existing / fails with non-existing', () => { | ||
process.env['FOO'] = 'BAR'; | ||
const fooValue = getEnv('FOO'); | ||
expect(fooValue).toEqual('BAR'); | ||
expect(() => getEnv('')).toThrowError(); | ||
}); | ||
|
||
test('log helper coverage', () => { | ||
log('foo', 'bar'); | ||
log('foo', { bar: 'baz' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.