@contember/engine-content-api 2.2.0-alpha.17 → 2.2.0-alpha.19

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 (405) hide show
  1. package/CLAUDE.md +1 -1
  2. package/dist/development/index.cjs +3 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +4 -1
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ExecutionContainer.cjs +1 -0
  7. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  8. package/dist/development/src/ExecutionContainer.js +1 -0
  9. package/dist/development/src/ExecutionContainer.js.map +1 -1
  10. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
  11. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  12. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
  13. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  14. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
  15. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  16. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
  17. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  18. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
  19. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  20. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
  21. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  22. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
  23. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  24. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
  25. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  26. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
  27. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  28. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
  29. package/dist/development/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  30. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
  31. package/dist/development/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  32. package/dist/development/src/inputProcessing/UpdateInputVisitor.js +52 -2
  33. package/dist/development/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  34. package/dist/development/src/mapper/ErrorUtils.cjs +10 -0
  35. package/dist/development/src/mapper/ErrorUtils.cjs.map +1 -1
  36. package/dist/development/src/mapper/ErrorUtils.js +10 -0
  37. package/dist/development/src/mapper/ErrorUtils.js.map +1 -1
  38. package/dist/development/src/mapper/Mapper.cjs +37 -1
  39. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  40. package/dist/development/src/mapper/Mapper.js +38 -2
  41. package/dist/development/src/mapper/Mapper.js.map +1 -1
  42. package/dist/development/src/mapper/MutationProcessorHelper.cjs +12 -0
  43. package/dist/development/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  44. package/dist/development/src/mapper/MutationProcessorHelper.js +13 -1
  45. package/dist/development/src/mapper/MutationProcessorHelper.js.map +1 -1
  46. package/dist/development/src/mapper/Result.cjs +1 -0
  47. package/dist/development/src/mapper/Result.cjs.map +1 -1
  48. package/dist/development/src/mapper/Result.js +1 -0
  49. package/dist/development/src/mapper/Result.js.map +1 -1
  50. package/dist/development/src/mapper/delete/DeleteExecutor.cjs +1 -1
  51. package/dist/development/src/mapper/delete/DeleteExecutor.js +1 -1
  52. package/dist/development/src/mapper/select/Path.cjs +2 -2
  53. package/dist/development/src/mapper/select/Path.cjs.map +1 -1
  54. package/dist/development/src/mapper/select/Path.js +2 -2
  55. package/dist/development/src/mapper/select/Path.js.map +1 -1
  56. package/dist/development/src/mapper/select/handlers/MetaHandler.cjs +1 -1
  57. package/dist/development/src/mapper/select/handlers/MetaHandler.js +1 -1
  58. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
  59. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  60. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
  61. package/dist/development/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  62. package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
  63. package/dist/development/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
  64. package/dist/development/src/mapper/select/optimizer/WhereReplacer.js +1 -1
  65. package/dist/development/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
  66. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
  67. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  68. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
  69. package/dist/development/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  70. package/dist/development/src/mapper/update/Updater.cjs +1 -1
  71. package/dist/development/src/mapper/update/Updater.js +1 -1
  72. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
  73. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  74. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
  75. package/dist/development/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  76. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
  77. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  78. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
  79. package/dist/development/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  80. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
  81. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
  82. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
  83. package/dist/development/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
  84. package/dist/development/src/resolvers/MutationResolver.cjs +4 -1
  85. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  86. package/dist/development/src/resolvers/MutationResolver.js +4 -1
  87. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  88. package/dist/development/src/resolvers/ReadHelpers.cjs +2 -1
  89. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  90. package/dist/development/src/resolvers/ReadHelpers.js +2 -1
  91. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  92. package/dist/development/src/schema/CustomTypesProvider.cjs +35 -14
  93. package/dist/development/src/schema/CustomTypesProvider.cjs.map +1 -1
  94. package/dist/development/src/schema/CustomTypesProvider.js +36 -15
  95. package/dist/development/src/schema/CustomTypesProvider.js.map +1 -1
  96. package/dist/development/src/schema/EntityTypeProvider.cjs +8 -5
  97. package/dist/development/src/schema/EntityTypeProvider.cjs.map +1 -1
  98. package/dist/development/src/schema/EntityTypeProvider.js +8 -5
  99. package/dist/development/src/schema/EntityTypeProvider.js.map +1 -1
  100. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
  101. package/dist/development/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
  102. package/dist/development/src/schema/MutationProvider.cjs +4 -0
  103. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  104. package/dist/development/src/schema/MutationProvider.js +4 -0
  105. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  106. package/dist/development/src/schema/OrderByTypeProvider.cjs +8 -2
  107. package/dist/development/src/schema/OrderByTypeProvider.cjs.map +1 -1
  108. package/dist/development/src/schema/OrderByTypeProvider.js +9 -3
  109. package/dist/development/src/schema/OrderByTypeProvider.js.map +1 -1
  110. package/dist/development/src/schema/QueryProvider.cjs +3 -0
  111. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  112. package/dist/development/src/schema/QueryProvider.js +3 -0
  113. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  114. package/dist/development/src/schema/ValidationQueriesProvider.cjs +2 -0
  115. package/dist/development/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  116. package/dist/development/src/schema/ValidationQueriesProvider.js +2 -0
  117. package/dist/development/src/schema/ValidationQueriesProvider.js.map +1 -1
  118. package/dist/development/src/schema/WhereTypeProvider.cjs +17 -5
  119. package/dist/development/src/schema/WhereTypeProvider.cjs.map +1 -1
  120. package/dist/development/src/schema/WhereTypeProvider.js +18 -6
  121. package/dist/development/src/schema/WhereTypeProvider.js.map +1 -1
  122. package/dist/development/src/schema/calendarDate.cjs +21 -0
  123. package/dist/development/src/schema/calendarDate.cjs.map +1 -0
  124. package/dist/development/src/schema/calendarDate.js +21 -0
  125. package/dist/development/src/schema/calendarDate.js.map +1 -0
  126. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
  127. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  128. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
  129. package/dist/development/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  130. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
  131. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  132. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
  133. package/dist/development/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  134. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
  135. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  136. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
  137. package/dist/development/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  138. package/dist/development/src/schema/utils.cjs +10 -0
  139. package/dist/development/src/schema/utils.cjs.map +1 -1
  140. package/dist/development/src/schema/utils.js +11 -1
  141. package/dist/development/src/schema/utils.js.map +1 -1
  142. package/dist/production/index.cjs +3 -0
  143. package/dist/production/index.cjs.map +1 -1
  144. package/dist/production/index.js +4 -1
  145. package/dist/production/index.js.map +1 -1
  146. package/dist/production/src/ExecutionContainer.cjs +1 -0
  147. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  148. package/dist/production/src/ExecutionContainer.js +1 -0
  149. package/dist/production/src/ExecutionContainer.js.map +1 -1
  150. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs +2 -1
  151. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.cjs.map +1 -1
  152. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js +2 -1
  153. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.js.map +1 -1
  154. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +5 -1
  155. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs.map +1 -1
  156. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +5 -1
  157. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js.map +1 -1
  158. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs +2 -1
  159. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.cjs.map +1 -1
  160. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js +2 -1
  161. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.js.map +1 -1
  162. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +4 -1
  163. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs.map +1 -1
  164. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +4 -1
  165. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js.map +1 -1
  166. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs +24 -3
  167. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.cjs.map +1 -1
  168. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js +24 -3
  169. package/dist/production/src/input-validation/preValidation/UpdateInputPreValidationProcessor.js.map +1 -1
  170. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs +52 -2
  171. package/dist/production/src/inputProcessing/UpdateInputVisitor.cjs.map +1 -1
  172. package/dist/production/src/inputProcessing/UpdateInputVisitor.js +52 -2
  173. package/dist/production/src/inputProcessing/UpdateInputVisitor.js.map +1 -1
  174. package/dist/production/src/mapper/ErrorUtils.cjs +10 -0
  175. package/dist/production/src/mapper/ErrorUtils.cjs.map +1 -1
  176. package/dist/production/src/mapper/ErrorUtils.js +10 -0
  177. package/dist/production/src/mapper/ErrorUtils.js.map +1 -1
  178. package/dist/production/src/mapper/Mapper.cjs +37 -1
  179. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  180. package/dist/production/src/mapper/Mapper.js +38 -2
  181. package/dist/production/src/mapper/Mapper.js.map +1 -1
  182. package/dist/production/src/mapper/MutationProcessorHelper.cjs +12 -0
  183. package/dist/production/src/mapper/MutationProcessorHelper.cjs.map +1 -1
  184. package/dist/production/src/mapper/MutationProcessorHelper.js +13 -1
  185. package/dist/production/src/mapper/MutationProcessorHelper.js.map +1 -1
  186. package/dist/production/src/mapper/Result.cjs +1 -0
  187. package/dist/production/src/mapper/Result.cjs.map +1 -1
  188. package/dist/production/src/mapper/Result.js +1 -0
  189. package/dist/production/src/mapper/Result.js.map +1 -1
  190. package/dist/production/src/mapper/delete/DeleteExecutor.cjs +1 -1
  191. package/dist/production/src/mapper/delete/DeleteExecutor.js +1 -1
  192. package/dist/production/src/mapper/select/Path.cjs +2 -2
  193. package/dist/production/src/mapper/select/Path.cjs.map +1 -1
  194. package/dist/production/src/mapper/select/Path.js +2 -2
  195. package/dist/production/src/mapper/select/Path.js.map +1 -1
  196. package/dist/production/src/mapper/select/handlers/MetaHandler.cjs +1 -1
  197. package/dist/production/src/mapper/select/handlers/MetaHandler.js +1 -1
  198. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs +2 -2
  199. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.cjs.map +1 -1
  200. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js +1 -1
  201. package/dist/production/src/mapper/select/optimizer/WhereOptimizer.js.map +1 -1
  202. package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs +3 -3
  203. package/dist/production/src/mapper/select/optimizer/WhereReplacer.cjs.map +1 -1
  204. package/dist/production/src/mapper/select/optimizer/WhereReplacer.js +1 -1
  205. package/dist/production/src/mapper/select/optimizer/WhereReplacer.js.map +1 -1
  206. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs +6 -3
  207. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.cjs.map +1 -1
  208. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js +7 -4
  209. package/dist/production/src/mapper/update/SqlUpdateInputProcessor.js.map +1 -1
  210. package/dist/production/src/mapper/update/Updater.cjs +1 -1
  211. package/dist/production/src/mapper/update/Updater.js +1 -1
  212. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs +6 -0
  213. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.cjs.map +1 -1
  214. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js +6 -0
  215. package/dist/production/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.js.map +1 -1
  216. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs +6 -0
  217. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.cjs.map +1 -1
  218. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js +6 -0
  219. package/dist/production/src/mapper/update/relations/OneHasManyUpdateInputProcessor.js.map +1 -1
  220. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs +123 -0
  221. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.cjs.map +1 -0
  222. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js +123 -0
  223. package/dist/production/src/mapper/update/relations/SetManyRelationHelper.js.map +1 -0
  224. package/dist/production/src/resolvers/MutationResolver.cjs +4 -1
  225. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  226. package/dist/production/src/resolvers/MutationResolver.js +4 -1
  227. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  228. package/dist/production/src/resolvers/ReadHelpers.cjs +2 -1
  229. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  230. package/dist/production/src/resolvers/ReadHelpers.js +2 -1
  231. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  232. package/dist/production/src/schema/CustomTypesProvider.cjs +35 -14
  233. package/dist/production/src/schema/CustomTypesProvider.cjs.map +1 -1
  234. package/dist/production/src/schema/CustomTypesProvider.js +36 -15
  235. package/dist/production/src/schema/CustomTypesProvider.js.map +1 -1
  236. package/dist/production/src/schema/EntityTypeProvider.cjs +8 -5
  237. package/dist/production/src/schema/EntityTypeProvider.cjs.map +1 -1
  238. package/dist/production/src/schema/EntityTypeProvider.js +8 -5
  239. package/dist/production/src/schema/EntityTypeProvider.js.map +1 -1
  240. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.cjs +1 -1
  241. package/dist/production/src/schema/GraphQlSchemaBuilderFactory.js +1 -1
  242. package/dist/production/src/schema/MutationProvider.cjs +4 -0
  243. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  244. package/dist/production/src/schema/MutationProvider.js +4 -0
  245. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  246. package/dist/production/src/schema/OrderByTypeProvider.cjs +8 -2
  247. package/dist/production/src/schema/OrderByTypeProvider.cjs.map +1 -1
  248. package/dist/production/src/schema/OrderByTypeProvider.js +9 -3
  249. package/dist/production/src/schema/OrderByTypeProvider.js.map +1 -1
  250. package/dist/production/src/schema/QueryProvider.cjs +3 -0
  251. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  252. package/dist/production/src/schema/QueryProvider.js +3 -0
  253. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  254. package/dist/production/src/schema/ValidationQueriesProvider.cjs +2 -0
  255. package/dist/production/src/schema/ValidationQueriesProvider.cjs.map +1 -1
  256. package/dist/production/src/schema/ValidationQueriesProvider.js +2 -0
  257. package/dist/production/src/schema/ValidationQueriesProvider.js.map +1 -1
  258. package/dist/production/src/schema/WhereTypeProvider.cjs +17 -5
  259. package/dist/production/src/schema/WhereTypeProvider.cjs.map +1 -1
  260. package/dist/production/src/schema/WhereTypeProvider.js +18 -6
  261. package/dist/production/src/schema/WhereTypeProvider.js.map +1 -1
  262. package/dist/production/src/schema/calendarDate.cjs +21 -0
  263. package/dist/production/src/schema/calendarDate.cjs.map +1 -0
  264. package/dist/production/src/schema/calendarDate.js +21 -0
  265. package/dist/production/src/schema/calendarDate.js.map +1 -0
  266. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs +11 -3
  267. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.cjs.map +1 -1
  268. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js +11 -3
  269. package/dist/production/src/schema/mutations/CreateEntityInputFieldVisitor.js.map +1 -1
  270. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs +11 -3
  271. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.cjs.map +1 -1
  272. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js +11 -3
  273. package/dist/production/src/schema/mutations/UpdateEntityInputFieldVisitor.js.map +1 -1
  274. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs +39 -2
  275. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.cjs.map +1 -1
  276. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js +40 -3
  277. package/dist/production/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.js.map +1 -1
  278. package/dist/production/src/schema/utils.cjs +10 -0
  279. package/dist/production/src/schema/utils.cjs.map +1 -1
  280. package/dist/production/src/schema/utils.js +11 -1
  281. package/dist/production/src/schema/utils.js.map +1 -1
  282. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts +2 -0
  283. package/dist/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.d.ts.map +1 -0
  284. package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts +2 -0
  285. package/dist/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.d.ts.map +1 -0
  286. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts +2 -0
  287. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.d.ts.map +1 -0
  288. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts +2 -0
  289. package/dist/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.d.ts.map +1 -0
  290. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts +2 -0
  291. package/dist/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.d.ts.map +1 -0
  292. package/dist/tests/cases/unit/checkViolationError.test.d.ts +2 -0
  293. package/dist/tests/cases/unit/checkViolationError.test.d.ts.map +1 -0
  294. package/dist/tests/cases/unit/dateType.test.d.ts +2 -0
  295. package/dist/tests/cases/unit/dateType.test.d.ts.map +1 -0
  296. package/dist/tests/cases/unit/internalColumnAliases.test.d.ts +2 -0
  297. package/dist/tests/cases/unit/internalColumnAliases.test.d.ts.map +1 -0
  298. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  299. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
  300. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
  301. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts +6 -0
  302. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
  303. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts +7 -0
  304. package/dist/types/inputProcessing/UpdateInputProcessor.d.ts.map +1 -1
  305. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts +2 -0
  306. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  307. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  308. package/dist/types/mapper/Mapper.d.ts +5 -0
  309. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  310. package/dist/types/mapper/MutationProcessorHelper.d.ts +3 -0
  311. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  312. package/dist/types/mapper/Result.d.ts +2 -1
  313. package/dist/types/mapper/Result.d.ts.map +1 -1
  314. package/dist/types/mapper/types.d.ts +8 -1
  315. package/dist/types/mapper/types.d.ts.map +1 -1
  316. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  317. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +5 -0
  318. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  319. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts +5 -0
  320. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  321. package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts +67 -0
  322. package/dist/types/mapper/update/relations/SetManyRelationHelper.d.ts.map +1 -0
  323. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  324. package/dist/types/schema/CustomTypesProvider.d.ts.map +1 -1
  325. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  326. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  327. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  328. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  329. package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
  330. package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
  331. package/dist/types/schema/calendarDate.d.ts +6 -0
  332. package/dist/types/schema/calendarDate.d.ts.map +1 -0
  333. package/dist/types/schema/index.d.ts +1 -0
  334. package/dist/types/schema/index.d.ts.map +1 -1
  335. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
  336. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts +3 -0
  337. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
  338. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts +1 -0
  339. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  340. package/dist/types/schema/utils.d.ts +7 -0
  341. package/dist/types/schema/utils.d.ts.map +1 -1
  342. package/dist/types/tsconfig.tsbuildinfo +1 -1
  343. package/package.json +10 -10
  344. package/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.ts +3 -0
  345. package/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.ts +9 -7
  346. package/src/input-validation/preValidation/UpdateInputPreValidationProcessor.ts +29 -0
  347. package/src/inputProcessing/UpdateInputProcessor.ts +6 -0
  348. package/src/inputProcessing/UpdateInputVisitor.ts +64 -2
  349. package/src/mapper/ErrorUtils.ts +12 -1
  350. package/src/mapper/Mapper.ts +61 -1
  351. package/src/mapper/MutationProcessorHelper.ts +14 -0
  352. package/src/mapper/Result.ts +1 -0
  353. package/src/mapper/select/Path.ts +2 -2
  354. package/src/mapper/select/optimizer/WhereOptimizer.ts +1 -1
  355. package/src/mapper/select/optimizer/WhereReplacer.ts +1 -1
  356. package/src/mapper/types.ts +16 -1
  357. package/src/mapper/update/SqlUpdateInputProcessor.ts +4 -1
  358. package/src/mapper/update/relations/ManyHasManyUpdateInputProcessor.ts +9 -0
  359. package/src/mapper/update/relations/OneHasManyUpdateInputProcessor.ts +9 -0
  360. package/src/mapper/update/relations/SetManyRelationHelper.ts +199 -0
  361. package/src/resolvers/MutationResolver.ts +2 -0
  362. package/src/schema/CustomTypesProvider.ts +40 -15
  363. package/src/schema/EntityTypeProvider.ts +8 -4
  364. package/src/schema/MutationProvider.ts +4 -0
  365. package/src/schema/OrderByTypeProvider.ts +9 -3
  366. package/src/schema/QueryProvider.ts +3 -0
  367. package/src/schema/ValidationQueriesProvider.ts +2 -0
  368. package/src/schema/WhereTypeProvider.ts +18 -6
  369. package/src/schema/calendarDate.ts +26 -0
  370. package/src/schema/index.ts +1 -0
  371. package/src/schema/mutations/CreateEntityInputFieldVisitor.ts +10 -2
  372. package/src/schema/mutations/UpdateEntityInputFieldVisitor.ts +10 -2
  373. package/src/schema/mutations/UpdateEntityRelationInputFieldVisitor.ts +66 -7
  374. package/src/schema/utils.ts +14 -0
  375. package/src/tsconfig.json +2 -1
  376. package/tests/cases/integration/graphQlRequests/query/acl/internalColumnAliases.test.ts +326 -0
  377. package/tests/cases/integration/graphQlRequests/query/acl/mergedRolePredicate.test.ts +124 -0
  378. package/tests/cases/integration/graphQlRequests/update/manyHasManyInverse/set.test.ts +219 -0
  379. package/tests/cases/integration/graphQlRequests/update/manyHasManyOwning/set.test.ts +479 -0
  380. package/tests/cases/integration/graphQlRequests/update/oneHasMany/set.test.ts +948 -0
  381. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +102 -1
  382. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +17 -0
  383. package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
  384. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +14 -0
  385. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +11 -0
  386. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-read.gql +254 -0
  387. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +1 -0
  388. package/tests/cases/integration/graphQlSchema/schema-acl.gql +1 -0
  389. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +1 -0
  390. package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
  391. package/tests/cases/integration/graphQlSchema/schema-basic.gql +50 -0
  392. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +17 -0
  393. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
  394. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +50 -0
  395. package/tests/cases/integration/graphQlSchema/schema-deprecation.gql +962 -0
  396. package/tests/cases/integration/graphQlSchema/schema-description.gql +992 -0
  397. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +17 -0
  398. package/tests/cases/integration/graphQlSchema/schema-mixed-root-through.gql +1 -0
  399. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +50 -0
  400. package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
  401. package/tests/cases/unit/checkViolationError.test.ts +49 -0
  402. package/tests/cases/unit/dateType.test.ts +46 -0
  403. package/tests/cases/unit/decimalType.test.ts +2 -2
  404. package/tests/cases/unit/internalColumnAliases.test.ts +41 -0
  405. package/tests/cases/unit/mutationSqlError.test.ts +1 -1
@@ -0,0 +1,948 @@
1
+ import { test } from 'bun:test'
2
+ import { Acl } from '@contember/schema'
3
+ import { execute, failedTransaction, sqlTransaction } from '../../../../../src/test.js'
4
+ import { GQL, SQL } from '../../../../../src/tags.js'
5
+ import { testUuid } from '../../../../../src/testUuid.js'
6
+ import { postWithLocale, postWithNullableLocale } from './schema.js'
7
+
8
+ test('set with default orphanStrategy (disconnect)', async () => {
9
+ await execute({
10
+ schema: postWithNullableLocale,
11
+ query: GQL`mutation {
12
+ updatePost(
13
+ by: {id: "${testUuid(2)}"},
14
+ data: {locales: {set: [{connect: {id: "${testUuid(1)}"}}]}}
15
+ ) {
16
+ ok
17
+ }
18
+ }`,
19
+ executes: [
20
+ ...sqlTransaction([
21
+ {
22
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
23
+ parameters: [testUuid(2)],
24
+ response: { rows: [{ id: testUuid(2) }] },
25
+ },
26
+ // snapshot the members up front - orphans are members from *before* the operation
27
+ {
28
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
29
+ parameters: [testUuid(2)],
30
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
31
+ },
32
+ // resolve the connect target primary
33
+ {
34
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
35
+ parameters: [testUuid(1)],
36
+ response: { rows: [{ id: testUuid(1) }] },
37
+ },
38
+ // orphan (id=3) is disconnected: resolve it
39
+ {
40
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
41
+ parameters: [testUuid(3), testUuid(2)],
42
+ response: { rows: [{ id: testUuid(3) }] },
43
+ },
44
+ // orphan (id=3) disconnected: set post_id to null
45
+ {
46
+ sql:
47
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
48
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
49
+ parameters: [null, testUuid(3)],
50
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
51
+ },
52
+ // connect: point the target locale to the post
53
+ {
54
+ sql:
55
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
56
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
57
+ parameters: [testUuid(2), testUuid(1)],
58
+ response: { rows: [{ post_id_old__: testUuid(99) }] },
59
+ },
60
+ ]),
61
+ ],
62
+ return: {
63
+ data: {
64
+ updatePost: {
65
+ ok: true,
66
+ },
67
+ },
68
+ },
69
+ })
70
+ })
71
+
72
+ test('set with orphanStrategy delete', async () => {
73
+ await execute({
74
+ schema: postWithNullableLocale,
75
+ query: GQL`mutation {
76
+ updatePost(
77
+ by: {id: "${testUuid(2)}"},
78
+ data: {locales: {orphanStrategy: delete, set: [{connect: {id: "${testUuid(1)}"}}]}}
79
+ ) {
80
+ ok
81
+ }
82
+ }`,
83
+ executes: [
84
+ ...sqlTransaction([
85
+ {
86
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
87
+ parameters: [testUuid(2)],
88
+ response: { rows: [{ id: testUuid(2) }] },
89
+ },
90
+ {
91
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
92
+ parameters: [testUuid(2)],
93
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
94
+ },
95
+ {
96
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
97
+ parameters: [testUuid(1)],
98
+ response: { rows: [{ id: testUuid(1) }] },
99
+ },
100
+ // orphan (id=3) is deleted
101
+ {
102
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
103
+ parameters: [testUuid(3), testUuid(2)],
104
+ response: { rows: [{ id: testUuid(3) }] },
105
+ },
106
+ {
107
+ sql: SQL`select "root_"."id" as "id", true as "allowed" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
108
+ parameters: [testUuid(3)],
109
+ response: { rows: [{ id: testUuid(3), allowed: true }] },
110
+ },
111
+ {
112
+ sql: SQL`delete from "public"."post_locale" where "id" in (?)`,
113
+ parameters: [testUuid(3)],
114
+ response: { rows: [{ id: testUuid(3) }] },
115
+ },
116
+ {
117
+ sql:
118
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
119
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
120
+ parameters: [testUuid(2), testUuid(1)],
121
+ response: { rows: [{ post_id_old__: testUuid(99) }] },
122
+ },
123
+ ]),
124
+ ],
125
+ return: {
126
+ data: {
127
+ updatePost: {
128
+ ok: true,
129
+ },
130
+ },
131
+ },
132
+ })
133
+ })
134
+
135
+ test('set without orphans (collection already matches)', async () => {
136
+ await execute({
137
+ schema: postWithNullableLocale,
138
+ query: GQL`mutation {
139
+ updatePost(
140
+ by: {id: "${testUuid(2)}"},
141
+ data: {locales: {set: [{connect: {id: "${testUuid(1)}"}}]}}
142
+ ) {
143
+ ok
144
+ }
145
+ }`,
146
+ executes: [
147
+ ...sqlTransaction([
148
+ {
149
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
150
+ parameters: [testUuid(2)],
151
+ response: { rows: [{ id: testUuid(2) }] },
152
+ },
153
+ // snapshot the members up front - orphans are members from *before* the operation
154
+ {
155
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
156
+ parameters: [testUuid(2)],
157
+ response: { rows: [{ primary_: testUuid(1) }] },
158
+ },
159
+ {
160
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
161
+ parameters: [testUuid(1)],
162
+ response: { rows: [{ id: testUuid(1) }] },
163
+ },
164
+ {
165
+ sql:
166
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
167
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
168
+ parameters: [testUuid(2), testUuid(1)],
169
+ response: { rows: [{ post_id_old__: testUuid(99) }] },
170
+ },
171
+ ]),
172
+ ],
173
+ return: {
174
+ data: {
175
+ updatePost: {
176
+ ok: true,
177
+ },
178
+ },
179
+ },
180
+ })
181
+ })
182
+
183
+ test('set with a create item and an orphan disconnect', async () => {
184
+ await execute({
185
+ schema: postWithNullableLocale,
186
+ query: GQL`mutation {
187
+ updatePost(
188
+ by: {id: "${testUuid(2)}"},
189
+ data: {locales: {set: [{create: {locale: "cs", title: "cs"}}]}}
190
+ ) {
191
+ ok
192
+ }
193
+ }`,
194
+ executes: [
195
+ ...sqlTransaction([
196
+ {
197
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
198
+ parameters: [testUuid(2)],
199
+ response: { rows: [{ id: testUuid(2) }] },
200
+ },
201
+ // snapshot the members up front - orphans are members from *before* the operation
202
+ {
203
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
204
+ parameters: [testUuid(2)],
205
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
206
+ },
207
+ // phase 2: a `create` item names no existing member, so both are orphans and go first
208
+ {
209
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
210
+ parameters: [testUuid(1), testUuid(2)],
211
+ response: { rows: [{ id: testUuid(1) }] },
212
+ },
213
+ {
214
+ sql:
215
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
216
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
217
+ parameters: [null, testUuid(1)],
218
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
219
+ },
220
+ {
221
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
222
+ parameters: [testUuid(3), testUuid(2)],
223
+ response: { rows: [{ id: testUuid(3) }] },
224
+ },
225
+ {
226
+ sql:
227
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
228
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
229
+ parameters: [null, testUuid(3)],
230
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
231
+ },
232
+ // phase 3: only now is the new locale inserted
233
+ {
234
+ sql:
235
+ SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "post_id") insert into "public"."post_locale" ("id", "title", "locale", "post_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."post_id" from "root_" returning "id"`,
236
+ parameters: [testUuid(1), 'cs', 'cs', testUuid(2)],
237
+ response: { rows: [{ id: testUuid(1) }] },
238
+ },
239
+ ]),
240
+ ],
241
+ return: {
242
+ data: {
243
+ updatePost: {
244
+ ok: true,
245
+ },
246
+ },
247
+ },
248
+ })
249
+ })
250
+
251
+ test('set must be the only item', async () => {
252
+ let error: unknown
253
+ try {
254
+ await execute({
255
+ schema: postWithNullableLocale,
256
+ query: GQL`mutation {
257
+ updatePost(
258
+ by: {id: "${testUuid(2)}"},
259
+ data: {locales: [{set: [{connect: {id: "${testUuid(1)}"}}]}, {connect: {id: "${testUuid(3)}"}}]}
260
+ ) {
261
+ ok
262
+ }
263
+ }`,
264
+ executes: [
265
+ ...sqlTransaction([]),
266
+ ],
267
+ return: {},
268
+ })
269
+ } catch (e) {
270
+ error = e
271
+ }
272
+ if (!(error instanceof Error) || !error.message.includes('"set" operation must be the only item')) {
273
+ throw new Error(`Expected a "set must be the only item" error, got: ${String(error)}`)
274
+ }
275
+ })
276
+
277
+ test('set with an update item (updates an existing member, no orphans)', async () => {
278
+ await execute({
279
+ schema: postWithNullableLocale,
280
+ query: GQL`mutation {
281
+ updatePost(
282
+ by: {id: "${testUuid(2)}"},
283
+ data: {locales: {set: [{update: {by: {id: "${testUuid(1)}"}, data: {title: "Hello"}}}]}}
284
+ ) {
285
+ ok
286
+ }
287
+ }`,
288
+ executes: [
289
+ ...sqlTransaction([
290
+ {
291
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
292
+ parameters: [testUuid(2)],
293
+ response: { rows: [{ id: testUuid(2) }] },
294
+ },
295
+ // snapshot the members up front - orphans are members from *before* the operation
296
+ {
297
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
298
+ parameters: [testUuid(2)],
299
+ response: { rows: [{ primary_: testUuid(1) }] },
300
+ },
301
+ // phase 1 resolves the update target scoped to the owner, so a partial composite
302
+ // unique key would work here just as it does for a plain per-item update
303
+ {
304
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
305
+ parameters: [testUuid(1), testUuid(2)],
306
+ response: { rows: [{ id: testUuid(1) }] },
307
+ },
308
+ // no orphans - the only member is the one the input names
309
+ // phase 3: the update processor resolves it again, then updates
310
+ {
311
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
312
+ parameters: [testUuid(1), testUuid(2)],
313
+ response: { rows: [{ id: testUuid(1) }] },
314
+ },
315
+ {
316
+ sql:
317
+ SQL`with "newData_" as (select ? :: text as "title", "root_"."title" as "title_old__", "root_"."id", "root_"."locale", "root_"."post_id" from "public"."post_locale" as "root_" where "root_"."id" = ?)
318
+ update "public"."post_locale" set "title" = "newData_"."title" from "newData_" where "post_locale"."id" = "newData_"."id" returning "title_old__"`,
319
+ parameters: ['Hello', testUuid(1)],
320
+ response: { rows: [{ title_old__: 'Hi' }] },
321
+ },
322
+ ]),
323
+ ],
324
+ return: {
325
+ data: {
326
+ updatePost: {
327
+ ok: true,
328
+ },
329
+ },
330
+ },
331
+ })
332
+ })
333
+
334
+ test('set with a connectOrCreate item (existing target) and an orphan disconnect', async () => {
335
+ await execute({
336
+ schema: postWithNullableLocale,
337
+ query: GQL`mutation {
338
+ updatePost(
339
+ by: {id: "${testUuid(2)}"},
340
+ data: {locales: {set: [{connectOrCreate: {connect: {id: "${testUuid(1)}"}, create: {locale: "cs", title: "cs"}}}]}}
341
+ ) {
342
+ ok
343
+ }
344
+ }`,
345
+ executes: [
346
+ ...sqlTransaction([
347
+ {
348
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
349
+ parameters: [testUuid(2)],
350
+ response: { rows: [{ id: testUuid(2) }] },
351
+ },
352
+ // snapshot the members up front - orphans are members from *before* the operation
353
+ {
354
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
355
+ parameters: [testUuid(2)],
356
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
357
+ },
358
+ // the set helper resolves the connectOrCreate target up-front to mark it desired
359
+ {
360
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
361
+ parameters: [testUuid(1)],
362
+ response: { rows: [{ id: testUuid(1) }] },
363
+ },
364
+ {
365
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
366
+ parameters: [testUuid(3), testUuid(2)],
367
+ response: { rows: [{ id: testUuid(3) }] },
368
+ },
369
+ {
370
+ sql:
371
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
372
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
373
+ parameters: [null, testUuid(3)],
374
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
375
+ },
376
+ // connectOrCreate processor resolves the target again, finds it, and connects it
377
+ {
378
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
379
+ parameters: [testUuid(1)],
380
+ response: { rows: [{ id: testUuid(1) }] },
381
+ },
382
+ {
383
+ sql:
384
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
385
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
386
+ parameters: [testUuid(2), testUuid(1)],
387
+ response: { rows: [{ post_id_old__: testUuid(99) }] },
388
+ },
389
+ ]),
390
+ ],
391
+ return: {
392
+ data: {
393
+ updatePost: {
394
+ ok: true,
395
+ },
396
+ },
397
+ },
398
+ })
399
+ })
400
+
401
+ test('set with an upsert item that creates (target does not exist)', async () => {
402
+ await execute({
403
+ schema: postWithNullableLocale,
404
+ query: GQL`mutation {
405
+ updatePost(
406
+ by: {id: "${testUuid(2)}"},
407
+ data: {locales: {set: [{upsert: {by: {id: "${testUuid(1)}"}, update: {title: "upd"}, create: {locale: "cs", title: "cs"}}}]}}
408
+ ) {
409
+ ok
410
+ }
411
+ }`,
412
+ executes: [
413
+ ...sqlTransaction([
414
+ {
415
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
416
+ parameters: [testUuid(2)],
417
+ response: { rows: [{ id: testUuid(2) }] },
418
+ },
419
+ // snapshot the members up front - orphans are members from *before* the operation
420
+ {
421
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
422
+ parameters: [testUuid(2)],
423
+ response: { rows: [{ primary_: testUuid(3) }] },
424
+ },
425
+ // phase 1 resolves the upsert target within the collection - it is not there
426
+ {
427
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
428
+ parameters: [testUuid(1), testUuid(2)],
429
+ response: { rows: [] },
430
+ },
431
+ // phase 2: the member the input does not name is disconnected first
432
+ {
433
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
434
+ parameters: [testUuid(3), testUuid(2)],
435
+ response: { rows: [{ id: testUuid(3) }] },
436
+ },
437
+ {
438
+ sql:
439
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
440
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
441
+ parameters: [null, testUuid(3)],
442
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
443
+ },
444
+ // phase 3: the upsert processor tries the update first, scoped to the owner - not found
445
+ {
446
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
447
+ parameters: [testUuid(1), testUuid(2)],
448
+ response: { rows: [] },
449
+ },
450
+ // falls back to insert
451
+ {
452
+ sql:
453
+ SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "post_id") insert into "public"."post_locale" ("id", "title", "locale", "post_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."post_id" from "root_" returning "id"`,
454
+ parameters: [testUuid(1), 'cs', 'cs', testUuid(2)],
455
+ response: { rows: [{ id: testUuid(1) }] },
456
+ },
457
+ ]),
458
+ ],
459
+ return: {
460
+ data: {
461
+ updatePost: {
462
+ ok: true,
463
+ },
464
+ },
465
+ },
466
+ })
467
+ })
468
+
469
+ test('set with orphanStrategy delete is rejected when delete is ACL-denied', async () => {
470
+ await execute({
471
+ schema: postWithNullableLocale,
472
+ query: GQL`mutation {
473
+ updatePost(
474
+ by: {id: "${testUuid(2)}"},
475
+ data: {locales: {orphanStrategy: delete, set: [{connect: {id: "${testUuid(1)}"}}]}}
476
+ ) {
477
+ ok
478
+ }
479
+ }`,
480
+ executes: [
481
+ ...failedTransaction([
482
+ {
483
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
484
+ parameters: [testUuid(2)],
485
+ response: { rows: [{ id: testUuid(2) }] },
486
+ },
487
+ {
488
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
489
+ parameters: [testUuid(2)],
490
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
491
+ },
492
+ {
493
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
494
+ parameters: [testUuid(1)],
495
+ response: { rows: [{ id: testUuid(1) }] },
496
+ },
497
+ // orphan (id=3): delete is attempted, but the ACL predicate denies it
498
+ {
499
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
500
+ parameters: [testUuid(3), testUuid(2)],
501
+ response: { rows: [{ id: testUuid(3) }] },
502
+ },
503
+ {
504
+ sql: SQL`select "root_"."id" as "id", true as "allowed" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
505
+ parameters: [testUuid(3)],
506
+ response: { rows: [{ id: testUuid(3), allowed: false }] },
507
+ },
508
+ ]),
509
+ ],
510
+ return: {
511
+ data: {
512
+ updatePost: {
513
+ ok: false,
514
+ },
515
+ },
516
+ },
517
+ })
518
+ })
519
+
520
+ test('empty set clears the whole collection (disconnect)', async () => {
521
+ await execute({
522
+ schema: postWithNullableLocale,
523
+ query: GQL`mutation {
524
+ updatePost(
525
+ by: {id: "${testUuid(2)}"},
526
+ data: {locales: {set: []}}
527
+ ) {
528
+ ok
529
+ }
530
+ }`,
531
+ executes: [
532
+ ...sqlTransaction([
533
+ {
534
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
535
+ parameters: [testUuid(2)],
536
+ response: { rows: [{ id: testUuid(2) }] },
537
+ },
538
+ // no desired members - every current member is an orphan
539
+ {
540
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
541
+ parameters: [testUuid(2)],
542
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
543
+ },
544
+ // orphan (id=1) disconnected
545
+ {
546
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
547
+ parameters: [testUuid(1), testUuid(2)],
548
+ response: { rows: [{ id: testUuid(1) }] },
549
+ },
550
+ {
551
+ sql:
552
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
553
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
554
+ parameters: [null, testUuid(1)],
555
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
556
+ },
557
+ // orphan (id=3) disconnected
558
+ {
559
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
560
+ parameters: [testUuid(3), testUuid(2)],
561
+ response: { rows: [{ id: testUuid(3) }] },
562
+ },
563
+ {
564
+ sql:
565
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
566
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
567
+ parameters: [null, testUuid(3)],
568
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
569
+ },
570
+ ]),
571
+ ],
572
+ return: {
573
+ data: {
574
+ updatePost: {
575
+ ok: true,
576
+ },
577
+ },
578
+ },
579
+ })
580
+ })
581
+
582
+ // An upsert whose `by` names a record outside the collection falls back to an insert. Phase 1
583
+ // resolves `by` within the collection, so it marks nothing, and the record the insert creates
584
+ // cannot be an orphan - it did not exist when the snapshot was taken.
585
+ test('set with an upsert item whose "by" matches a record outside the collection', async () => {
586
+ await execute({
587
+ schema: postWithNullableLocale,
588
+ query: GQL`mutation {
589
+ updatePost(
590
+ by: {id: "${testUuid(2)}"},
591
+ data: {locales: {set: [{upsert: {by: {id: "${testUuid(10)}"}, update: {title: "upd"}, create: {locale: "cs", title: "cs"}}}]}}
592
+ ) {
593
+ ok
594
+ }
595
+ }`,
596
+ executes: [
597
+ ...sqlTransaction([
598
+ {
599
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
600
+ parameters: [testUuid(2)],
601
+ response: { rows: [{ id: testUuid(2) }] },
602
+ },
603
+ // snapshot the members up front - orphans are members from *before* the operation
604
+ {
605
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
606
+ parameters: [testUuid(2)],
607
+ response: { rows: [{ primary_: testUuid(3) }] },
608
+ },
609
+ // phase 1 resolves `by` within the collection - not there, so nothing is marked
610
+ {
611
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
612
+ parameters: [testUuid(10), testUuid(2)],
613
+ response: { rows: [] },
614
+ },
615
+ // phase 2: only the pre-existing member (id=3) is orphaned
616
+ {
617
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
618
+ parameters: [testUuid(3), testUuid(2)],
619
+ response: { rows: [{ id: testUuid(3) }] },
620
+ },
621
+ {
622
+ sql:
623
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
624
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
625
+ parameters: [null, testUuid(3)],
626
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
627
+ },
628
+ // phase 3: the upsert processor tries its own scoped update first - not found
629
+ {
630
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
631
+ parameters: [testUuid(10), testUuid(2)],
632
+ response: { rows: [] },
633
+ },
634
+ // falls back to insert; the new record survives the operation
635
+ {
636
+ sql:
637
+ SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "post_id") insert into "public"."post_locale" ("id", "title", "locale", "post_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."post_id" from "root_" returning "id"`,
638
+ parameters: [testUuid(1), 'cs', 'cs', testUuid(2)],
639
+ response: { rows: [{ id: testUuid(1) }] },
640
+ },
641
+ ]),
642
+ ],
643
+ return: {
644
+ data: {
645
+ updatePost: {
646
+ ok: true,
647
+ },
648
+ },
649
+ },
650
+ })
651
+ })
652
+
653
+ // The relation input type exposes `alias` next to `set`, so it must be accepted (and ignored)
654
+ // rather than rejected as an unexpected key.
655
+ test('set accepts an alias on the relation input', async () => {
656
+ await execute({
657
+ schema: postWithNullableLocale,
658
+ query: GQL`mutation {
659
+ updatePost(
660
+ by: {id: "${testUuid(2)}"},
661
+ data: {locales: {alias: "myAlias", set: [{connect: {id: "${testUuid(1)}"}}]}}
662
+ ) {
663
+ ok
664
+ }
665
+ }`,
666
+ executes: [
667
+ ...sqlTransaction([
668
+ {
669
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
670
+ parameters: [testUuid(2)],
671
+ response: { rows: [{ id: testUuid(2) }] },
672
+ },
673
+ {
674
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
675
+ parameters: [testUuid(2)],
676
+ response: { rows: [{ primary_: testUuid(1) }] },
677
+ },
678
+ {
679
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
680
+ parameters: [testUuid(1)],
681
+ response: { rows: [{ id: testUuid(1) }] },
682
+ },
683
+ {
684
+ sql:
685
+ SQL`with "newData_" as (select ? :: uuid as "post_id", "root_"."post_id" as "post_id_old__", "root_"."id", "root_"."title", "root_"."locale" from "public"."post_locale" as "root_" where "root_"."id" = ?)
686
+ update "public"."post_locale" set "post_id" = "newData_"."post_id" from "newData_" where "post_locale"."id" = "newData_"."id" returning "post_id_old__"`,
687
+ parameters: [testUuid(2), testUuid(1)],
688
+ response: { rows: [{ post_id_old__: testUuid(2) }] },
689
+ },
690
+ ]),
691
+ ],
692
+ return: {
693
+ data: {
694
+ updatePost: {
695
+ ok: true,
696
+ },
697
+ },
698
+ },
699
+ })
700
+ })
701
+
702
+ // A not-null owning relation has nowhere to put the null, so the default `disconnect` strategy
703
+ // cannot remove an orphan. The engine reports it instead of emitting a doomed UPDATE.
704
+ test('set with the default orphanStrategy fails on a not-null owning relation', async () => {
705
+ await execute({
706
+ schema: postWithLocale,
707
+ query: GQL`mutation {
708
+ updatePost(
709
+ by: {id: "${testUuid(2)}"},
710
+ data: {locales: {set: [{connect: {id: "${testUuid(1)}"}}]}}
711
+ ) {
712
+ ok
713
+ errors {
714
+ type
715
+ }
716
+ }
717
+ }`,
718
+ executes: [
719
+ ...failedTransaction([
720
+ {
721
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
722
+ parameters: [testUuid(2)],
723
+ response: { rows: [{ id: testUuid(2) }] },
724
+ },
725
+ // snapshot the members up front - orphans are members from *before* the operation
726
+ {
727
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
728
+ parameters: [testUuid(2)],
729
+ response: { rows: [{ primary_: testUuid(1) }, { primary_: testUuid(3) }] },
730
+ },
731
+ {
732
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ?`,
733
+ parameters: [testUuid(1)],
734
+ response: { rows: [{ id: testUuid(1) }] },
735
+ },
736
+ // orphan (id=3): resolved, but there is no way to detach it
737
+ {
738
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."id" = ? and "root_"."post_id" = ?`,
739
+ parameters: [testUuid(3), testUuid(2)],
740
+ response: { rows: [{ id: testUuid(3) }] },
741
+ },
742
+ ]),
743
+ ],
744
+ return: {
745
+ data: {
746
+ updatePost: {
747
+ ok: false,
748
+ errors: [{ type: 'NotNullConstraintViolation' }],
749
+ },
750
+ },
751
+ },
752
+ })
753
+ })
754
+
755
+ // Nullable GraphQL variables mean an operation key can arrive as an explicit null. The per-item
756
+ // path strips those before dispatching; `set` items have to behave the same, or the null key
757
+ // picks its branch and the mutation dies with an internal error.
758
+ test('set strips null-valued operation keys from an item', async () => {
759
+ await execute({
760
+ schema: postWithNullableLocale,
761
+ query: GQL`mutation {
762
+ updatePost(
763
+ by: {id: "${testUuid(2)}"},
764
+ data: {locales: {set: [{connect: null, create: {locale: "cs", title: "cs"}}]}}
765
+ ) {
766
+ ok
767
+ }
768
+ }`,
769
+ executes: [
770
+ ...sqlTransaction([
771
+ {
772
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
773
+ parameters: [testUuid(2)],
774
+ response: { rows: [{ id: testUuid(2) }] },
775
+ },
776
+ {
777
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
778
+ parameters: [testUuid(2)],
779
+ response: { rows: [] },
780
+ },
781
+ {
782
+ sql:
783
+ SQL`with "root_" as (select ? :: uuid as "id", ? :: text as "title", ? :: text as "locale", ? :: uuid as "post_id") insert into "public"."post_locale" ("id", "title", "locale", "post_id") select "root_"."id", "root_"."title", "root_"."locale", "root_"."post_id" from "root_" returning "id"`,
784
+ parameters: [testUuid(1), 'cs', 'cs', testUuid(2)],
785
+ response: { rows: [{ id: testUuid(1) }] },
786
+ },
787
+ ]),
788
+ ],
789
+ return: {
790
+ data: {
791
+ updatePost: {
792
+ ok: true,
793
+ },
794
+ },
795
+ },
796
+ })
797
+ })
798
+
799
+ // `set: null` is schema-valid (the field is a nullable list). It must be rejected with a user error
800
+ // rather than routed into the set path, where it would clear the collection.
801
+ test('set: null is rejected as a missing operation', async () => {
802
+ let error: unknown
803
+ try {
804
+ await execute({
805
+ schema: postWithNullableLocale,
806
+ query: GQL`mutation {
807
+ updatePost(
808
+ by: {id: "${testUuid(2)}"},
809
+ data: {locales: {set: null}}
810
+ ) {
811
+ ok
812
+ }
813
+ }`,
814
+ executes: [
815
+ ...sqlTransaction([
816
+ {
817
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
818
+ parameters: [testUuid(2)],
819
+ response: { rows: [{ id: testUuid(2) }] },
820
+ },
821
+ ]),
822
+ ],
823
+ return: {},
824
+ })
825
+ } catch (e) {
826
+ error = e
827
+ }
828
+ if (!(error instanceof Error) || !error.message.includes('Expected exactly one of')) {
829
+ throw new Error(`Expected a user error about a missing operation, got: ${String(error)}`)
830
+ }
831
+ })
832
+
833
+ // The owner scope is what lets a partial composite unique key address a member, so phase 1 has to
834
+ // resolve `update.by` the same way the processor does - a global lookup would reject `{locale}`
835
+ // as non-unique on an entity whose unique key is (locale, post).
836
+ test('set resolves a partial composite unique `by` within the collection', async () => {
837
+ await execute({
838
+ schema: postWithNullableLocale,
839
+ query: GQL`mutation {
840
+ updatePost(
841
+ by: {id: "${testUuid(2)}"},
842
+ data: {locales: {set: [{update: {by: {locale: "cs"}, data: {title: "Hello"}}}]}}
843
+ ) {
844
+ ok
845
+ }
846
+ }`,
847
+ executes: [
848
+ ...sqlTransaction([
849
+ {
850
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
851
+ parameters: [testUuid(2)],
852
+ response: { rows: [{ id: testUuid(2) }] },
853
+ },
854
+ {
855
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ?`,
856
+ parameters: [testUuid(2)],
857
+ response: { rows: [{ primary_: testUuid(1) }] },
858
+ },
859
+ // phase 1: `{locale: "cs"}` alone is only unique once the owner completes it
860
+ {
861
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
862
+ parameters: ['cs', testUuid(2)],
863
+ response: { rows: [{ id: testUuid(1) }] },
864
+ },
865
+ // phase 3: the update processor resolves it again, then updates
866
+ {
867
+ sql: SQL`select "root_"."id" from "public"."post_locale" as "root_" where "root_"."locale" = ? and "root_"."post_id" = ?`,
868
+ parameters: ['cs', testUuid(2)],
869
+ response: { rows: [{ id: testUuid(1) }] },
870
+ },
871
+ {
872
+ sql:
873
+ SQL`with "newData_" as (select ? :: text as "title", "root_"."title" as "title_old__", "root_"."id", "root_"."locale", "root_"."post_id" from "public"."post_locale" as "root_" where "root_"."id" = ?)
874
+ update "public"."post_locale" set "title" = "newData_"."title" from "newData_" where "post_locale"."id" = "newData_"."id" returning "title_old__"`,
875
+ parameters: ['Hello', testUuid(1)],
876
+ response: { rows: [{ title_old__: 'Hi' }] },
877
+ },
878
+ ]),
879
+ ],
880
+ return: {
881
+ data: {
882
+ updatePost: {
883
+ ok: true,
884
+ },
885
+ },
886
+ },
887
+ })
888
+ })
889
+
890
+ // Orphans are found by the FK column and the target's read predicate only, like the many-has-many
891
+ // junction read. The owner's read predicate must not hide members from the diff.
892
+ const restrictedReadPermissions: Acl.Permissions = {
893
+ Post: {
894
+ predicates: {
895
+ post_read_predicate: { id: { eq: testUuid(2) } },
896
+ },
897
+ operations: {
898
+ read: { id: 'post_read_predicate' },
899
+ update: { id: true, locales: true },
900
+ },
901
+ },
902
+ PostLocale: {
903
+ predicates: {
904
+ locale_read_predicate: { locale: { eq: 'cs' } },
905
+ },
906
+ operations: {
907
+ read: { id: 'locale_read_predicate', post: true, locale: 'locale_read_predicate' },
908
+ update: { post: true },
909
+ },
910
+ },
911
+ }
912
+
913
+ test('set applies only the target read predicate when computing orphans', async () => {
914
+ await execute({
915
+ schema: postWithNullableLocale,
916
+ permissions: restrictedReadPermissions,
917
+ variables: {},
918
+ query: GQL`mutation {
919
+ updatePost(
920
+ by: {id: "${testUuid(2)}"},
921
+ data: {locales: {set: []}}
922
+ ) {
923
+ ok
924
+ }
925
+ }`,
926
+ executes: [
927
+ ...sqlTransaction([
928
+ {
929
+ sql: SQL`select "root_"."id" from "public"."post" as "root_" where "root_"."id" = ?`,
930
+ parameters: [testUuid(2)],
931
+ response: { rows: [{ id: testUuid(2) }] },
932
+ },
933
+ {
934
+ sql: SQL`select "root_"."id" as "primary_" from "public"."post_locale" as "root_" where "root_"."post_id" = ? and "root_"."locale" = ?`,
935
+ parameters: [testUuid(2), 'cs'],
936
+ response: { rows: [] },
937
+ },
938
+ ]),
939
+ ],
940
+ return: {
941
+ data: {
942
+ updatePost: {
943
+ ok: true,
944
+ },
945
+ },
946
+ },
947
+ })
948
+ })