Skip to content

Commit

Permalink
allow passing in a schema configuration for string based schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
kekami committed Jul 2, 2024
1 parent bc20ab1 commit f905cac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/twenty-pants-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/backend-data': minor
---

allow passing in a schema configuration for string based SQL schemas
17 changes: 16 additions & 1 deletion packages/backend-data/src/convert_schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
DataSourceConfiguration,
DerivedCombinedSchema,
DerivedModelSchema as DerivedDataSchema,
SchemaConfiguration,
} from '@aws-amplify/data-schema-types';
import {
AmplifyDataDefinition,
Expand Down Expand Up @@ -74,7 +75,8 @@ const SQL_DB_TYPES = {
export const convertSchemaToCDK = (
schema: DataSchema,
backendSecretResolver: BackendSecretResolver,
stableBackendIdentifiers: StableBackendIdentifiers
stableBackendIdentifiers: StableBackendIdentifiers,
schemaConfiguration?: SchemaConfiguration
): IAmplifyDataDefinition => {
if (isDataSchema(schema)) {
/**
Expand Down Expand Up @@ -125,6 +127,19 @@ export const convertSchemaToCDK = (
})
) || [],
};
} else if (
schemaConfiguration &&
schemaConfiguration?.database.engine != 'dynamodb'
) {
const provisionStrategyName =
stableBackendIdentifiers.getStableBackendHash();
const dbStrategy = convertDatabaseConfigurationToDataSourceStrategy(
schemaConfiguration.database,
[],
backendSecretResolver,
provisionStrategyName
);
return AmplifyDataDefinition.fromString(schema, dbStrategy);
}

return AmplifyDataDefinition.fromString(schema, DYNAMO_DATA_SOURCE_STRATEGY);
Expand Down
6 changes: 6 additions & 0 deletions packages/backend-data/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DerivedCombinedSchema,
DerivedModelSchema,
SchemaConfiguration,
} from '@aws-amplify/data-schema-types';
import { AmplifyFunction, ConstructFactory } from '@aws-amplify/plugin-types';

Expand Down Expand Up @@ -125,6 +126,11 @@ export type DataProps = {
*/
schema: DataSchemaInput;

/**
* Schema configuration for non-DynamoDB data sources.
*/
schemaConfiguration?: SchemaConfiguration;

/**
* Optional name for the generated Api.
*/
Expand Down

0 comments on commit f905cac

Please sign in to comment.