@aws-amplify/graphql-api-construct 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +202 -201
- package/API.md +7 -7
- package/CHANGELOG.md +12 -0
- package/README.md +210 -20
- package/lib/amplify-dynamodb-table-wrapper.js +1 -1
- package/lib/amplify-graphql-api.d.ts +0 -7
- package/lib/amplify-graphql-api.js +18 -76
- package/lib/amplify-graphql-definition.d.ts +1 -13
- package/lib/amplify-graphql-definition.js +27 -16
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/internal/data-source-config.d.ts +14 -20
- package/lib/internal/data-source-config.js +110 -38
- package/lib/internal/model-type-name.d.ts +2 -2
- package/lib/internal/model-type-name.js +4 -4
- package/lib/{model-datasource-strategy.d.ts → model-datasource-strategy-types.d.ts} +17 -11
- package/lib/model-datasource-strategy-types.js +10 -0
- package/lib/sql-model-datasource-strategy.d.ts +1 -1
- package/lib/sql-model-datasource-strategy.js +4 -4
- package/lib/types.d.ts +1 -9
- package/lib/types.js +1 -1
- package/node_modules/@aws-amplify/graphql-auth-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.js +6 -10
- package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-auth-transformer/lib/utils/validations.js +1 -1
- package/node_modules/@aws-amplify/graphql-auth-transformer/package.json +16 -12
- package/node_modules/@aws-amplify/graphql-default-value-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.js +2 -7
- package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-default-value-transformer/package.json +13 -9
- package/node_modules/@aws-amplify/graphql-function-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.js +7 -0
- package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-function-transformer/package.json +11 -7
- package/node_modules/@aws-amplify/graphql-http-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-http-transformer/package.json +11 -7
- package/node_modules/@aws-amplify/graphql-index-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.js +4 -4
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.d.ts +3 -5
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.js +12 -34
- package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-index-transformer/package.json +13 -9
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/assets/mapping-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.js +3 -4
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.js +3 -3
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-maps-to-transformer/package.json +16 -12
- package/node_modules/@aws-amplify/graphql-model-transformer/API.md +2 -2
- package/node_modules/@aws-amplify/graphql-model-transformer/CHANGELOG.md +7 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.d.ts +1 -3
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.js +61 -68
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-notification-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-patching-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts +8 -8
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js +32 -36
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts +3 -2
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js +70 -34
- package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-model-transformer/package.json +15 -10
- package/node_modules/@aws-amplify/graphql-predictions-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-predictions-transformer/lib/predictionsLambdaFunction.zip +0 -0
- package/node_modules/@aws-amplify/graphql-predictions-transformer/package.json +11 -7
- package/node_modules/@aws-amplify/graphql-relational-transformer/API.md +2 -2
- package/node_modules/@aws-amplify/graphql-relational-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js +14 -7
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js +6 -6
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js +6 -6
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js +8 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js +5 -3
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts +2 -2
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js +18 -6
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts +18 -18
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js +54 -54
- package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-relational-transformer/package.json +14 -10
- package/node_modules/@aws-amplify/graphql-searchable-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/graphql-searchable-transformer.js +1 -1
- package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/streaming-lambda.zip +0 -0
- package/node_modules/@aws-amplify/graphql-searchable-transformer/package.json +12 -8
- package/node_modules/@aws-amplify/graphql-sql-transformer/CHANGELOG.md +6 -0
- package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js +31 -25
- package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-sql-transformer/package.json +12 -8
- package/node_modules/@aws-amplify/graphql-transformer/API.md +3 -17
- package/node_modules/@aws-amplify/graphql-transformer/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts +4 -14
- package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js +8 -15
- package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer/package.json +20 -16
- package/node_modules/@aws-amplify/graphql-transformer/src/graphql-transformer.ts +30 -57
- package/node_modules/@aws-amplify/graphql-transformer-core/API.md +97 -30
- package/node_modules/@aws-amplify/graphql-transformer-core/CHANGELOG.md +7 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts +3 -3
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js +22 -10
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js +4 -2
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts +6 -12
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js +4 -11
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts +0 -9
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts +12 -10
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js +94 -39
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts +10 -22
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js +3 -7
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts +1 -4
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js +1 -4
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts +2 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js +16 -4
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts +7 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts.map +1 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js +15 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js.map +1 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/types.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts +16 -2
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js +21 -5
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts +3 -4
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js +5 -12
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts +11 -8
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js +64 -52
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts +0 -10
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js +1 -58
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts +22 -0
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js +28 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts +2 -2
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js +7 -6
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/package.json +9 -5
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/API.md +32 -68
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/CHANGELOG.md +4 -0
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts +11 -7
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js +1 -3
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts +11 -18
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts +0 -15
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js +1 -10
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js.map +1 -1
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/package.json +7 -3
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/model-datasource/types.ts +50 -18
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts +0 -6
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-context-provider.ts +14 -21
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-datasource-provider.ts +0 -43
- package/node_modules/@aws-amplify/graphql-transformer-interfaces/tsconfig.tsbuildinfo +1 -1
- package/node_modules/graphql-mapping-template/CHANGELOG.md +4 -0
- package/node_modules/graphql-mapping-template/LICENSE +201 -0
- package/node_modules/graphql-mapping-template/package.json +8 -3
- package/node_modules/graphql-transformer-common/API.md +0 -15
- package/node_modules/graphql-transformer-common/CHANGELOG.md +6 -0
- package/node_modules/graphql-transformer-common/LICENSE +201 -0
- package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts +0 -15
- package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts.map +1 -1
- package/node_modules/graphql-transformer-common/lib/ResourceConstants.js +0 -15
- package/node_modules/graphql-transformer-common/lib/ResourceConstants.js.map +1 -1
- package/node_modules/graphql-transformer-common/package.json +8 -3
- package/package.json +24 -19
- package/src/amplify-graphql-api.ts +19 -91
- package/src/amplify-graphql-definition.ts +41 -17
- package/src/index.ts +1 -1
- package/src/internal/data-source-config.ts +146 -52
- package/src/internal/model-type-name.ts +3 -2
- package/src/{model-datasource-strategy.ts → model-datasource-strategy-types.ts} +20 -12
- package/src/sql-model-datasource-strategy.ts +3 -3
- package/src/types.ts +1 -9
- package/lib/model-datasource-strategy.js +0 -10
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts +0 -3
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts.map +0 -1
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.js +0 -15
- package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/graphql-api-construct",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "AppSync GraphQL Api Construct using Amplify GraphQL Transformer.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -75,20 +75,20 @@
|
|
|
75
75
|
"dependencies": {
|
|
76
76
|
"@aws-amplify/backend-output-schemas": "^0.4.0",
|
|
77
77
|
"@aws-amplify/backend-output-storage": "^0.2.2",
|
|
78
|
-
"@aws-amplify/graphql-auth-transformer": "3.
|
|
79
|
-
"@aws-amplify/graphql-default-value-transformer": "2.
|
|
80
|
-
"@aws-amplify/graphql-function-transformer": "2.1.
|
|
81
|
-
"@aws-amplify/graphql-http-transformer": "2.1.
|
|
82
|
-
"@aws-amplify/graphql-index-transformer": "2.
|
|
83
|
-
"@aws-amplify/graphql-maps-to-transformer": "3.
|
|
84
|
-
"@aws-amplify/graphql-model-transformer": "2.
|
|
85
|
-
"@aws-amplify/graphql-predictions-transformer": "2.1.
|
|
86
|
-
"@aws-amplify/graphql-relational-transformer": "2.
|
|
87
|
-
"@aws-amplify/graphql-searchable-transformer": "2.
|
|
88
|
-
"@aws-amplify/graphql-sql-transformer": "0.
|
|
89
|
-
"@aws-amplify/graphql-transformer": "1.3.
|
|
90
|
-
"@aws-amplify/graphql-transformer-core": "2.
|
|
91
|
-
"@aws-amplify/graphql-transformer-interfaces": "3.3.
|
|
78
|
+
"@aws-amplify/graphql-auth-transformer": "3.3.0",
|
|
79
|
+
"@aws-amplify/graphql-default-value-transformer": "2.2.0",
|
|
80
|
+
"@aws-amplify/graphql-function-transformer": "2.1.12",
|
|
81
|
+
"@aws-amplify/graphql-http-transformer": "2.1.12",
|
|
82
|
+
"@aws-amplify/graphql-index-transformer": "2.3.0",
|
|
83
|
+
"@aws-amplify/graphql-maps-to-transformer": "3.4.0",
|
|
84
|
+
"@aws-amplify/graphql-model-transformer": "2.4.0",
|
|
85
|
+
"@aws-amplify/graphql-predictions-transformer": "2.1.12",
|
|
86
|
+
"@aws-amplify/graphql-relational-transformer": "2.3.0",
|
|
87
|
+
"@aws-amplify/graphql-searchable-transformer": "2.4.0",
|
|
88
|
+
"@aws-amplify/graphql-sql-transformer": "0.2.0",
|
|
89
|
+
"@aws-amplify/graphql-transformer": "1.3.4",
|
|
90
|
+
"@aws-amplify/graphql-transformer-core": "2.4.0",
|
|
91
|
+
"@aws-amplify/graphql-transformer-interfaces": "3.3.2",
|
|
92
92
|
"@aws-amplify/platform-core": "^0.2.0",
|
|
93
93
|
"@aws-amplify/plugin-types": "^0.4.1",
|
|
94
94
|
"charenc": "^0.0.2",
|
|
@@ -96,8 +96,8 @@
|
|
|
96
96
|
"fs-extra": "^8.1.0",
|
|
97
97
|
"graceful-fs": "^4.2.11",
|
|
98
98
|
"graphql": "^15.5.0",
|
|
99
|
-
"graphql-mapping-template": "4.20.
|
|
100
|
-
"graphql-transformer-common": "4.
|
|
99
|
+
"graphql-mapping-template": "4.20.13",
|
|
100
|
+
"graphql-transformer-common": "4.27.0",
|
|
101
101
|
"hjson": "^3.2.2",
|
|
102
102
|
"immer": "^9.0.12",
|
|
103
103
|
"is-buffer": "^2.0.5",
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"zod": "^3.22.3"
|
|
113
113
|
},
|
|
114
114
|
"devDependencies": {
|
|
115
|
+
"@aws-amplify/graphql-transformer-test-utils": "0.4.0",
|
|
115
116
|
"@types/fs-extra": "^8.0.1",
|
|
116
117
|
"@types/node": "^12.12.6",
|
|
117
118
|
"aws-cdk-lib": "2.80.0",
|
|
@@ -162,7 +163,11 @@
|
|
|
162
163
|
"functions": 80,
|
|
163
164
|
"lines": 80
|
|
164
165
|
}
|
|
165
|
-
}
|
|
166
|
+
},
|
|
167
|
+
"coverageReporters": [
|
|
168
|
+
"clover",
|
|
169
|
+
"text"
|
|
170
|
+
]
|
|
166
171
|
},
|
|
167
|
-
"gitHead": "
|
|
172
|
+
"gitHead": "6e450d037cf84098b51ce787a99d6023cbc0e39d"
|
|
168
173
|
}
|
|
@@ -29,7 +29,6 @@ import { IEventBus } from 'aws-cdk-lib/aws-events';
|
|
|
29
29
|
import { IFunction } from 'aws-cdk-lib/aws-lambda';
|
|
30
30
|
import { IServerlessCluster } from 'aws-cdk-lib/aws-rds';
|
|
31
31
|
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager';
|
|
32
|
-
import { MYSQL_DB_TYPE, POSTGRES_DB_TYPE, RDSConnectionSecrets } from '@aws-amplify/graphql-transformer-core';
|
|
33
32
|
import { parseUserDefinedSlots, validateFunctionSlots, separateSlots } from './internal/user-defined-slots';
|
|
34
33
|
import type {
|
|
35
34
|
AmplifyGraphqlApiResources,
|
|
@@ -38,6 +37,7 @@ import type {
|
|
|
38
37
|
IBackendOutputStorageStrategy,
|
|
39
38
|
AddFunctionProps,
|
|
40
39
|
ConflictResolution,
|
|
40
|
+
IAmplifyGraphqlDefinition,
|
|
41
41
|
} from './types';
|
|
42
42
|
import {
|
|
43
43
|
convertAuthorizationModesToTransformerAuthConfig,
|
|
@@ -49,10 +49,8 @@ import {
|
|
|
49
49
|
CodegenAssets,
|
|
50
50
|
getAdditionalAuthenticationTypes,
|
|
51
51
|
} from './internal';
|
|
52
|
-
import { mapInterfaceCustomSqlStrategiesToImplementationStrategies, parseDataSourceConfig } from './internal/data-source-config';
|
|
53
52
|
import { getStackForScope, walkAndProcessNodes } from './internal/construct-tree';
|
|
54
|
-
import {
|
|
55
|
-
import { isSQLLambdaModelDataSourceStrategy } from './sql-model-datasource-strategy';
|
|
53
|
+
import { getDataSourceStrategiesProvider } from './internal/data-source-config';
|
|
56
54
|
|
|
57
55
|
/**
|
|
58
56
|
* L3 Construct which invokes the Amplify Transformer Pattern over an input Graphql Schema.
|
|
@@ -156,7 +154,11 @@ export class AmplifyGraphqlApi extends Construct {
|
|
|
156
154
|
outputStorageStrategy,
|
|
157
155
|
} = props;
|
|
158
156
|
|
|
159
|
-
|
|
157
|
+
const dataSources = getMetadataDataSources(definition);
|
|
158
|
+
|
|
159
|
+
new AttributionMetadataStorage().storeAttributionMetadata(Stack.of(scope), this.stackType, path.join(__dirname, '..', 'package.json'), {
|
|
160
|
+
dataSources,
|
|
161
|
+
});
|
|
160
162
|
|
|
161
163
|
const { authConfig, authSynthParameters } = convertAuthorizationModesToTransformerAuthConfig(authorizationModes);
|
|
162
164
|
|
|
@@ -173,7 +175,7 @@ export class AmplifyGraphqlApi extends Construct {
|
|
|
173
175
|
|
|
174
176
|
const assetManager = new AssetManager();
|
|
175
177
|
|
|
176
|
-
|
|
178
|
+
const executeTransformConfig: ExecuteTransformConfig = {
|
|
177
179
|
scope: this,
|
|
178
180
|
nestedStackProvider: {
|
|
179
181
|
provide: (nestedStackScope: Construct, name: string) => new NestedStack(nestedStackScope, name),
|
|
@@ -204,33 +206,12 @@ export class AmplifyGraphqlApi extends Construct {
|
|
|
204
206
|
...defaultTranslationBehavior,
|
|
205
207
|
...(translationBehavior ?? {}),
|
|
206
208
|
},
|
|
207
|
-
|
|
208
|
-
//
|
|
209
|
-
|
|
209
|
+
// CDK construct uses a custom resource. We'll define this explicitly here to remind ourselves that this value is unused in the CDK
|
|
210
|
+
// construct flow
|
|
211
|
+
rdsLayerMapping: undefined,
|
|
212
|
+
...getDataSourceStrategiesProvider(definition),
|
|
210
213
|
};
|
|
211
214
|
|
|
212
|
-
// TODO: Normalize all of this once we start using strategies internally. Right now the data source configuration (VPC, connection info,
|
|
213
|
-
// etc) is separate from the DataSourceType, and singular
|
|
214
|
-
const customSqlDataSourceStrategies = mapInterfaceCustomSqlStrategiesToImplementationStrategies(
|
|
215
|
-
definition.customSqlDataSourceStrategies,
|
|
216
|
-
);
|
|
217
|
-
if (customSqlDataSourceStrategies.length > 0) {
|
|
218
|
-
executeTransformConfig = {
|
|
219
|
-
...executeTransformConfig,
|
|
220
|
-
customSqlDataSourceStrategies,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// TODO: Update this to support multiple definitions; right now we assume only one SQL data source type
|
|
225
|
-
const modelStrategies = Object.values(definition.dataSourceStrategies).filter(isSQLLambdaModelDataSourceStrategy);
|
|
226
|
-
const customSqlStrategies = definition.customSqlDataSourceStrategies?.map((css) => css.strategy) ?? [];
|
|
227
|
-
for (const strategy of [...modelStrategies, ...customSqlStrategies]) {
|
|
228
|
-
if (isSQLLambdaModelDataSourceStrategy(strategy)) {
|
|
229
|
-
executeTransformConfig = this.extendTransformConfig(executeTransformConfig, strategy);
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
215
|
executeTransform(executeTransformConfig);
|
|
235
216
|
|
|
236
217
|
this.codegenAssets = new CodegenAssets(this, 'AmplifyCodegenAssets', { modelSchema: definition.schema });
|
|
@@ -246,66 +227,6 @@ export class AmplifyGraphqlApi extends Construct {
|
|
|
246
227
|
this.apiKey = this.resources.cfnResources.cfnApiKey?.attrApiKey;
|
|
247
228
|
}
|
|
248
229
|
|
|
249
|
-
/**
|
|
250
|
-
* Extends executeTransformConfig with fields for provisioning a SQL Lambda
|
|
251
|
-
* @param executeTransformConfig the executeTransformConfig to extend
|
|
252
|
-
* @param strategy the SQLLambdaModelDataSourceStrategy containing the SQL connection values to add to the transform config
|
|
253
|
-
* @returns the extended configuration that includes SQL DB connection information
|
|
254
|
-
*/
|
|
255
|
-
private extendTransformConfig(
|
|
256
|
-
executeTransformConfig: ExecuteTransformConfig,
|
|
257
|
-
strategy: SQLLambdaModelDataSourceStrategy,
|
|
258
|
-
): ExecuteTransformConfig {
|
|
259
|
-
const extendedConfig = { ...executeTransformConfig };
|
|
260
|
-
|
|
261
|
-
if (strategy.customSqlStatements) {
|
|
262
|
-
extendedConfig.customQueries = new Map(Object.entries(strategy.customSqlStatements));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const dbSecrets: Map<string, RDSConnectionSecrets> = new Map();
|
|
266
|
-
let dbSecretDbTypeKey: string;
|
|
267
|
-
switch (strategy.dbType) {
|
|
268
|
-
case 'MYSQL':
|
|
269
|
-
dbSecretDbTypeKey = MYSQL_DB_TYPE;
|
|
270
|
-
break;
|
|
271
|
-
case 'POSTGRES':
|
|
272
|
-
dbSecretDbTypeKey = POSTGRES_DB_TYPE;
|
|
273
|
-
break;
|
|
274
|
-
default:
|
|
275
|
-
throw new Error(`Unsupported binding type ${strategy.dbType}`);
|
|
276
|
-
}
|
|
277
|
-
dbSecrets.set(dbSecretDbTypeKey, {
|
|
278
|
-
username: strategy.dbConnectionConfig.usernameSsmPath,
|
|
279
|
-
password: strategy.dbConnectionConfig.passwordSsmPath,
|
|
280
|
-
host: strategy.dbConnectionConfig.hostnameSsmPath,
|
|
281
|
-
// Cast through `any` to allow the SSM Path string to be used on a type expecting a number. This flow expects the incoming value to be
|
|
282
|
-
// a string containing the SSM path.
|
|
283
|
-
port: strategy.dbConnectionConfig.portSsmPath as any,
|
|
284
|
-
database: strategy.dbConnectionConfig.databaseNameSsmPath,
|
|
285
|
-
});
|
|
286
|
-
extendedConfig.datasourceSecretParameterLocations = dbSecrets;
|
|
287
|
-
|
|
288
|
-
if (strategy.vpcConfiguration) {
|
|
289
|
-
const subnetAvailabilityZoneConfig = strategy.vpcConfiguration.subnetAvailabilityZoneConfig.map(
|
|
290
|
-
(saz): { subnetId: string; availabilityZone: string } => ({
|
|
291
|
-
subnetId: saz.subnetId,
|
|
292
|
-
availabilityZone: saz.availabilityZone,
|
|
293
|
-
}),
|
|
294
|
-
);
|
|
295
|
-
extendedConfig.sqlLambdaVpcConfig = {
|
|
296
|
-
vpcId: strategy.vpcConfiguration.vpcId,
|
|
297
|
-
securityGroupIds: strategy.vpcConfiguration.securityGroupIds,
|
|
298
|
-
subnetAvailabilityZoneConfig,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
if (strategy.sqlLambdaProvisionedConcurrencyConfig) {
|
|
303
|
-
extendedConfig.sqlLambdaProvisionedConcurrencyConfig = strategy.sqlLambdaProvisionedConcurrencyConfig;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return extendedConfig;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
230
|
/**
|
|
310
231
|
* Stores graphql api output to be used for client config generation
|
|
311
232
|
* @param outputStorageStrategy Strategy to store construct outputs. If no strategy is provided a default strategy will be used.
|
|
@@ -484,3 +405,10 @@ const validateNoOtherAmplifyGraphqlApiInStack = (scope: Construct): void => {
|
|
|
484
405
|
throw new Error('Only one AmplifyGraphqlApi is expected in a stack');
|
|
485
406
|
}
|
|
486
407
|
};
|
|
408
|
+
|
|
409
|
+
const getMetadataDataSources = (definition: IAmplifyGraphqlDefinition): string => {
|
|
410
|
+
const dataSourceDbTypes = Object.values(definition.dataSourceStrategies).map((strategy) => strategy.dbType.toLocaleLowerCase());
|
|
411
|
+
const customSqlDbTypes = (definition.customSqlDataSourceStrategies ?? []).map((strategy) => strategy.strategy.dbType.toLocaleLowerCase());
|
|
412
|
+
const dataSources = [...new Set([...dataSourceDbTypes, ...customSqlDbTypes])].sort();
|
|
413
|
+
return dataSources.join(',');
|
|
414
|
+
};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import * as os from 'os';
|
|
2
2
|
import { SchemaFile } from 'aws-cdk-lib/aws-appsync';
|
|
3
|
+
import { isSqlStrategy } from '@aws-amplify/graphql-transformer-core';
|
|
3
4
|
import { IAmplifyGraphqlDefinition } from './types';
|
|
4
|
-
import {
|
|
5
|
-
import { ModelDataSourceStrategy } from './model-datasource-strategy';
|
|
6
|
-
import {
|
|
5
|
+
import { constructDataSourceStrategies } from './internal';
|
|
6
|
+
import { CustomSqlDataSourceStrategy, ModelDataSourceStrategy } from './model-datasource-strategy-types';
|
|
7
|
+
import {
|
|
8
|
+
constructCustomSqlDataSourceStrategies,
|
|
9
|
+
schemaByMergingDefinitions,
|
|
10
|
+
validateDataSourceStrategy,
|
|
11
|
+
} from './internal/data-source-config';
|
|
7
12
|
|
|
8
13
|
export const DEFAULT_MODEL_DATA_SOURCE_STRATEGY: ModelDataSourceStrategy = {
|
|
9
14
|
dbType: 'DYNAMODB',
|
|
@@ -16,24 +21,21 @@ export const DEFAULT_MODEL_DATA_SOURCE_STRATEGY: ModelDataSourceStrategy = {
|
|
|
16
21
|
export class AmplifyGraphqlDefinition {
|
|
17
22
|
/**
|
|
18
23
|
* Produce a schema definition from a string input.
|
|
19
|
-
*
|
|
20
|
-
* **NOTE** The 'dataSourceStrategy' configuration option is in preview and is not recommended to use with production systems.
|
|
21
|
-
*
|
|
22
24
|
* @param schema the graphql input as a string
|
|
23
25
|
* @param dataSourceStrategy the provisioning definition for datasources that resolve `@model`s and custom SQL statements in this schema.
|
|
24
26
|
* The DynamoDB from CloudFormation will be used by default.
|
|
25
|
-
* @experimental dataSourceStrategy
|
|
26
27
|
* @returns a fully formed amplify graphql definition
|
|
27
28
|
*/
|
|
28
29
|
static fromString(
|
|
29
30
|
schema: string,
|
|
30
31
|
dataSourceStrategy: ModelDataSourceStrategy = DEFAULT_MODEL_DATA_SOURCE_STRATEGY,
|
|
31
32
|
): IAmplifyGraphqlDefinition {
|
|
33
|
+
validateDataSourceStrategy(dataSourceStrategy);
|
|
32
34
|
return {
|
|
33
35
|
schema,
|
|
34
36
|
functionSlots: [],
|
|
35
37
|
referencedLambdaFunctions: {},
|
|
36
|
-
dataSourceStrategies:
|
|
38
|
+
dataSourceStrategies: constructDataSourceStrategies(schema, dataSourceStrategy),
|
|
37
39
|
customSqlDataSourceStrategies: constructCustomSqlDataSourceStrategies(schema, dataSourceStrategy),
|
|
38
40
|
};
|
|
39
41
|
}
|
|
@@ -53,10 +55,6 @@ export class AmplifyGraphqlDefinition {
|
|
|
53
55
|
|
|
54
56
|
/**
|
|
55
57
|
* Convert one or more appsync SchemaFile objects into an Amplify Graphql Schema
|
|
56
|
-
*
|
|
57
|
-
* **NOTE** This API is in preview and is not recommended to use with production systems.
|
|
58
|
-
*
|
|
59
|
-
* @experimental
|
|
60
58
|
* @param filePaths one or more paths to the graphql files to process
|
|
61
59
|
* @param dataSourceStrategy the provisioning definition for datasources that resolve `@model`s in this schema. The DynamoDB from
|
|
62
60
|
* CloudFormation will be used by default.
|
|
@@ -75,10 +73,6 @@ export class AmplifyGraphqlDefinition {
|
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
* Combines multiple IAmplifyGraphqlDefinitions into a single definition.
|
|
78
|
-
*
|
|
79
|
-
* **NOTE** This API is in preview and is not recommended to use with production systems.
|
|
80
|
-
*
|
|
81
|
-
* @experimental
|
|
82
76
|
* @param definitions the definitions to combine
|
|
83
77
|
*/
|
|
84
78
|
static combine(definitions: IAmplifyGraphqlDefinition[]): IAmplifyGraphqlDefinition {
|
|
@@ -88,11 +82,41 @@ export class AmplifyGraphqlDefinition {
|
|
|
88
82
|
if (definitions.length === 1) {
|
|
89
83
|
return definitions[0];
|
|
90
84
|
}
|
|
85
|
+
|
|
86
|
+
// A strategy will be present multiple times in a given definition: once per model. We'll create a unique list per definition to ensure
|
|
87
|
+
// no reuse across definitions.
|
|
88
|
+
let combinedStrategyNames: string[] = [];
|
|
89
|
+
for (const definition of definitions) {
|
|
90
|
+
const definitionStrategyNames = new Set<string>();
|
|
91
|
+
for (const strategy of Object.values(definition.dataSourceStrategies)) {
|
|
92
|
+
if (!isSqlStrategy(strategy)) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const strategyName = strategy.name;
|
|
96
|
+
if (combinedStrategyNames.includes(strategyName)) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`The SQL-based ModelDataSourceStrategy '${strategyName}' was found in multiple definitions, but a strategy name cannot be ` +
|
|
99
|
+
"shared between definitions. To specify a SQL-based API with schemas across multiple files, use 'fromFilesAndStrategy'",
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
definitionStrategyNames.add(strategyName);
|
|
103
|
+
}
|
|
104
|
+
combinedStrategyNames = [...combinedStrategyNames, ...definitionStrategyNames];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const customSqlDataSourceStrategies = definitions.reduce(
|
|
108
|
+
(acc, cur) => [...acc, ...(cur.customSqlDataSourceStrategies ?? [])],
|
|
109
|
+
[] as CustomSqlDataSourceStrategy[],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const mergedSchema = schemaByMergingDefinitions(definitions);
|
|
113
|
+
|
|
91
114
|
return {
|
|
92
|
-
schema:
|
|
115
|
+
schema: mergedSchema,
|
|
93
116
|
functionSlots: [],
|
|
94
117
|
referencedLambdaFunctions: definitions.reduce((acc, cur) => ({ ...acc, ...cur.referencedLambdaFunctions }), {}),
|
|
95
118
|
dataSourceStrategies: definitions.reduce((acc, cur) => ({ ...acc, ...cur.dataSourceStrategies }), {}),
|
|
119
|
+
customSqlDataSourceStrategies,
|
|
96
120
|
};
|
|
97
121
|
}
|
|
98
122
|
}
|
package/src/index.ts
CHANGED
|
@@ -43,4 +43,4 @@ export {
|
|
|
43
43
|
StreamSpecification,
|
|
44
44
|
} from './amplify-dynamodb-table-wrapper';
|
|
45
45
|
export { SQLLambdaModelDataSourceStrategyFactory } from './sql-model-datasource-strategy';
|
|
46
|
-
export * from './model-datasource-strategy';
|
|
46
|
+
export * from './model-datasource-strategy-types';
|
|
@@ -1,37 +1,17 @@
|
|
|
1
|
-
import { parse } from 'graphql';
|
|
1
|
+
import { DefinitionNode, FieldDefinitionNode, InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode, parse, print } from 'graphql';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
DataSourceType,
|
|
5
|
-
SQLLambdaModelProvisionStrategy,
|
|
6
|
-
} from '@aws-amplify/graphql-transformer-interfaces';
|
|
7
|
-
import {
|
|
8
|
-
dataSourceStrategyToDataSourceType,
|
|
3
|
+
isBuiltInGraphqlNode,
|
|
9
4
|
isSqlStrategy,
|
|
10
5
|
isQueryNode,
|
|
11
6
|
isMutationNode,
|
|
12
7
|
fieldsWithSqlDirective,
|
|
13
8
|
} from '@aws-amplify/graphql-transformer-core';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* An internal helper to convert from a map of model-to-ModelDataSourceStrategies to the map of model-to-DataSourceTypes that internal
|
|
23
|
-
* transform processing requires. TODO: We can remove this once we refactor the internals to use ModelDataSourceStrategies natively.
|
|
24
|
-
*/
|
|
25
|
-
export const parseDataSourceConfig = (dataSourceDefinitionMap: Record<string, ModelDataSourceStrategy>): DataSourceConfig => {
|
|
26
|
-
const modelToDatasourceMap = new Map<string, DataSourceType>();
|
|
27
|
-
for (const [key, value] of Object.entries(dataSourceDefinitionMap)) {
|
|
28
|
-
const dataSourceType = dataSourceStrategyToDataSourceType(value);
|
|
29
|
-
modelToDatasourceMap.set(key, dataSourceType);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
modelToDatasourceMap,
|
|
33
|
-
};
|
|
34
|
-
};
|
|
9
|
+
import { DataSourceStrategiesProvider } from '@aws-amplify/graphql-transformer-interfaces';
|
|
10
|
+
import {
|
|
11
|
+
CustomSqlDataSourceStrategy as ConstructCustomSqlDataSourceStrategy,
|
|
12
|
+
ModelDataSourceStrategy as ConstructModelDataSourceStrategy,
|
|
13
|
+
} from '../model-datasource-strategy-types';
|
|
14
|
+
import { IAmplifyGraphqlDefinition } from '../types';
|
|
35
15
|
|
|
36
16
|
/**
|
|
37
17
|
* Creates an interface flavor of customSqlDataSourceStrategies from a factory method's schema and data source. Internally, this function
|
|
@@ -40,13 +20,11 @@ export const parseDataSourceConfig = (dataSourceDefinitionMap: Record<string, Mo
|
|
|
40
20
|
*
|
|
41
21
|
* Note that we do not scan for `Subscription` fields: `@sql` directives are not allowed on those, and it wouldn't make sense to do so
|
|
42
22
|
* anyway, since subscriptions are processed from an incoming Mutation, not as the result of a direct datasource access.
|
|
43
|
-
*
|
|
44
|
-
* TODO: Reword this when we refactor to use Strategies throughout the implementation rather than DataSources.
|
|
45
23
|
*/
|
|
46
24
|
export const constructCustomSqlDataSourceStrategies = (
|
|
47
25
|
schema: string,
|
|
48
|
-
dataSourceStrategy:
|
|
49
|
-
):
|
|
26
|
+
dataSourceStrategy: ConstructModelDataSourceStrategy,
|
|
27
|
+
): ConstructCustomSqlDataSourceStrategy[] => {
|
|
50
28
|
if (!isSqlStrategy(dataSourceStrategy)) {
|
|
51
29
|
return [];
|
|
52
30
|
}
|
|
@@ -59,7 +37,7 @@ export const constructCustomSqlDataSourceStrategies = (
|
|
|
59
37
|
return [];
|
|
60
38
|
}
|
|
61
39
|
|
|
62
|
-
const customSqlDataSourceStrategies:
|
|
40
|
+
const customSqlDataSourceStrategies: ConstructCustomSqlDataSourceStrategy[] = [];
|
|
63
41
|
|
|
64
42
|
if (queryNode) {
|
|
65
43
|
const fields = fieldsWithSqlDirective(queryNode);
|
|
@@ -87,25 +65,141 @@ export const constructCustomSqlDataSourceStrategies = (
|
|
|
87
65
|
};
|
|
88
66
|
|
|
89
67
|
/**
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* DataSourceType).
|
|
93
|
-
*
|
|
94
|
-
* TODO: Remove this once we refactor the internals to use strategies rather than DataSourceTypes
|
|
68
|
+
* Extracts the data source provider from the definition. This jumps through some hoops to avoid changing the public interface. If we decide
|
|
69
|
+
* to change the public interface to simplify the structure, then this process gets a lot simpler.
|
|
95
70
|
*/
|
|
96
|
-
export const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
71
|
+
export const getDataSourceStrategiesProvider = (definition: IAmplifyGraphqlDefinition): DataSourceStrategiesProvider => {
|
|
72
|
+
const provider: DataSourceStrategiesProvider = {
|
|
73
|
+
// We can directly use the interface strategies, even though the SQL strategies have the customSqlStatements field that is unused by the
|
|
74
|
+
// transformer flavor of this type
|
|
75
|
+
dataSourceStrategies: definition.dataSourceStrategies,
|
|
76
|
+
sqlDirectiveDataSourceStrategies: [],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// We'll collect all the custom SQL statements from the definition into a single map, and use that to make our
|
|
80
|
+
// SqlDirectiveDataSourceStrategies
|
|
81
|
+
const customSqlStatements: Record<string, string> = {};
|
|
82
|
+
|
|
83
|
+
const constructSqlStrategies = definition.customSqlDataSourceStrategies ?? [];
|
|
84
|
+
|
|
85
|
+
// Note that we're relying on the `customSqlStatements` object reference to stay the same throughout this loop. Don't reassign it, or the
|
|
86
|
+
// collected sqlDirectiveStrategies will break
|
|
87
|
+
constructSqlStrategies.forEach((sqlStrategy) => {
|
|
88
|
+
if (sqlStrategy.strategy.customSqlStatements) {
|
|
89
|
+
Object.assign(customSqlStatements, sqlStrategy.strategy.customSqlStatements);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
provider.sqlDirectiveDataSourceStrategies!.push({
|
|
93
|
+
typeName: sqlStrategy.typeName,
|
|
94
|
+
fieldName: sqlStrategy.fieldName,
|
|
95
|
+
strategy: sqlStrategy.strategy,
|
|
96
|
+
customSqlStatements,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
return provider;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new schema by merging the individual schemas contained in the definitions, combining fields of the Query and Mutation types in
|
|
105
|
+
* individual definitions into a single combined definition. Adding directives to `Query` and `Mutation` types participating in a
|
|
106
|
+
* combination is not supported (the behavior is undefined whether those directives are migrated).
|
|
107
|
+
*/
|
|
108
|
+
export const schemaByMergingDefinitions = (definitions: IAmplifyGraphqlDefinition[]): string => {
|
|
109
|
+
const schema = definitions.map((def) => def.schema).join('\n');
|
|
110
|
+
const parsedSchema = parse(schema);
|
|
111
|
+
|
|
112
|
+
// We store the Query & Mutation definitions separately. Since the interfaces are readonly, we'll have to re-compose the types after we've
|
|
113
|
+
// collected all the fields
|
|
114
|
+
const queryAndMutationDefinitions: Record<
|
|
115
|
+
string,
|
|
116
|
+
{
|
|
117
|
+
node: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode;
|
|
118
|
+
fields: FieldDefinitionNode[];
|
|
119
|
+
}
|
|
120
|
+
> = {};
|
|
121
|
+
|
|
122
|
+
// Throws if the field has already been encountered
|
|
123
|
+
const validateField = (typeName: string, fieldName: string): void => {
|
|
124
|
+
const fields = queryAndMutationDefinitions[typeName]?.fields;
|
|
125
|
+
if (!fields) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (fields.find((field) => field.name.value === fieldName)) {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`The custom ${typeName} field '${fieldName}' was found in multiple definitions, but a field name cannot be shared between definitions.`,
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Transform the schema by reducing Mutation & Query types:
|
|
136
|
+
// - Collect Mutation and Query definitions
|
|
137
|
+
// - Alter the parsed schema by filtering out Mutation & Query types
|
|
138
|
+
// - Add the combined Mutation & Query definitions to the filtered schema
|
|
139
|
+
parsedSchema.definitions.filter(isBuiltInGraphqlNode).forEach((def) => {
|
|
140
|
+
const typeName = def.name.value;
|
|
141
|
+
if (!queryAndMutationDefinitions[typeName]) {
|
|
142
|
+
queryAndMutationDefinitions[typeName] = {
|
|
143
|
+
node: def,
|
|
144
|
+
// `ObjectTypeDefinitionNode.fields` is a ReadonlyArray; so we have to create a new mutable array to collect all the fields
|
|
145
|
+
fields: [...(def.fields ?? [])],
|
|
146
|
+
};
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
(def.fields ?? []).forEach((field) => {
|
|
151
|
+
validateField(typeName, field.name.value);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
queryAndMutationDefinitions[typeName].fields = [...queryAndMutationDefinitions[typeName].fields, ...(def.fields ?? [])];
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Gather the collected Query & Mutation fields into <=2 new definitions
|
|
158
|
+
const combinedDefinitions = Object.values(queryAndMutationDefinitions)
|
|
159
|
+
.sort((a, b) => a.node.name.value.localeCompare(b.node.name.value))
|
|
160
|
+
.reduce((acc, cur) => {
|
|
161
|
+
const definitionNode = {
|
|
162
|
+
...cur.node,
|
|
163
|
+
fields: cur.fields,
|
|
164
|
+
};
|
|
165
|
+
return [...acc, definitionNode];
|
|
166
|
+
}, [] as DefinitionNode[]);
|
|
167
|
+
|
|
168
|
+
// Filter out the old Query & Mutation definitions
|
|
169
|
+
const filteredDefinitions = parsedSchema.definitions.filter((def) => !isBuiltInGraphqlNode(def));
|
|
170
|
+
|
|
171
|
+
// Compose the new schema by appending the collected definitions to the filtered definitions. This means that every query will be
|
|
172
|
+
// rewritten such that the Mutation and Query types appear at the end of the schema.
|
|
173
|
+
const newSchema = {
|
|
174
|
+
...parsedSchema,
|
|
175
|
+
definitions: [...filteredDefinitions, ...combinedDefinitions],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const combinedSchemaString = print(newSchema);
|
|
179
|
+
return combinedSchemaString;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/*
|
|
183
|
+
* Validates the user input for the dataSourceStrategy. This is a no-op for DynamoDB strategies for now.
|
|
184
|
+
* @param strategy user provided model data source strategy
|
|
185
|
+
* @returns validates and throws an error if the strategy is invalid
|
|
186
|
+
*/
|
|
187
|
+
export const validateDataSourceStrategy = (strategy: ConstructModelDataSourceStrategy) => {
|
|
188
|
+
if (!isSqlStrategy(strategy)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const dbConnectionConfig = strategy.dbConnectionConfig;
|
|
193
|
+
const invalidSSMPaths = Object.values(dbConnectionConfig).filter((value) => typeof value === 'string' && !isValidSSMPath(value));
|
|
194
|
+
if (invalidSSMPaths.length > 0) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`Invalid data source strategy "${
|
|
197
|
+
strategy.name
|
|
198
|
+
}". Following SSM paths must start with '/' in dbConnectionConfig: ${invalidSSMPaths.join(', ')}.`,
|
|
199
|
+
);
|
|
101
200
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
dbType: normalizeDbType(interfaceStrategy.strategy.dbType),
|
|
107
|
-
provisionDB: false,
|
|
108
|
-
provisionStrategy: SQLLambdaModelProvisionStrategy.DEFAULT,
|
|
109
|
-
},
|
|
110
|
-
}));
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const isValidSSMPath = (path: string): boolean => {
|
|
204
|
+
return path.startsWith('/');
|
|
111
205
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Kind, ObjectTypeDefinitionNode, StringValueNode, parse } from 'graphql';
|
|
2
|
-
import { ModelDataSourceStrategy } from '../model-datasource-strategy';
|
|
2
|
+
import { ModelDataSourceStrategy } from '../model-datasource-strategy-types';
|
|
3
3
|
|
|
4
4
|
const MODEL_DIRECTIVE_NAME = 'model';
|
|
5
5
|
const MANY_TO_MANY_DIRECTIVE_NAME = 'manyToMany';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Get the type names with model directives in the GraphQL schema in SDL
|
|
8
9
|
* @param schema graphql schema in SDL
|
|
@@ -30,7 +31,7 @@ export const getModelTypeNames = (schema: string): string[] => {
|
|
|
30
31
|
return modelKeys.filter((key, idx) => modelKeys.indexOf(key) === idx);
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export const
|
|
34
|
+
export const constructDataSourceStrategies = (
|
|
34
35
|
schema: string,
|
|
35
36
|
dataSourceStrategy: ModelDataSourceStrategy,
|
|
36
37
|
): Record<string, ModelDataSourceStrategy> => {
|