@aws-amplify/graphql-api-construct 1.4.3 → 1.5.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. package/.jsii +202 -201
  2. package/API.md +7 -7
  3. package/CHANGELOG.md +12 -0
  4. package/README.md +210 -20
  5. package/lib/amplify-dynamodb-table-wrapper.js +1 -1
  6. package/lib/amplify-graphql-api.d.ts +0 -7
  7. package/lib/amplify-graphql-api.js +18 -76
  8. package/lib/amplify-graphql-definition.d.ts +1 -13
  9. package/lib/amplify-graphql-definition.js +27 -16
  10. package/lib/index.d.ts +1 -1
  11. package/lib/index.js +2 -2
  12. package/lib/internal/data-source-config.d.ts +14 -20
  13. package/lib/internal/data-source-config.js +110 -38
  14. package/lib/internal/model-type-name.d.ts +2 -2
  15. package/lib/internal/model-type-name.js +4 -4
  16. package/lib/{model-datasource-strategy.d.ts → model-datasource-strategy-types.d.ts} +17 -11
  17. package/lib/model-datasource-strategy-types.js +10 -0
  18. package/lib/sql-model-datasource-strategy.d.ts +1 -1
  19. package/lib/sql-model-datasource-strategy.js +4 -4
  20. package/lib/types.d.ts +1 -9
  21. package/lib/types.js +1 -1
  22. package/node_modules/@aws-amplify/graphql-auth-transformer/CHANGELOG.md +6 -0
  23. package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.d.ts.map +1 -1
  24. package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.js +6 -10
  25. package/node_modules/@aws-amplify/graphql-auth-transformer/lib/graphql-auth-transformer.js.map +1 -1
  26. package/node_modules/@aws-amplify/graphql-auth-transformer/lib/utils/validations.js +1 -1
  27. package/node_modules/@aws-amplify/graphql-auth-transformer/package.json +16 -12
  28. package/node_modules/@aws-amplify/graphql-default-value-transformer/CHANGELOG.md +6 -0
  29. package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.d.ts.map +1 -1
  30. package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.js +2 -7
  31. package/node_modules/@aws-amplify/graphql-default-value-transformer/lib/graphql-default-value-transformer.js.map +1 -1
  32. package/node_modules/@aws-amplify/graphql-default-value-transformer/package.json +13 -9
  33. package/node_modules/@aws-amplify/graphql-function-transformer/CHANGELOG.md +6 -0
  34. package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.d.ts.map +1 -1
  35. package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.js +7 -0
  36. package/node_modules/@aws-amplify/graphql-function-transformer/lib/graphql-function-transformer.js.map +1 -1
  37. package/node_modules/@aws-amplify/graphql-function-transformer/package.json +11 -7
  38. package/node_modules/@aws-amplify/graphql-http-transformer/CHANGELOG.md +4 -0
  39. package/node_modules/@aws-amplify/graphql-http-transformer/package.json +11 -7
  40. package/node_modules/@aws-amplify/graphql-index-transformer/CHANGELOG.md +6 -0
  41. package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.d.ts.map +1 -1
  42. package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.js +4 -4
  43. package/node_modules/@aws-amplify/graphql-index-transformer/lib/graphql-primary-key-transformer.js.map +1 -1
  44. package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.d.ts +3 -5
  45. package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.d.ts.map +1 -1
  46. package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.js +12 -34
  47. package/node_modules/@aws-amplify/graphql-index-transformer/lib/resolvers/resolvers.js.map +1 -1
  48. package/node_modules/@aws-amplify/graphql-index-transformer/package.json +13 -9
  49. package/node_modules/@aws-amplify/graphql-maps-to-transformer/CHANGELOG.md +6 -0
  50. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/assets/mapping-lambda.zip +0 -0
  51. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.d.ts.map +1 -1
  52. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.js +3 -4
  53. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-maps-to-transformer.js.map +1 -1
  54. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.d.ts.map +1 -1
  55. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.js +3 -3
  56. package/node_modules/@aws-amplify/graphql-maps-to-transformer/lib/graphql-refers-to-transformer.js.map +1 -1
  57. package/node_modules/@aws-amplify/graphql-maps-to-transformer/package.json +16 -12
  58. package/node_modules/@aws-amplify/graphql-model-transformer/API.md +2 -2
  59. package/node_modules/@aws-amplify/graphql-model-transformer/CHANGELOG.md +7 -0
  60. package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.d.ts +1 -3
  61. package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.d.ts.map +1 -1
  62. package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.js +61 -68
  63. package/node_modules/@aws-amplify/graphql-model-transformer/lib/graphql-model-transformer.js.map +1 -1
  64. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-lambda.zip +0 -0
  65. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-notification-lambda.zip +0 -0
  66. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-patching-lambda.zip +0 -0
  67. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts +8 -8
  68. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts.map +1 -1
  69. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js +32 -36
  70. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js.map +1 -1
  71. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts +3 -2
  72. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts.map +1 -1
  73. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js +70 -34
  74. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js.map +1 -1
  75. package/node_modules/@aws-amplify/graphql-model-transformer/package.json +15 -10
  76. package/node_modules/@aws-amplify/graphql-predictions-transformer/CHANGELOG.md +4 -0
  77. package/node_modules/@aws-amplify/graphql-predictions-transformer/lib/predictionsLambdaFunction.zip +0 -0
  78. package/node_modules/@aws-amplify/graphql-predictions-transformer/package.json +11 -7
  79. package/node_modules/@aws-amplify/graphql-relational-transformer/API.md +2 -2
  80. package/node_modules/@aws-amplify/graphql-relational-transformer/CHANGELOG.md +6 -0
  81. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.d.ts.map +1 -1
  82. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js +14 -7
  83. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js.map +1 -1
  84. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.d.ts.map +1 -1
  85. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js +6 -6
  86. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js.map +1 -1
  87. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js +6 -6
  88. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js.map +1 -1
  89. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.d.ts.map +1 -1
  90. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js +8 -1
  91. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js.map +1 -1
  92. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.d.ts.map +1 -1
  93. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js +5 -3
  94. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js.map +1 -1
  95. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts +2 -2
  96. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts.map +1 -1
  97. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.js.map +1 -1
  98. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.d.ts.map +1 -1
  99. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js +18 -6
  100. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js.map +1 -1
  101. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts +18 -18
  102. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts.map +1 -1
  103. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js +54 -54
  104. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js.map +1 -1
  105. package/node_modules/@aws-amplify/graphql-relational-transformer/package.json +14 -10
  106. package/node_modules/@aws-amplify/graphql-searchable-transformer/CHANGELOG.md +6 -0
  107. package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/graphql-searchable-transformer.js +1 -1
  108. package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/streaming-lambda.zip +0 -0
  109. package/node_modules/@aws-amplify/graphql-searchable-transformer/package.json +12 -8
  110. package/node_modules/@aws-amplify/graphql-sql-transformer/CHANGELOG.md +6 -0
  111. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.d.ts.map +1 -1
  112. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js +31 -25
  113. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js.map +1 -1
  114. package/node_modules/@aws-amplify/graphql-sql-transformer/package.json +12 -8
  115. package/node_modules/@aws-amplify/graphql-transformer/API.md +3 -17
  116. package/node_modules/@aws-amplify/graphql-transformer/CHANGELOG.md +4 -0
  117. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts +4 -14
  118. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts.map +1 -1
  119. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js +8 -15
  120. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js.map +1 -1
  121. package/node_modules/@aws-amplify/graphql-transformer/package.json +20 -16
  122. package/node_modules/@aws-amplify/graphql-transformer/src/graphql-transformer.ts +30 -57
  123. package/node_modules/@aws-amplify/graphql-transformer-core/API.md +97 -30
  124. package/node_modules/@aws-amplify/graphql-transformer-core/CHANGELOG.md +7 -0
  125. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts +3 -3
  126. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts.map +1 -1
  127. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js +22 -10
  128. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js.map +1 -1
  129. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts +1 -1
  130. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts.map +1 -1
  131. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js +4 -2
  132. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js.map +1 -1
  133. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts +6 -12
  134. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts.map +1 -1
  135. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js +4 -11
  136. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js.map +1 -1
  137. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts +0 -9
  138. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts.map +1 -1
  139. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts +12 -10
  140. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts.map +1 -1
  141. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js +94 -39
  142. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js.map +1 -1
  143. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts +10 -22
  144. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts.map +1 -1
  145. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js +3 -7
  146. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js.map +1 -1
  147. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts +1 -4
  148. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts.map +1 -1
  149. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js +1 -4
  150. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js.map +1 -1
  151. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts +2 -1
  152. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts.map +1 -1
  153. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js +16 -4
  154. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js.map +1 -1
  155. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts +7 -0
  156. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts.map +1 -0
  157. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js +15 -0
  158. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js.map +1 -0
  159. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/types.d.ts.map +1 -1
  160. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts +16 -2
  161. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts.map +1 -1
  162. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js +21 -5
  163. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js.map +1 -1
  164. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts +3 -4
  165. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts.map +1 -1
  166. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js +5 -12
  167. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js.map +1 -1
  168. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts +11 -8
  169. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts.map +1 -1
  170. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js +64 -52
  171. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js.map +1 -1
  172. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts +0 -10
  173. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts.map +1 -1
  174. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js +1 -58
  175. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js.map +1 -1
  176. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts +22 -0
  177. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts.map +1 -1
  178. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js +28 -1
  179. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js.map +1 -1
  180. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts +2 -2
  181. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts.map +1 -1
  182. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js +7 -6
  183. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js.map +1 -1
  184. package/node_modules/@aws-amplify/graphql-transformer-core/package.json +9 -5
  185. package/node_modules/@aws-amplify/graphql-transformer-interfaces/API.md +32 -68
  186. package/node_modules/@aws-amplify/graphql-transformer-interfaces/CHANGELOG.md +4 -0
  187. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts +11 -7
  188. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts.map +1 -1
  189. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts +1 -1
  190. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts.map +1 -1
  191. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js +1 -3
  192. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js.map +1 -1
  193. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts +11 -18
  194. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts.map +1 -1
  195. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts +0 -15
  196. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts.map +1 -1
  197. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js +1 -10
  198. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js.map +1 -1
  199. package/node_modules/@aws-amplify/graphql-transformer-interfaces/package.json +7 -3
  200. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/model-datasource/types.ts +50 -18
  201. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts +0 -6
  202. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-context-provider.ts +14 -21
  203. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-datasource-provider.ts +0 -43
  204. package/node_modules/@aws-amplify/graphql-transformer-interfaces/tsconfig.tsbuildinfo +1 -1
  205. package/node_modules/graphql-mapping-template/CHANGELOG.md +4 -0
  206. package/node_modules/graphql-mapping-template/LICENSE +201 -0
  207. package/node_modules/graphql-mapping-template/package.json +8 -3
  208. package/node_modules/graphql-transformer-common/API.md +0 -15
  209. package/node_modules/graphql-transformer-common/CHANGELOG.md +6 -0
  210. package/node_modules/graphql-transformer-common/LICENSE +201 -0
  211. package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts +0 -15
  212. package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts.map +1 -1
  213. package/node_modules/graphql-transformer-common/lib/ResourceConstants.js +0 -15
  214. package/node_modules/graphql-transformer-common/lib/ResourceConstants.js.map +1 -1
  215. package/node_modules/graphql-transformer-common/package.json +8 -3
  216. package/package.json +24 -19
  217. package/src/amplify-graphql-api.ts +19 -91
  218. package/src/amplify-graphql-definition.ts +41 -17
  219. package/src/index.ts +1 -1
  220. package/src/internal/data-source-config.ts +146 -52
  221. package/src/internal/model-type-name.ts +3 -2
  222. package/src/{model-datasource-strategy.ts → model-datasource-strategy-types.ts} +20 -12
  223. package/src/sql-model-datasource-strategy.ts +3 -3
  224. package/src/types.ts +1 -9
  225. package/lib/model-datasource-strategy.js +0 -10
  226. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts +0 -3
  227. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts.map +0 -1
  228. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.js +0 -15
  229. 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.4.3",
3
+ "version": "1.5.1-alpha.1+edba38d57",
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.2.3",
79
- "@aws-amplify/graphql-default-value-transformer": "2.1.12",
80
- "@aws-amplify/graphql-function-transformer": "2.1.11",
81
- "@aws-amplify/graphql-http-transformer": "2.1.11",
82
- "@aws-amplify/graphql-index-transformer": "2.2.3",
83
- "@aws-amplify/graphql-maps-to-transformer": "3.3.3",
84
- "@aws-amplify/graphql-model-transformer": "2.3.3",
85
- "@aws-amplify/graphql-predictions-transformer": "2.1.11",
86
- "@aws-amplify/graphql-relational-transformer": "2.2.3",
87
- "@aws-amplify/graphql-searchable-transformer": "2.3.3",
88
- "@aws-amplify/graphql-sql-transformer": "0.1.3",
89
- "@aws-amplify/graphql-transformer": "1.3.3",
90
- "@aws-amplify/graphql-transformer-core": "2.3.3",
91
- "@aws-amplify/graphql-transformer-interfaces": "3.3.1",
78
+ "@aws-amplify/graphql-auth-transformer": "3.3.1-alpha.1+edba38d57",
79
+ "@aws-amplify/graphql-default-value-transformer": "2.2.1-alpha.1+edba38d57",
80
+ "@aws-amplify/graphql-function-transformer": "2.1.13-alpha.1+edba38d57",
81
+ "@aws-amplify/graphql-http-transformer": "2.1.13-alpha.1+edba38d57",
82
+ "@aws-amplify/graphql-index-transformer": "2.3.1-alpha.1+edba38d57",
83
+ "@aws-amplify/graphql-maps-to-transformer": "3.4.1-alpha.1+edba38d57",
84
+ "@aws-amplify/graphql-model-transformer": "2.4.1-alpha.1+edba38d57",
85
+ "@aws-amplify/graphql-predictions-transformer": "2.1.13-alpha.1+edba38d57",
86
+ "@aws-amplify/graphql-relational-transformer": "2.3.1-alpha.1+edba38d57",
87
+ "@aws-amplify/graphql-searchable-transformer": "2.4.1-alpha.1+edba38d57",
88
+ "@aws-amplify/graphql-sql-transformer": "0.2.1-alpha.1+edba38d57",
89
+ "@aws-amplify/graphql-transformer": "1.3.5-alpha.1+edba38d57",
90
+ "@aws-amplify/graphql-transformer-core": "2.4.1-alpha.1+edba38d57",
91
+ "@aws-amplify/graphql-transformer-interfaces": "3.3.3-alpha.1+edba38d57",
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.12",
100
- "graphql-transformer-common": "4.26.2",
99
+ "graphql-mapping-template": "4.20.14-alpha.1+edba38d57",
100
+ "graphql-transformer-common": "4.27.1-alpha.1+edba38d57",
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": "5256b5955ee204dd56f8074a43406852f8206c54"
172
+ "gitHead": "edba38d57f363191913c763e621d92d1aa9490f8"
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 { SQLLambdaModelDataSourceStrategy } from './model-datasource-strategy';
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
- new AttributionMetadataStorage().storeAttributionMetadata(Stack.of(scope), this.stackType, path.join(__dirname, '..', 'package.json'));
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
- let executeTransformConfig: ExecuteTransformConfig = {
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
- // Adds a modelToDataSourceMap field/value
209
- ...parseDataSourceConfig(definition.dataSourceStrategies),
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 { constructDataSourceStrategyMap } from './internal';
5
- import { ModelDataSourceStrategy } from './model-datasource-strategy';
6
- import { constructCustomSqlDataSourceStrategies } from './internal/data-source-config';
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: constructDataSourceStrategyMap(schema, dataSourceStrategy),
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: definitions.map((def) => def.schema).join(os.EOL),
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
- CustomSqlDataSourceStrategy as ImplementationCustomSqlDataSourceStrategy,
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 { normalizeDbType } from '@aws-amplify/graphql-transformer-core/lib/utils';
15
- import { CustomSqlDataSourceStrategy as InterfaceCustomSqlDataSourceStrategy, ModelDataSourceStrategy } from '../model-datasource-strategy';
16
-
17
- type DataSourceConfig = {
18
- modelToDatasourceMap: Map<string, DataSourceType>;
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: ModelDataSourceStrategy,
49
- ): InterfaceCustomSqlDataSourceStrategy[] => {
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: InterfaceCustomSqlDataSourceStrategy[] = [];
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
- * We currently use a different type structure to model strategies in the interface than we do in the implementation. This maps the
91
- * interface CustomSqlDataSourceStrategy (which uses SQLLambdaModelDataSourceStrategy) to the implementation flavor (which uses
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 mapInterfaceCustomSqlStrategiesToImplementationStrategies = (
97
- strategies?: InterfaceCustomSqlDataSourceStrategy[],
98
- ): ImplementationCustomSqlDataSourceStrategy[] => {
99
- if (!strategies) {
100
- return [];
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
- return strategies.map((interfaceStrategy) => ({
103
- fieldName: interfaceStrategy.fieldName,
104
- typeName: interfaceStrategy.typeName,
105
- dataSourceType: {
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 constructDataSourceStrategyMap = (
34
+ export const constructDataSourceStrategies = (
34
35
  schema: string,
35
36
  dataSourceStrategy: ModelDataSourceStrategy,
36
37
  ): Record<string, ModelDataSourceStrategy> => {