Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 107 additions & 114 deletions packages/amplify-graphql-api-construct/.jsii

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/amplify-graphql-api-construct/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export interface AmplifyGraphqlApiProps {
readonly definition: IAmplifyGraphqlDefinition;
readonly functionNameMap?: Record<string, IFunction>;
readonly functionSlots?: FunctionSlot[];
readonly importedAmplifyDynamoDBTableMap?: Record<string, string>;
readonly outputStorageStrategy?: IBackendOutputStorageStrategy;
readonly predictionsBucket?: IBucket;
readonly stackMappings?: Record<string, string>;
Expand Down Expand Up @@ -283,6 +282,8 @@ export interface ImportedAmplifyDynamoDbModelDataSourceStrategy {
readonly dbType: 'DYNAMODB';
// (undocumented)
readonly provisionStrategy: 'IMPORTED_AMPLIFY_TABLE';
// (undocumented)
readonly tableName: string;
}

// @public
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-graphql-api-construct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"global": {
"branches": 90,
"functions": 90,
"lines": 60
"lines": 59
}
},
"coverageReporters": [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
} from './internal';
import { getStackForScope, walkAndProcessNodes } from './internal/construct-tree';
import { getDataSourceStrategiesProvider } from './internal/data-source-config';
import { validateImportedTableMap } from './internal/imported-tables';

/**
* L3 Construct which invokes the Amplify Transformer Pattern over an input Graphql Schema.
Expand Down Expand Up @@ -153,11 +152,8 @@ export class AmplifyGraphqlApi extends Construct {
functionNameMap,
outputStorageStrategy,
dataStoreConfiguration,
importedAmplifyDynamoDBTableMap,
} = props;

validateImportedTableMap(definition, importedAmplifyDynamoDBTableMap);

if (conflictResolution && dataStoreConfiguration) {
throw new Error(
'conflictResolution is deprecated. conflictResolution and dataStoreConfiguration cannot be used together. Please use dataStoreConfiguration.',
Expand Down Expand Up @@ -220,7 +216,7 @@ export class AmplifyGraphqlApi extends Construct {
// construct flow
rdsLayerMapping: undefined,
rdsSnsTopicMapping: undefined,
...getDataSourceStrategiesProvider(definition, importedAmplifyDynamoDBTableMap ?? {}),
...getDataSourceStrategiesProvider(definition),
};

executeTransform(executeTransformConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,12 @@ export const constructCustomSqlDataSourceStrategies = (
* Extracts the data source provider from the definition. This jumps through some hoops to avoid changing the public interface. If we decide
* to change the public interface to simplify the structure, then this process gets a lot simpler.
*/
export const getDataSourceStrategiesProvider = (
definition: IAmplifyGraphqlDefinition,
importedAmplifyDynamoDBTableMap: Record<string, string> = {},
): DataSourceStrategiesProvider => {
export const getDataSourceStrategiesProvider = (definition: IAmplifyGraphqlDefinition): DataSourceStrategiesProvider => {
const provider: DataSourceStrategiesProvider = {
// We can directly use the interface strategies, even though the SQL strategies have the customSqlStatements field that is unused by the
// transformer flavor of this type
dataSourceStrategies: definition.dataSourceStrategies,
sqlDirectiveDataSourceStrategies: [],
importedAmplifyDynamoDBTableMap,
};

// We'll collect all the custom SQL statements from the definition into a single map, and use that to make our
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ export interface AmplifyDynamoDbModelDataSourceStrategy {

// TODO: decide final naming before merging to main
/**
* Use custom resource type 'Custom::ImportedAmplifyDynamoDBTable' to provision table.
* Use custom resource type 'Custom::ImportedAmplifyDynamoDBTable' to manage an imported table.
*
* Tables can be imported only if they meet the following criteria.
* 1. The imported table must have been created with through an Amplify Gen 1 project.
* 2. The imported table must be in the same account and region as this construct.
* 3. The imported table properties must match the corresponding table properties specified in this construct.
* (AttributeDefinitions, KeySchema, GlobalSecondaryIndexes, BillingModeSummary, ProvisionedThroughput, StreamSpecification, SSEDescription, DeletionProtectionEnabled)
*
* The imported tables will follow the auth rules defined in this construct.
* The auth rules of the source Gen 1 project will not apply to the API created by this construct.
* Ensure the correct auth rules have been set to prevent data exposure.
*/
export interface ImportedAmplifyDynamoDbModelDataSourceStrategy {
readonly dbType: 'DYNAMODB';
readonly provisionStrategy: 'IMPORTED_AMPLIFY_TABLE';
readonly tableName: string;
}

/**
Expand Down
8 changes: 1 addition & 7 deletions packages/amplify-graphql-api-construct/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ export interface AmplifyGraphqlApiProps {
readonly translationBehavior?: PartialTranslationBehavior;

/**
* Strategy to store construct outputs. If no outputStorageStrategey is provided a default strategy will be used.
* Strategy to store construct outputs. If no outputStorageStrategy is provided a default strategy will be used.
*/
readonly outputStorageStrategy?: IBackendOutputStorageStrategy;

Expand All @@ -752,12 +752,6 @@ export interface AmplifyGraphqlApiProps {
* For more information, refer to https://docs.amplify.aws/lib/datastore/getting-started/q/platform/js/
*/
readonly dataStoreConfiguration?: DataStoreConfiguration;

// TODO: decide final naming before merging to main
/**
* The table map for the imported tables. The key is the model type name defined in schema; the value is the table name of the existing table
*/
readonly importedAmplifyDynamoDBTableMap?: Record<string, string>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
DDB_AMPLIFY_MANAGED_DATASOURCE_STRATEGY,
DDB_DEFAULT_DATASOURCE_STRATEGY,
validateModelSchema,
IMPORTED_DDB_AMPLIFY_MANAGED_DATASOURCE_STRATEGY,
} from '@aws-amplify/graphql-transformer-core';
import { parse } from 'graphql';
import { ModelTransformer } from '../graphql-model-transformer';
Expand Down Expand Up @@ -32,10 +31,11 @@ describe('ModelTransformer:', () => {
dataSourceStrategies: {
Comment: DDB_DEFAULT_DATASOURCE_STRATEGY,
Post: DDB_AMPLIFY_MANAGED_DATASOURCE_STRATEGY,
Author: IMPORTED_DDB_AMPLIFY_MANAGED_DATASOURCE_STRATEGY,
},
importedAmplifyDynamoDBTableMap: {
Author: 'Author-myApiId-myEnv',
Author: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: 'Author-myApiId-myEnv',
},
},
});
expect(out).toBeDefined();
Expand Down Expand Up @@ -72,13 +72,12 @@ describe('ModelTransformer:', () => {
expect(authorTable.DeletionPolicy).toBe('Retain');
expect(authorTable.Properties.isImported).toBe(true);
expect(authorTable.Properties.tableName).toBe('Author-myApiId-myEnv');
// Validate schema
validateModelSchema(parse(out.schema));

// Outputs should contain a reference to the Arn to the entry point (onEventHandler)
// of the provider for the AmplifyTableManager custom resource.
// If any of these assertions should fail, it is likely caused by a change in the custom resource provider
/** {@link Provider} */ // that caused the entry point ARN to change.
/** {@link Provider} */
// !! This will result in broken redeployments !!
// Friends don't let friends mutate custom resource entry point ARNs.
const outputs = amplifyTableManagerStack.Outputs!;
Expand Down Expand Up @@ -107,7 +106,29 @@ describe('ModelTransformer:', () => {
const onEventHandlerLambda = amplifyTableManagerResources![onEventHandlerResourceName];
expect(onEventHandlerLambda).toBeDefined();
});
it('should throw error when the mapping is not provided for model of imported table strategy', async () => {

it('should throw error when tableName is not set for imported table strategy', async () => {
const validSchema = `
type Post @model {
id: ID!
title: String!
}
`;
const transformOption = {
schema: validSchema,
transformers: [new ModelTransformer()],
dataSourceStrategies: {
Post: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
},
},
};
// @ts-expect-error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume the @ts-expect-error is to suppress the compile warning about the missing tableName attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, updated to clarify

expect(() => testTransform(transformOption)).toThrow('No resource generator assigned for Post with dbType DYNAMODB');
});

it('should throw error when tableName is empty for imported table strategy', async () => {
const validSchema = `
type Post @model {
id: ID!
Expand All @@ -118,9 +139,13 @@ describe('ModelTransformer:', () => {
schema: validSchema,
transformers: [new ModelTransformer()],
dataSourceStrategies: {
Post: IMPORTED_DDB_AMPLIFY_MANAGED_DATASOURCE_STRATEGY,
Post: {
dbType: 'DYNAMODB' as const,
provisionStrategy: 'IMPORTED_AMPLIFY_TABLE' as const,
tableName: '',
},
},
};
expect(() => testTransform(transformOption)).toThrowErrorMatchingInlineSnapshot(`"Cannot find imported table mapping for model Post"`);
expect(() => testTransform(transformOption)).toThrow('No resource generator assigned for Post with dbType DYNAMODB');
});
});
Loading