Skip to content

Commit

Permalink
fix: propagate mutation context to relational fields (aws-amplify#2416)
Browse files Browse the repository at this point in the history
* chore: remove unused makeExportName utility
* test: add getTableNameForModel test
* chore: reduce coverage threshold
* chore: split e2es
  • Loading branch information
palpatim authored Apr 8, 2024
1 parent 64a1b7f commit fd7f6fb
Show file tree
Hide file tree
Showing 35 changed files with 23,796 additions and 389 deletions.
698 changes: 350 additions & 348 deletions codebuild_specs/e2e_workflow.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dependency_licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ Apache License

-----

The following software may be included in this product: @aws-sdk/client-cloudwatch-logs, @aws-sdk/client-cognito-identity, @aws-sdk/client-comprehend, @aws-sdk/client-dynamodb, @aws-sdk/client-ec2, @aws-sdk/client-firehose, @aws-sdk/client-iam, @aws-sdk/client-kinesis, @aws-sdk/client-kms, @aws-sdk/client-lambda, @aws-sdk/client-lex-runtime-service, @aws-sdk/client-personalize-events, @aws-sdk/client-pinpoint, @aws-sdk/client-polly, @aws-sdk/client-rds, @aws-sdk/client-rekognition, @aws-sdk/client-s3, @aws-sdk/client-secrets-manager, @aws-sdk/client-ssm, @aws-sdk/client-sso, @aws-sdk/client-sso-oidc, @aws-sdk/client-sts, @aws-sdk/client-textract, @aws-sdk/client-translate, @aws-sdk/credential-provider-cognito-identity, @aws-sdk/eventstream-codec, @aws-sdk/eventstream-marshaller, @aws-sdk/middleware-apply-body-checksum, @aws-sdk/middleware-bucket-endpoint, @aws-sdk/middleware-endpoint-discovery, @aws-sdk/middleware-eventstream, @aws-sdk/middleware-expect-continue, @aws-sdk/middleware-header-default, @aws-sdk/middleware-location-constraint, @aws-sdk/middleware-retry, @aws-sdk/middleware-sdk-rds, @aws-sdk/middleware-sdk-sts, @aws-sdk/middleware-ssec, @aws-sdk/querystring-builder, @aws-sdk/querystring-parser, @aws-sdk/service-error-classification, @aws-sdk/url-parser, @aws-sdk/url-parser-native, @aws-sdk/util-defaults-mode-browser, @aws-sdk/util-defaults-mode-node, @aws-sdk/util-user-agent-browser, @aws-sdk/util-user-agent-node, @smithy/eventstream-codec, @smithy/middleware-retry, @smithy/querystring-builder, @smithy/querystring-parser, @smithy/service-error-classification, @smithy/url-parser, @smithy/util-defaults-mode-browser, @smithy/util-defaults-mode-node. A copy of the source code may be downloaded from https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-cloudwatch-logs), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-cognito-identity), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-comprehend), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-dynamodb), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-ec2), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-firehose), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-iam), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-kinesis), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-kms), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-lambda), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-lex-runtime-service), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-personalize-events), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-pinpoint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-polly), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-rds), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-rekognition), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-s3), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-secrets-manager), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-ssm), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sso), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sso-oidc), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sts), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-textract), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-translate), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/credential-provider-cognito-identity), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/eventstream-codec), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/eventstream-marshaller), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-apply-body-checksum), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-bucket-endpoint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-endpoint-discovery), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-eventstream), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-expect-continue), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-header-default), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-location-constraint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-retry), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-sdk-rds), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-sdk-sts), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-ssec), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/querystring-builder), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/querystring-parser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/service-error-classification), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/url-parser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/url-parser-native), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-defaults-mode-browser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-defaults-mode-node), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-user-agent-browser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-user-agent-node), https://github.com/awslabs/smithy-typescript.git (@smithy/eventstream-codec), https://github.com/awslabs/smithy-typescript.git (@smithy/middleware-retry), https://github.com/awslabs/smithy-typescript.git (@smithy/querystring-builder), https://github.com/awslabs/smithy-typescript.git (@smithy/querystring-parser), https://github.com/awslabs/smithy-typescript.git (@smithy/service-error-classification), https://github.com/awslabs/smithy-typescript.git (@smithy/url-parser), https://github.com/awslabs/smithy-typescript.git (@smithy/util-defaults-mode-browser), https://github.com/awslabs/smithy-typescript.git (@smithy/util-defaults-mode-node). This software contains the following license and notice below:
The following software may be included in this product: @aws-sdk/client-cloudwatch-logs, @aws-sdk/client-cognito-identity, @aws-sdk/client-cognito-identity-provider, @aws-sdk/client-comprehend, @aws-sdk/client-dynamodb, @aws-sdk/client-ec2, @aws-sdk/client-firehose, @aws-sdk/client-iam, @aws-sdk/client-kinesis, @aws-sdk/client-kms, @aws-sdk/client-lambda, @aws-sdk/client-lex-runtime-service, @aws-sdk/client-personalize-events, @aws-sdk/client-pinpoint, @aws-sdk/client-polly, @aws-sdk/client-rds, @aws-sdk/client-rekognition, @aws-sdk/client-s3, @aws-sdk/client-secrets-manager, @aws-sdk/client-ssm, @aws-sdk/client-sso, @aws-sdk/client-sso-oidc, @aws-sdk/client-sts, @aws-sdk/client-textract, @aws-sdk/client-translate, @aws-sdk/credential-provider-cognito-identity, @aws-sdk/eventstream-codec, @aws-sdk/eventstream-marshaller, @aws-sdk/middleware-apply-body-checksum, @aws-sdk/middleware-bucket-endpoint, @aws-sdk/middleware-endpoint-discovery, @aws-sdk/middleware-eventstream, @aws-sdk/middleware-expect-continue, @aws-sdk/middleware-header-default, @aws-sdk/middleware-location-constraint, @aws-sdk/middleware-retry, @aws-sdk/middleware-sdk-rds, @aws-sdk/middleware-sdk-sts, @aws-sdk/middleware-ssec, @aws-sdk/querystring-builder, @aws-sdk/querystring-parser, @aws-sdk/service-error-classification, @aws-sdk/url-parser, @aws-sdk/url-parser-native, @aws-sdk/util-defaults-mode-browser, @aws-sdk/util-defaults-mode-node, @aws-sdk/util-user-agent-browser, @aws-sdk/util-user-agent-node, @smithy/eventstream-codec, @smithy/middleware-retry, @smithy/querystring-builder, @smithy/querystring-parser, @smithy/service-error-classification, @smithy/url-parser, @smithy/util-defaults-mode-browser, @smithy/util-defaults-mode-node. A copy of the source code may be downloaded from https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-cloudwatch-logs), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-cognito-identity), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-cognito-identity-provider), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-comprehend), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-dynamodb), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-ec2), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-firehose), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-iam), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-kinesis), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-kms), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-lambda), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-lex-runtime-service), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-personalize-events), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-pinpoint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-polly), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-rds), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-rekognition), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-s3), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-secrets-manager), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-ssm), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sso), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sso-oidc), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-sts), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-textract), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/client-translate), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/credential-provider-cognito-identity), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/eventstream-codec), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/eventstream-marshaller), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-apply-body-checksum), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-bucket-endpoint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-endpoint-discovery), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-eventstream), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-expect-continue), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-header-default), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-location-constraint), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-retry), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-sdk-rds), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-sdk-sts), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/middleware-ssec), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/querystring-builder), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/querystring-parser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/service-error-classification), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/url-parser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/url-parser-native), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-defaults-mode-browser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-defaults-mode-node), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-user-agent-browser), https://github.com/aws/aws-sdk-js-v3.git (@aws-sdk/util-user-agent-node), https://github.com/awslabs/smithy-typescript.git (@smithy/eventstream-codec), https://github.com/awslabs/smithy-typescript.git (@smithy/middleware-retry), https://github.com/awslabs/smithy-typescript.git (@smithy/querystring-builder), https://github.com/awslabs/smithy-typescript.git (@smithy/querystring-parser), https://github.com/awslabs/smithy-typescript.git (@smithy/service-error-classification), https://github.com/awslabs/smithy-typescript.git (@smithy/url-parser), https://github.com/awslabs/smithy-typescript.git (@smithy/util-defaults-mode-browser), https://github.com/awslabs/smithy-typescript.git (@smithy/util-defaults-mode-node). This software contains the following license and notice below:

Apache License
Version 2.0, January 2004
Expand Down
1 change: 1 addition & 0 deletions packages/amplify-graphql-api-construct-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@aws-amplify/graphql-api-construct": "1.7.0",
"@aws-cdk/aws-cognito-identitypool-alpha": "2.80.0-alpha.0",
"@aws-sdk/client-cognito-identity-provider": "3.338.0",
"@aws-sdk/client-lambda": "3.338.0",
"@aws-sdk/client-rds": "3.338.0",
"@faker-js/faker": "^8.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env node
import 'source-map-support/register';
import * as fs from 'fs';
import * as path from 'path';
import { App, CfnOutput, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
import { UserPool } from 'aws-cdk-lib/aws-cognito';
import {
AmplifyGraphqlApi,
AmplifyGraphqlDefinition,
IAmplifyGraphqlDefinition,
ModelDataSourceStrategy,
} from '@aws-amplify/graphql-api-construct';

interface TestDefinition {
schema: string;
strategy: ModelDataSourceStrategy;
}

const definitionFromTestDefinition = (testDefinition: TestDefinition): IAmplifyGraphqlDefinition => {
const { schema, strategy } = testDefinition;
return AmplifyGraphqlDefinition.fromString(schema, strategy);
};

const combineTestDefinitionsInDirectory = (directory: string): IAmplifyGraphqlDefinition => {
const definitions = fs
.readdirSync(directory)
.filter((file) => file.endsWith('.test-definition.json'))
.map((file) => path.join(directory, file))
.map((fullPath) => fs.readFileSync(fullPath).toString())
.map((fileContents) => JSON.parse(fileContents) as TestDefinition)
.map(definitionFromTestDefinition);

return AmplifyGraphqlDefinition.combine(definitions);
};

// Keeping this short so we don't bump up against resource length limits (e.g., 140 characters for lambda layers).
// arn:aws:lambda:ap-northeast-2:012345678901:layer:${PREFIX}ApiAmplifyCodegenAssetsAmplifyCodegenAssetsDeploymentAwsCliLayerABCDEF12:1
const PREFIX = 'RFAuthTest';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJson = require('../package.json');

// Stack setup

const app = new App();
const stackName = packageJson.name.replace(/_/g, '-');
const stack = new Stack(app, stackName, {
env: { region: process.env.CLI_REGION || 'us-west-2' },
});

const userPool = new UserPool(stack, `${PREFIX}UserPool`, {
deletionProtection: false,
});
userPool.applyRemovalPolicy(RemovalPolicy.DESTROY);

// Allow username/password without SRP, so our tests can easily login without having to set up an Amplify project and client library. Also
// enable SRP, so we can troubleshoot in the console if need be.
const userPoolClient = userPool.addClient(`${PREFIX}UserPoolClient`, {
authFlows: {
userPassword: true,
userSrp: true,
},
});

const testDefinitionDir = path.normalize(path.join(__dirname, '..'));
const combinedDefinition = combineTestDefinitionsInDirectory(testDefinitionDir);

new AmplifyGraphqlApi(stack, `${PREFIX}Api`, {
definition: combinedDefinition,
authorizationModes: {
defaultAuthorizationMode: 'AMAZON_COGNITO_USER_POOLS',
userPoolConfig: { userPool },
apiKeyConfig: { expires: Duration.days(360) },
},
});

new CfnOutput(stack, 'UserPoolId', { value: userPool.userPoolId });
new CfnOutput(stack, 'UserPoolClientId', { value: userPoolClient.userPoolClientId });
Loading

0 comments on commit fd7f6fb

Please sign in to comment.