@aws-amplify/graphql-api-construct 1.4.2 → 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.
Files changed (251) hide show
  1. package/.jsii +367 -278
  2. package/API.md +14 -3
  3. package/CHANGELOG.md +18 -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 -65
  8. package/lib/amplify-graphql-definition.d.ts +4 -15
  9. package/lib/amplify-graphql-definition.js +33 -30
  10. package/lib/index.d.ts +2 -1
  11. package/lib/index.js +16 -1
  12. package/lib/internal/data-source-config.d.ts +22 -9
  13. package/lib/internal/data-source-config.js +150 -39
  14. package/lib/internal/model-type-name.d.ts +3 -3
  15. package/lib/internal/model-type-name.js +7 -7
  16. package/lib/model-datasource-strategy-types.d.ts +122 -0
  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 +12 -119
  21. package/lib/types.js +1 -1
  22. package/node_modules/@aws-amplify/graphql-auth-transformer/CHANGELOG.md +10 -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 +10 -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 +10 -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 +8 -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 +10 -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 +10 -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 +16 -0
  59. package/node_modules/@aws-amplify/graphql-model-transformer/CHANGELOG.md +13 -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/index.d.ts +1 -0
  65. package/node_modules/@aws-amplify/graphql-model-transformer/lib/index.d.ts.map +1 -1
  66. package/node_modules/@aws-amplify/graphql-model-transformer/lib/index.js +3 -1
  67. package/node_modules/@aws-amplify/graphql-model-transformer/lib/index.js.map +1 -1
  68. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-lambda.zip +0 -0
  69. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-notification-lambda.zip +0 -0
  70. package/node_modules/@aws-amplify/graphql-model-transformer/lib/rds-patching-lambda.zip +0 -0
  71. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts +8 -8
  72. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.d.ts.map +1 -1
  73. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js +32 -36
  74. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resolvers/rds/resolver.js.map +1 -1
  75. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts +3 -2
  76. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.d.ts.map +1 -1
  77. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js +70 -34
  78. package/node_modules/@aws-amplify/graphql-model-transformer/lib/resources/rds-model-resource-generator.js.map +1 -1
  79. package/node_modules/@aws-amplify/graphql-model-transformer/package.json +15 -10
  80. package/node_modules/@aws-amplify/graphql-predictions-transformer/CHANGELOG.md +8 -0
  81. package/node_modules/@aws-amplify/graphql-predictions-transformer/lib/predictionsLambdaFunction.zip +0 -0
  82. package/node_modules/@aws-amplify/graphql-predictions-transformer/package.json +11 -7
  83. package/node_modules/@aws-amplify/graphql-relational-transformer/API.md +2 -2
  84. package/node_modules/@aws-amplify/graphql-relational-transformer/CHANGELOG.md +12 -0
  85. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.d.ts.map +1 -1
  86. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js +14 -7
  87. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-belongs-to-transformer.js.map +1 -1
  88. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.d.ts.map +1 -1
  89. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js +6 -6
  90. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-many-transformer.js.map +1 -1
  91. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js +6 -6
  92. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-has-one-transformer.js.map +1 -1
  93. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.d.ts.map +1 -1
  94. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js +8 -1
  95. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/graphql-many-to-many-transformer.js.map +1 -1
  96. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.d.ts.map +1 -1
  97. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js +5 -3
  98. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/ddb-generator.js.map +1 -1
  99. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts +2 -2
  100. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.d.ts.map +1 -1
  101. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/generator-factory.js.map +1 -1
  102. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.d.ts.map +1 -1
  103. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js +18 -6
  104. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/resolver/rds-generator.js.map +1 -1
  105. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts +18 -18
  106. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.d.ts.map +1 -1
  107. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js +54 -54
  108. package/node_modules/@aws-amplify/graphql-relational-transformer/lib/utils.js.map +1 -1
  109. package/node_modules/@aws-amplify/graphql-relational-transformer/package.json +14 -10
  110. package/node_modules/@aws-amplify/graphql-searchable-transformer/CHANGELOG.md +10 -0
  111. package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/graphql-searchable-transformer.js +1 -1
  112. package/node_modules/@aws-amplify/graphql-searchable-transformer/lib/streaming-lambda.zip +0 -0
  113. package/node_modules/@aws-amplify/graphql-searchable-transformer/package.json +12 -8
  114. package/node_modules/@aws-amplify/graphql-sql-transformer/CHANGELOG.md +12 -0
  115. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.d.ts.map +1 -1
  116. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js +32 -12
  117. package/node_modules/@aws-amplify/graphql-sql-transformer/lib/graphql-sql-transformer.js.map +1 -1
  118. package/node_modules/@aws-amplify/graphql-sql-transformer/package.json +12 -8
  119. package/node_modules/@aws-amplify/graphql-transformer/API.md +4 -16
  120. package/node_modules/@aws-amplify/graphql-transformer/CHANGELOG.md +10 -0
  121. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts +4 -13
  122. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.d.ts.map +1 -1
  123. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js +8 -14
  124. package/node_modules/@aws-amplify/graphql-transformer/lib/graphql-transformer.js.map +1 -1
  125. package/node_modules/@aws-amplify/graphql-transformer/package.json +20 -16
  126. package/node_modules/@aws-amplify/graphql-transformer/src/graphql-transformer.ts +30 -54
  127. package/node_modules/@aws-amplify/graphql-transformer-core/API.md +128 -31
  128. package/node_modules/@aws-amplify/graphql-transformer-core/CHANGELOG.md +13 -0
  129. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts +3 -3
  130. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.d.ts.map +1 -1
  131. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js +34 -16
  132. package/node_modules/@aws-amplify/graphql-transformer-core/lib/index.js.map +1 -1
  133. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts +1 -1
  134. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.d.ts.map +1 -1
  135. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js +4 -2
  136. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/index.js.map +1 -1
  137. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts +6 -12
  138. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.d.ts.map +1 -1
  139. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js +16 -5
  140. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/transform.js.map +1 -1
  141. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts +0 -8
  142. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/types.d.ts.map +1 -1
  143. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts +12 -10
  144. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.d.ts.map +1 -1
  145. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js +94 -39
  146. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformation/utils.js.map +1 -1
  147. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts +18 -12
  148. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.d.ts.map +1 -1
  149. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js +13 -15
  150. package/node_modules/@aws-amplify/graphql-transformer-core/lib/transformer-context/index.js.map +1 -1
  151. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts +1 -4
  152. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.d.ts.map +1 -1
  153. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js +1 -4
  154. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/import-appsync-api-types.js.map +1 -1
  155. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts +2 -1
  156. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.d.ts.map +1 -1
  157. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js +16 -4
  158. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/index.js.map +1 -1
  159. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts +7 -0
  160. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.d.ts.map +1 -0
  161. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js +15 -0
  162. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/model-datasource-strategies.js.map +1 -0
  163. package/node_modules/@aws-amplify/graphql-transformer-core/lib/types/types.d.ts.map +1 -1
  164. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts +28 -0
  165. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.d.ts.map +1 -0
  166. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js +39 -0
  167. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/graphql-utils.js.map +1 -0
  168. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts +5 -4
  169. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.d.ts.map +1 -1
  170. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js +21 -12
  171. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/index.js.map +1 -1
  172. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts +14 -0
  173. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.d.ts.map +1 -0
  174. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js +96 -0
  175. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/model-datasource-strategy-utils.js.map +1 -0
  176. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts +0 -10
  177. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.d.ts.map +1 -1
  178. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js +1 -58
  179. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/rds-util.js.map +1 -1
  180. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts +22 -0
  181. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.d.ts.map +1 -1
  182. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js +28 -1
  183. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/resource-name.js.map +1 -1
  184. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts +2 -2
  185. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.d.ts.map +1 -1
  186. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js +7 -6
  187. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/schema-utils.js.map +1 -1
  188. package/node_modules/@aws-amplify/graphql-transformer-core/package.json +9 -5
  189. package/node_modules/@aws-amplify/graphql-transformer-interfaces/API.md +88 -40
  190. package/node_modules/@aws-amplify/graphql-transformer-interfaces/CHANGELOG.md +10 -0
  191. package/node_modules/@aws-amplify/graphql-transformer-interfaces/LICENSE +201 -0
  192. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/graphql-api-provider.d.ts +0 -17
  193. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/graphql-api-provider.d.ts.map +1 -1
  194. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/graphql-api-provider.js.map +1 -1
  195. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/index.d.ts +2 -1
  196. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/index.d.ts.map +1 -1
  197. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/index.js +1 -0
  198. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/index.js.map +1 -1
  199. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/index.d.ts +2 -0
  200. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/index.d.ts.map +1 -0
  201. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/index.js +18 -0
  202. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/index.js.map +1 -0
  203. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts +59 -0
  204. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.d.ts.map +1 -0
  205. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.js +3 -0
  206. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/model-datasource/types.js.map +1 -0
  207. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transform-host-provider.d.ts +2 -1
  208. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transform-host-provider.d.ts.map +1 -1
  209. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts +2 -2
  210. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.d.ts.map +1 -1
  211. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js +1 -3
  212. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/index.js.map +1 -1
  213. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts +12 -17
  214. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-context-provider.d.ts.map +1 -1
  215. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts +0 -15
  216. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.d.ts.map +1 -1
  217. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js +1 -10
  218. package/node_modules/@aws-amplify/graphql-transformer-interfaces/lib/transformer-context/transformer-datasource-provider.js.map +1 -1
  219. package/node_modules/@aws-amplify/graphql-transformer-interfaces/package.json +8 -3
  220. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/graphql-api-provider.ts +1 -41
  221. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/index.ts +1 -4
  222. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/model-datasource/index.ts +1 -0
  223. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/model-datasource/types.ts +195 -0
  224. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transform-host-provider.ts +1 -1
  225. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/index.ts +4 -9
  226. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-context-provider.ts +15 -23
  227. package/node_modules/@aws-amplify/graphql-transformer-interfaces/src/transformer-context/transformer-datasource-provider.ts +0 -43
  228. package/node_modules/@aws-amplify/graphql-transformer-interfaces/tsconfig.tsbuildinfo +1 -1
  229. package/node_modules/graphql-mapping-template/CHANGELOG.md +4 -0
  230. package/node_modules/graphql-mapping-template/LICENSE +201 -0
  231. package/node_modules/graphql-mapping-template/package.json +8 -3
  232. package/node_modules/graphql-transformer-common/API.md +0 -15
  233. package/node_modules/graphql-transformer-common/CHANGELOG.md +6 -0
  234. package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts +0 -15
  235. package/node_modules/graphql-transformer-common/lib/ResourceConstants.d.ts.map +1 -1
  236. package/node_modules/graphql-transformer-common/lib/ResourceConstants.js +0 -15
  237. package/node_modules/graphql-transformer-common/lib/ResourceConstants.js.map +1 -1
  238. package/node_modules/graphql-transformer-common/package.json +7 -3
  239. package/package.json +24 -19
  240. package/src/amplify-graphql-api.ts +19 -76
  241. package/src/amplify-graphql-definition.ts +47 -30
  242. package/src/index.ts +2 -10
  243. package/src/internal/data-source-config.ts +195 -47
  244. package/src/internal/model-type-name.ts +5 -4
  245. package/src/model-datasource-strategy-types.ts +157 -0
  246. package/src/sql-model-datasource-strategy.ts +3 -3
  247. package/src/types.ts +13 -144
  248. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts +0 -3
  249. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.d.ts.map +0 -1
  250. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.js +0 -15
  251. package/node_modules/@aws-amplify/graphql-transformer-core/lib/utils/provision-strategy-utils.js.map +0 -1
@@ -1,7 +1,14 @@
1
1
  import * as os from 'os';
2
2
  import { SchemaFile } from 'aws-cdk-lib/aws-appsync';
3
- import { IAmplifyGraphqlDefinition, ModelDataSourceStrategy } from './types';
4
- import { constructDataSourceStrategyMap } from './internal';
3
+ import { isSqlStrategy } from '@aws-amplify/graphql-transformer-core';
4
+ import { IAmplifyGraphqlDefinition } from './types';
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';
5
12
 
6
13
  export const DEFAULT_MODEL_DATA_SOURCE_STRATEGY: ModelDataSourceStrategy = {
7
14
  dbType: 'DYNAMODB',
@@ -14,24 +21,22 @@ export const DEFAULT_MODEL_DATA_SOURCE_STRATEGY: ModelDataSourceStrategy = {
14
21
  export class AmplifyGraphqlDefinition {
15
22
  /**
16
23
  * Produce a schema definition from a string input.
17
- *
18
- * **NOTE** The 'dataSourceStrategy' configuration option is in preview and is not recommended to use with production systems.
19
- *
20
24
  * @param schema the graphql input as a string
21
- * @param dataSourceStrategy the provisioning definition for datasources that resolve `@model`s in this schema. The DynamoDB from
22
- * CloudFormation will be used by default.
23
- * @experimental dataSourceStrategy
25
+ * @param dataSourceStrategy the provisioning definition for datasources that resolve `@model`s and custom SQL statements in this schema.
26
+ * The DynamoDB from CloudFormation will be used by default.
24
27
  * @returns a fully formed amplify graphql definition
25
28
  */
26
29
  static fromString(
27
30
  schema: string,
28
31
  dataSourceStrategy: ModelDataSourceStrategy = DEFAULT_MODEL_DATA_SOURCE_STRATEGY,
29
32
  ): IAmplifyGraphqlDefinition {
33
+ validateDataSourceStrategy(dataSourceStrategy);
30
34
  return {
31
35
  schema,
32
36
  functionSlots: [],
33
37
  referencedLambdaFunctions: {},
34
- dataSourceStrategies: constructDataSourceStrategyMap(schema, dataSourceStrategy),
38
+ dataSourceStrategies: constructDataSourceStrategies(schema, dataSourceStrategy),
39
+ customSqlDataSourceStrategies: constructCustomSqlDataSourceStrategies(schema, dataSourceStrategy),
35
40
  };
36
41
  }
37
42
 
@@ -45,20 +50,11 @@ export class AmplifyGraphqlDefinition {
45
50
  filePaths = [filePaths];
46
51
  }
47
52
  const schema = filePaths.map((filePath) => new SchemaFile({ filePath }).definition).join(os.EOL);
48
- return {
49
- schema,
50
- functionSlots: [],
51
- referencedLambdaFunctions: {},
52
- dataSourceStrategies: constructDataSourceStrategyMap(schema, DEFAULT_MODEL_DATA_SOURCE_STRATEGY),
53
- };
53
+ return AmplifyGraphqlDefinition.fromString(schema, DEFAULT_MODEL_DATA_SOURCE_STRATEGY);
54
54
  }
55
55
 
56
56
  /**
57
57
  * Convert one or more appsync SchemaFile objects into an Amplify Graphql Schema
58
- *
59
- * **NOTE** This API is in preview and is not recommended to use with production systems.
60
- *
61
- * @experimental
62
58
  * @param filePaths one or more paths to the graphql files to process
63
59
  * @param dataSourceStrategy the provisioning definition for datasources that resolve `@model`s in this schema. The DynamoDB from
64
60
  * CloudFormation will be used by default.
@@ -72,20 +68,11 @@ export class AmplifyGraphqlDefinition {
72
68
  filePaths = [filePaths];
73
69
  }
74
70
  const schema = filePaths.map((filePath) => new SchemaFile({ filePath }).definition).join(os.EOL);
75
- return {
76
- schema,
77
- functionSlots: [],
78
- referencedLambdaFunctions: {},
79
- dataSourceStrategies: constructDataSourceStrategyMap(schema, dataSourceStrategy),
80
- };
71
+ return AmplifyGraphqlDefinition.fromString(schema, dataSourceStrategy);
81
72
  }
82
73
 
83
74
  /**
84
75
  * Combines multiple IAmplifyGraphqlDefinitions into a single definition.
85
- *
86
- * **NOTE** This API is in preview and is not recommended to use with production systems.
87
- *
88
- * @experimental
89
76
  * @param definitions the definitions to combine
90
77
  */
91
78
  static combine(definitions: IAmplifyGraphqlDefinition[]): IAmplifyGraphqlDefinition {
@@ -95,11 +82,41 @@ export class AmplifyGraphqlDefinition {
95
82
  if (definitions.length === 1) {
96
83
  return definitions[0];
97
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
+
98
114
  return {
99
- schema: definitions.map((def) => def.schema).join(os.EOL),
115
+ schema: mergedSchema,
100
116
  functionSlots: [],
101
117
  referencedLambdaFunctions: definitions.reduce((acc, cur) => ({ ...acc, ...cur.referencedLambdaFunctions }), {}),
102
118
  dataSourceStrategies: definitions.reduce((acc, cur) => ({ ...acc, ...cur.dataSourceStrategies }), {}),
119
+ customSqlDataSourceStrategies,
103
120
  };
104
121
  }
105
122
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /* ATTENTION
2
2
  *
3
- * If you modify this file your must also modify packages/amplify-data-construct/src/index.ts to have the same exports
3
+ * If you modify this file you must also modify packages/amplify-data-construct/src/index.ts to have the same exports
4
4
  */
5
5
  export type {
6
6
  IAMAuthorizationConfig,
@@ -31,15 +31,6 @@ export type {
31
31
  IBackendOutputStorageStrategy,
32
32
  IBackendOutputEntry,
33
33
  AddFunctionProps,
34
- ModelDataSourceStrategy,
35
- DefaultDynamoDbModelDataSourceStrategy,
36
- AmplifyDynamoDbModelDataSourceStrategy,
37
- SQLLambdaModelDataSourceStrategy,
38
- ModelDataSourceStrategyDbType,
39
- VpcConfig,
40
- SubnetAvailabilityZone,
41
- SqlModelDataSourceDbConnectionConfig,
42
- ProvisionedConcurrencyConfig,
43
34
  } from './types';
44
35
  export { AmplifyGraphqlApi } from './amplify-graphql-api';
45
36
  export { AmplifyGraphqlDefinition } from './amplify-graphql-definition';
@@ -52,3 +43,4 @@ export {
52
43
  StreamSpecification,
53
44
  } from './amplify-dynamodb-table-wrapper';
54
45
  export { SQLLambdaModelDataSourceStrategyFactory } from './sql-model-datasource-strategy';
46
+ export * from './model-datasource-strategy-types';
@@ -1,57 +1,205 @@
1
+ import { DefinitionNode, FieldDefinitionNode, InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode, parse, print } from 'graphql';
1
2
  import {
2
- DataSourceType,
3
- DynamoDBProvisionStrategy,
4
- SQLDBType,
5
- SQLLambdaModelProvisionStrategy,
6
- } from '@aws-amplify/graphql-transformer-interfaces';
7
- import { ModelDataSourceStrategy } from '../types';
8
-
9
- type DataSourceConfig = {
10
- modelToDatasourceMap: Map<string, DataSourceType>;
11
- };
3
+ isBuiltInGraphqlNode,
4
+ isSqlStrategy,
5
+ isQueryNode,
6
+ isMutationNode,
7
+ fieldsWithSqlDirective,
8
+ } from '@aws-amplify/graphql-transformer-core';
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';
15
+
16
+ /**
17
+ * Creates an interface flavor of customSqlDataSourceStrategies from a factory method's schema and data source. Internally, this function
18
+ * scans the fields of `Query` and `Mutation` looking for fields annotated with the `@sql` directive and designates the specified
19
+ * dataSourceStrategy to fulfill those custom queries.
20
+ *
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
22
+ * anyway, since subscriptions are processed from an incoming Mutation, not as the result of a direct datasource access.
23
+ */
24
+ export const constructCustomSqlDataSourceStrategies = (
25
+ schema: string,
26
+ dataSourceStrategy: ConstructModelDataSourceStrategy,
27
+ ): ConstructCustomSqlDataSourceStrategy[] => {
28
+ if (!isSqlStrategy(dataSourceStrategy)) {
29
+ return [];
30
+ }
31
+
32
+ const parsedSchema = parse(schema);
33
+
34
+ const queryNode = parsedSchema.definitions.find(isQueryNode);
35
+ const mutationNode = parsedSchema.definitions.find(isMutationNode);
36
+ if (!queryNode && !mutationNode) {
37
+ return [];
38
+ }
39
+
40
+ const customSqlDataSourceStrategies: ConstructCustomSqlDataSourceStrategy[] = [];
41
+
42
+ if (queryNode) {
43
+ const fields = fieldsWithSqlDirective(queryNode);
44
+ for (const field of fields) {
45
+ customSqlDataSourceStrategies.push({
46
+ typeName: 'Query',
47
+ fieldName: field.name.value,
48
+ strategy: dataSourceStrategy,
49
+ });
50
+ }
51
+ }
12
52
 
13
- // TODO: Do away with this after we normalize database types throughout the internals
14
- const convertSQLDBType = (definitionDBType: 'MYSQL' | 'POSTGRES'): SQLDBType => (definitionDBType === 'MYSQL' ? 'MySQL' : 'Postgres');
15
-
16
- const convertToDataSourceType = (dataSourceStrategy: ModelDataSourceStrategy): DataSourceType => {
17
- if (dataSourceStrategy.dbType === 'DYNAMODB') {
18
- switch (dataSourceStrategy.provisionStrategy) {
19
- case 'DEFAULT':
20
- return {
21
- dbType: 'DDB',
22
- provisionDB: true,
23
- provisionStrategy: DynamoDBProvisionStrategy.DEFAULT,
24
- };
25
- case 'AMPLIFY_TABLE':
26
- return {
27
- dbType: 'DDB',
28
- provisionDB: true,
29
- provisionStrategy: DynamoDBProvisionStrategy.AMPLIFY_TABLE,
30
- };
31
- default:
32
- throw new Error(`Encountered unexpected provision strategy: ${(dataSourceStrategy as any).provisionStrategy}`);
53
+ if (mutationNode) {
54
+ const fields = fieldsWithSqlDirective(mutationNode);
55
+ for (const field of fields) {
56
+ customSqlDataSourceStrategies.push({
57
+ typeName: 'Mutation',
58
+ fieldName: field.name.value,
59
+ strategy: dataSourceStrategy,
60
+ });
33
61
  }
34
- } else if (dataSourceStrategy.dbType === 'MYSQL' || dataSourceStrategy.dbType === 'POSTGRES') {
35
- return {
36
- dbType: convertSQLDBType(dataSourceStrategy.dbType),
37
- provisionDB: false,
38
- provisionStrategy: SQLLambdaModelProvisionStrategy.DEFAULT,
39
- };
40
62
  }
41
- throw new Error(`Encountered unexpected database type ${dataSourceStrategy.dbType}`);
63
+
64
+ return customSqlDataSourceStrategies;
42
65
  };
43
66
 
44
67
  /**
45
- * An internal helper to convert from a map of model-to-ModelDataSourceStrategies to the map of model-to-DataSourceTypes that internal
46
- * transform processing requires. TODO: We can remove this once we refactor the internals to use ModelDataSourceStrategies natively.
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.
47
70
  */
48
- export const parseDataSourceConfig = (dataSourceDefinitionMap: Record<string, ModelDataSourceStrategy>): DataSourceConfig => {
49
- const modelToDatasourceMap = new Map<string, DataSourceType>();
50
- for (const [key, value] of Object.entries(dataSourceDefinitionMap)) {
51
- const dataSourceType = convertToDataSourceType(value);
52
- modelToDatasourceMap.set(key, dataSourceType);
53
- }
54
- return {
55
- modelToDatasourceMap,
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],
56
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
+ );
200
+ }
201
+ };
202
+
203
+ const isValidSSMPath = (path: string): boolean => {
204
+ return path.startsWith('/');
57
205
  };
@@ -1,14 +1,15 @@
1
- import { ModelDataSourceStrategy } from '../types';
2
1
  import { Kind, ObjectTypeDefinitionNode, StringValueNode, parse } from 'graphql';
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
9
10
  * @returns type names which model diretives are attached
10
11
  */
11
- export function getModelTypeNames(schema: string): string[] {
12
+ export const getModelTypeNames = (schema: string): string[] => {
12
13
  const parsedSchema = parse(schema);
13
14
  const nodesWithModelDirective = parsedSchema.definitions.filter(
14
15
  (obj) => obj.kind === Kind.OBJECT_TYPE_DEFINITION && obj.directives?.some((dir) => dir.name.value === MODEL_DIRECTIVE_NAME),
@@ -28,9 +29,9 @@ export function getModelTypeNames(schema: string): string[] {
28
29
  });
29
30
  });
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> => {
@@ -0,0 +1,157 @@
1
+ // #########################################################################################################################################
2
+ // These are the public-facing types used by customers to define their L3 CDK construct. Many of these have corresponding definitions in the
3
+ // transformer-interfaces package to define internal behavior.
4
+ //
5
+ // If you change types in this file (the customer-facing interface), be sure to make corresponding changes to
6
+ // amplify-graphql-transformer-interfaces/src/model-datasource (the internal implementation)
7
+ // #########################################################################################################################################
8
+
9
+ /**
10
+ * All known ModelDataSourceStrategies. Concrete strategies vary widely in their requirements and implementations.
11
+ */
12
+ export type ModelDataSourceStrategy =
13
+ | DefaultDynamoDbModelDataSourceStrategy
14
+ | AmplifyDynamoDbModelDataSourceStrategy
15
+ | SQLLambdaModelDataSourceStrategy;
16
+
17
+ /**
18
+ * All supported database types that can be used to resolve models.
19
+ */
20
+ export type ModelDataSourceStrategyDbType = 'DYNAMODB' | ModelDataSourceStrategySqlDbType;
21
+
22
+ /**
23
+ * All supported SQL database types that can be used to resolve models.
24
+ */
25
+ export type ModelDataSourceStrategySqlDbType = 'MYSQL' | 'POSTGRES';
26
+
27
+ /**
28
+ * Use default CloudFormation type 'AWS::DynamoDB::Table' to provision table.
29
+ */
30
+ export interface DefaultDynamoDbModelDataSourceStrategy {
31
+ readonly dbType: 'DYNAMODB';
32
+ readonly provisionStrategy: 'DEFAULT';
33
+ }
34
+
35
+ /**
36
+ * Use custom resource type 'Custom::AmplifyDynamoDBTable' to provision table.
37
+ */
38
+ export interface AmplifyDynamoDbModelDataSourceStrategy {
39
+ readonly dbType: 'DYNAMODB';
40
+ readonly provisionStrategy: 'AMPLIFY_TABLE';
41
+ }
42
+
43
+ /**
44
+ * A strategy that creates a Lambda to connect to a pre-existing SQL table to resolve model data.
45
+ */
46
+ export interface SQLLambdaModelDataSourceStrategy {
47
+ /**
48
+ * The name of the strategy. This will be used to name the AppSync DataSource itself, plus any associated resources like resolver Lambdas.
49
+ * This name must be unique across all schema definitions in a GraphQL API.
50
+ */
51
+ readonly name: string;
52
+
53
+ /**
54
+ * The type of the SQL database used to process model operations for this definition.
55
+ */
56
+ readonly dbType: ModelDataSourceStrategySqlDbType;
57
+
58
+ /**
59
+ * The parameters the Lambda data source will use to connect to the database.
60
+ */
61
+ readonly dbConnectionConfig: SqlModelDataSourceDbConnectionConfig;
62
+
63
+ /**
64
+ * The configuration of the VPC into which to install the Lambda.
65
+ */
66
+ readonly vpcConfiguration?: VpcConfig;
67
+
68
+ /**
69
+ * Custom SQL statements. The key is the value of the `references` attribute of the `@sql` directive in the `schema`; the value is the SQL
70
+ * to be executed.
71
+ */
72
+ readonly customSqlStatements?: Record<string, string>;
73
+
74
+ /**
75
+ * The configuration for the provisioned concurrency of the Lambda.
76
+ */
77
+ readonly sqlLambdaProvisionedConcurrencyConfig?: ProvisionedConcurrencyConfig;
78
+ }
79
+
80
+ /**
81
+ * Configuration of the VPC in which to install a Lambda to resolve queries against a SQL-based data source. The SQL Lambda will be deployed
82
+ * into the specified VPC, subnets, and security groups. The specified subnets and security groups must be in the same VPC. The VPC must
83
+ * have at least one subnet. The construct will also create VPC service endpoints in the specified subnets, as well as inbound security
84
+ * rules, to allow traffic on port 443 within each security group. This allows the Lambda to read database connection information from
85
+ * Secure Systems Manager.
86
+ */
87
+ export interface VpcConfig {
88
+ /** The VPC to install the Lambda data source in. */
89
+ readonly vpcId: string;
90
+
91
+ /** The security groups to install the Lambda data source in. */
92
+ readonly securityGroupIds: string[];
93
+
94
+ /** The subnets to install the Lambda data source in, one per availability zone. */
95
+ readonly subnetAvailabilityZoneConfig: SubnetAvailabilityZone[];
96
+ }
97
+
98
+ /**
99
+ * The configuration for the provisioned concurrency of the Lambda.
100
+ */
101
+ export interface ProvisionedConcurrencyConfig {
102
+ /** The amount of provisioned concurrency to allocate. **/
103
+ readonly provisionedConcurrentExecutions: number;
104
+ }
105
+
106
+ /**
107
+ * Subnet configuration for VPC endpoints used by a Lambda resolver for a SQL-based data source. Although it is possible to create multiple
108
+ * subnets in a single availability zone, VPC service endpoints may only be deployed to a single subnet in a given availability zone. This
109
+ * structure ensures that the Lambda function and VPC service endpoints are mutually consistent.
110
+ */
111
+ export interface SubnetAvailabilityZone {
112
+ /** The subnet ID to install the Lambda data source in. */
113
+ readonly subnetId: string;
114
+
115
+ /** The availability zone of the subnet. */
116
+ readonly availabilityZone: string;
117
+ }
118
+
119
+ /**
120
+ * The Secure Systems Manager parameter paths the Lambda data source will use to connect to the database.
121
+ *
122
+ * These parameters are retrieved from Secure Systems Manager in the same region as the Lambda.
123
+ */
124
+ export interface SqlModelDataSourceDbConnectionConfig {
125
+ /** The Secure Systems Manager parameter containing the hostname of the database. For RDS-based SQL data sources, this can be the hostname
126
+ * of a database proxy, cluster, or instance.
127
+ */
128
+ readonly hostnameSsmPath: string;
129
+
130
+ /** The Secure Systems Manager parameter containing the port number of the database proxy, cluster, or instance. */
131
+ readonly portSsmPath: string;
132
+
133
+ /** The Secure Systems Manager parameter containing the username to use when connecting to the database. */
134
+ readonly usernameSsmPath: string;
135
+
136
+ /** The Secure Systems Manager parameter containing the password to use when connecting to the database. */
137
+ readonly passwordSsmPath: string;
138
+
139
+ /** The Secure Systems Manager parameter containing the database name. */
140
+ readonly databaseNameSsmPath: string;
141
+ }
142
+
143
+ /**
144
+ * The input type for defining a ModelDataSourceStrategy used to resolve a field annotated with a `@sql` directive. Although this is a
145
+ * public type, you should rarely need to use this. The AmplifyGraphqlDefinition factory methods (e.g., `fromString`,
146
+ * `fromFilesAndStrategy`) will automatically construct this structure for you.
147
+ */
148
+ export interface CustomSqlDataSourceStrategy {
149
+ /** The built-in type (either "Query" or "Mutation") with which the custom SQL is associated */
150
+ readonly typeName: 'Query' | 'Mutation';
151
+
152
+ /** The field name with which the custom SQL is associated */
153
+ readonly fieldName: string;
154
+
155
+ /** The strategy used to create the datasource that will resolve the custom SQL statement. */
156
+ readonly strategy: SQLLambdaModelDataSourceStrategy;
157
+ }
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { SQLLambdaModelDataSourceStrategy, SqlModelDataSourceDbConnectionConfig } from './types';
3
+ import { isSqlDbType } from '@aws-amplify/graphql-transformer-core';
4
+ import { SQLLambdaModelDataSourceStrategy, SqlModelDataSourceDbConnectionConfig } from './model-datasource-strategy-types';
4
5
 
5
6
  /**
6
7
  * Type predicate that returns true if the object is a SQLLambdaModelDataSourceStrategy.
@@ -12,8 +13,7 @@ export const isSQLLambdaModelDataSourceStrategy = (obj: any): obj is SQLLambdaMo
12
13
  (typeof obj === 'object' || typeof obj === 'function') &&
13
14
  typeof obj.name === 'string' &&
14
15
  typeof obj.dbType === 'string' &&
15
- // TODO: Use canonical SQL DB type strings
16
- ['MYSQL', 'POSTGRES'].includes(obj.dbType) &&
16
+ isSqlDbType(obj.dbType) &&
17
17
  isSqlModelDataSourceDbConnectionConfig(obj.dbConnectionConfig)
18
18
  );
19
19
  };