@contember/engine-content-api 2.2.0-alpha.1 → 2.2.0-alpha.11

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/CLAUDE.md +12 -0
  2. package/dist/development/src/ExecutionContainer.cjs +7 -4
  3. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  4. package/dist/development/src/ExecutionContainer.js +7 -4
  5. package/dist/development/src/ExecutionContainer.js.map +1 -1
  6. package/dist/development/src/acl/PredicatesInjector.cjs +1 -68
  7. package/dist/development/src/acl/PredicatesInjector.cjs.map +1 -1
  8. package/dist/development/src/acl/PredicatesInjector.js +1 -68
  9. package/dist/development/src/acl/PredicatesInjector.js.map +1 -1
  10. package/dist/development/src/mapper/Mapper.cjs +8 -5
  11. package/dist/development/src/mapper/Mapper.cjs.map +1 -1
  12. package/dist/development/src/mapper/Mapper.js +8 -5
  13. package/dist/development/src/mapper/Mapper.js.map +1 -1
  14. package/dist/development/src/mapper/MapperFactory.cjs +7 -4
  15. package/dist/development/src/mapper/MapperFactory.cjs.map +1 -1
  16. package/dist/development/src/mapper/MapperFactory.js +7 -4
  17. package/dist/development/src/mapper/MapperFactory.js.map +1 -1
  18. package/dist/development/src/mapper/select/ConditionBuilder.cjs +8 -1
  19. package/dist/development/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  20. package/dist/development/src/mapper/select/ConditionBuilder.js +8 -1
  21. package/dist/development/src/mapper/select/ConditionBuilder.js.map +1 -1
  22. package/dist/development/src/mapper/select/RelationFetcher.cjs +2 -2
  23. package/dist/development/src/mapper/select/RelationFetcher.cjs.map +1 -1
  24. package/dist/development/src/mapper/select/RelationFetcher.js +2 -2
  25. package/dist/development/src/mapper/select/RelationFetcher.js.map +1 -1
  26. package/dist/development/src/mapper/select/SelectHydrator.cjs +39 -19
  27. package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
  28. package/dist/development/src/mapper/select/SelectHydrator.js +39 -19
  29. package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
  30. package/dist/development/src/resolvers/MutationResolver.cjs +49 -35
  31. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  32. package/dist/development/src/resolvers/MutationResolver.js +50 -36
  33. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  34. package/dist/production/src/ExecutionContainer.cjs +7 -4
  35. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  36. package/dist/production/src/ExecutionContainer.js +7 -4
  37. package/dist/production/src/ExecutionContainer.js.map +1 -1
  38. package/dist/production/src/acl/PredicatesInjector.cjs +1 -68
  39. package/dist/production/src/acl/PredicatesInjector.cjs.map +1 -1
  40. package/dist/production/src/acl/PredicatesInjector.js +1 -68
  41. package/dist/production/src/acl/PredicatesInjector.js.map +1 -1
  42. package/dist/production/src/mapper/Mapper.cjs +8 -5
  43. package/dist/production/src/mapper/Mapper.cjs.map +1 -1
  44. package/dist/production/src/mapper/Mapper.js +8 -5
  45. package/dist/production/src/mapper/Mapper.js.map +1 -1
  46. package/dist/production/src/mapper/MapperFactory.cjs +7 -4
  47. package/dist/production/src/mapper/MapperFactory.cjs.map +1 -1
  48. package/dist/production/src/mapper/MapperFactory.js +7 -4
  49. package/dist/production/src/mapper/MapperFactory.js.map +1 -1
  50. package/dist/production/src/mapper/select/ConditionBuilder.cjs +8 -1
  51. package/dist/production/src/mapper/select/ConditionBuilder.cjs.map +1 -1
  52. package/dist/production/src/mapper/select/ConditionBuilder.js +8 -1
  53. package/dist/production/src/mapper/select/ConditionBuilder.js.map +1 -1
  54. package/dist/production/src/mapper/select/RelationFetcher.cjs +2 -2
  55. package/dist/production/src/mapper/select/RelationFetcher.cjs.map +1 -1
  56. package/dist/production/src/mapper/select/RelationFetcher.js +2 -2
  57. package/dist/production/src/mapper/select/RelationFetcher.js.map +1 -1
  58. package/dist/production/src/mapper/select/SelectHydrator.cjs +39 -19
  59. package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
  60. package/dist/production/src/mapper/select/SelectHydrator.js +39 -19
  61. package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
  62. package/dist/production/src/resolvers/MutationResolver.cjs +49 -35
  63. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  64. package/dist/production/src/resolvers/MutationResolver.js +50 -36
  65. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  66. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts +2 -0
  67. package/dist/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.d.ts.map +1 -0
  68. package/dist/tests/cases/integration/graphQlRequests/validation/utils.d.ts.map +1 -1
  69. package/dist/tests/cases/integration/graphQlSchema/model.d.ts +1 -1
  70. package/dist/tests/src/assert.d.ts.map +1 -1
  71. package/dist/tests/src/tags.d.ts.map +1 -1
  72. package/dist/tests/src/test.d.ts +2 -0
  73. package/dist/tests/src/test.d.ts.map +1 -1
  74. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  75. package/dist/tests/src/testUuid.d.ts.map +1 -1
  76. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  77. package/dist/types/ExecutionContainer.d.ts +3 -2
  78. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  79. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  80. package/dist/types/acl/EvaluatedPredicateReplacer.d.ts.map +1 -1
  81. package/dist/types/acl/PermissionFactory.d.ts.map +1 -1
  82. package/dist/types/acl/PredicateFactory.d.ts.map +1 -1
  83. package/dist/types/acl/PredicatesInjector.d.ts +0 -6
  84. package/dist/types/acl/PredicatesInjector.d.ts.map +1 -1
  85. package/dist/types/acl/VariableInjector.d.ts.map +1 -1
  86. package/dist/types/acl/VariableUtils.d.ts.map +1 -1
  87. package/dist/types/exception.d.ts.map +1 -1
  88. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducer.d.ts.map +1 -1
  89. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneReducerExecutionHandler.d.ts.map +1 -1
  90. package/dist/types/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.d.ts.map +1 -1
  91. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyCountVisitor.d.ts.map +1 -1
  92. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyExecutionHandler.d.ts.map +1 -1
  93. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProvider.d.ts.map +1 -1
  94. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.d.ts.map +1 -1
  95. package/dist/types/extensions/paginatedHasMany/PaginatedHasManyNodesVisitor.d.ts.map +1 -1
  96. package/dist/types/input-validation/ColumnValueResolver.d.ts.map +1 -1
  97. package/dist/types/input-validation/EntityRulesResolver.d.ts.map +1 -1
  98. package/dist/types/input-validation/JsonSchemaValidator.d.ts.map +1 -1
  99. package/dist/types/input-validation/QueryAstFactory.d.ts.map +1 -1
  100. package/dist/types/input-validation/ValidationContext.d.ts.map +1 -1
  101. package/dist/types/input-validation/ValidationDataSelector.d.ts +1 -1
  102. package/dist/types/input-validation/ValidationDataSelector.d.ts.map +1 -1
  103. package/dist/types/input-validation/ValidationEvaluation.d.ts.map +1 -1
  104. package/dist/types/input-validation/ValidationPath.d.ts.map +1 -1
  105. package/dist/types/input-validation/dependencies/DependencyCollector.d.ts.map +1 -1
  106. package/dist/types/input-validation/dependencies/DependencyMerger.d.ts.map +1 -1
  107. package/dist/types/input-validation/preValidation/CreateInputPreValidationProcessor.d.ts.map +1 -1
  108. package/dist/types/input-validation/preValidation/InputPreValidator.d.ts.map +1 -1
  109. package/dist/types/input-validation/preValidation/UpdateInputPreValidationProcessor.d.ts.map +1 -1
  110. package/dist/types/inputProcessing/CreateInputVisitor.d.ts.map +1 -1
  111. package/dist/types/inputProcessing/FieldNode.d.ts.map +1 -1
  112. package/dist/types/inputProcessing/ObjectNode.d.ts.map +1 -1
  113. package/dist/types/inputProcessing/UniqueWhereExpander.d.ts.map +1 -1
  114. package/dist/types/inputProcessing/UpdateInputVisitor.d.ts.map +1 -1
  115. package/dist/types/introspection/IntrospectionSchemaDefinitionFactory.d.ts.map +1 -1
  116. package/dist/types/introspection/IntrospectionSchemaFactory.d.ts.map +1 -1
  117. package/dist/types/introspection/introspection.schema.d.ts.map +1 -1
  118. package/dist/types/mapper/CheckedPrimary.d.ts.map +1 -1
  119. package/dist/types/mapper/ColumnValue.d.ts.map +1 -1
  120. package/dist/types/mapper/Constraints.d.ts.map +1 -1
  121. package/dist/types/mapper/ErrorUtils.d.ts.map +1 -1
  122. package/dist/types/mapper/EventManager.d.ts +9 -9
  123. package/dist/types/mapper/EventManager.d.ts.map +1 -1
  124. package/dist/types/mapper/JunctionTableManager.d.ts.map +1 -1
  125. package/dist/types/mapper/Mapper.d.ts +5 -2
  126. package/dist/types/mapper/Mapper.d.ts.map +1 -1
  127. package/dist/types/mapper/MapperFactory.d.ts +3 -2
  128. package/dist/types/mapper/MapperFactory.d.ts.map +1 -1
  129. package/dist/types/mapper/MutationProcessorHelper.d.ts.map +1 -1
  130. package/dist/types/mapper/Result.d.ts.map +1 -1
  131. package/dist/types/mapper/delete/DeleteExecutor.d.ts.map +1 -1
  132. package/dist/types/mapper/delete/DeleteState.d.ts.map +1 -1
  133. package/dist/types/mapper/delete/DeletedEntitiesStorage.d.ts.map +1 -1
  134. package/dist/types/mapper/delete/helpers.d.ts +1 -1
  135. package/dist/types/mapper/delete/helpers.d.ts.map +1 -1
  136. package/dist/types/mapper/insert/InsertBuilder.d.ts.map +1 -1
  137. package/dist/types/mapper/insert/InsertBuilderFactory.d.ts.map +1 -1
  138. package/dist/types/mapper/insert/Inserter.d.ts.map +1 -1
  139. package/dist/types/mapper/insert/SqlCreateInputProcessor.d.ts.map +1 -1
  140. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts +1 -1
  141. package/dist/types/mapper/insert/relations/ManyHasManyCreateInputProcessor.d.ts.map +1 -1
  142. package/dist/types/mapper/insert/relations/ManyHasOneCreateInputProcessor.d.ts.map +1 -1
  143. package/dist/types/mapper/insert/relations/OneHasManyCreateInputProcessor.d.ts.map +1 -1
  144. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts +1 -1
  145. package/dist/types/mapper/insert/relations/OneHasOneInverseCreateInputProcessor.d.ts.map +1 -1
  146. package/dist/types/mapper/insert/relations/OneHasOneOwningCreateInputProcessor.d.ts.map +1 -1
  147. package/dist/types/mapper/select/ConditionBuilder.d.ts.map +1 -1
  148. package/dist/types/mapper/select/JoinBuilder.d.ts.map +1 -1
  149. package/dist/types/mapper/select/JoinVisitor.d.ts.map +1 -1
  150. package/dist/types/mapper/select/OrderByBuilder.d.ts.map +1 -1
  151. package/dist/types/mapper/select/OrderByHelper.d.ts.map +1 -1
  152. package/dist/types/mapper/select/Path.d.ts.map +1 -1
  153. package/dist/types/mapper/select/RelationFetcher.d.ts.map +1 -1
  154. package/dist/types/mapper/select/SelectBuilder.d.ts.map +1 -1
  155. package/dist/types/mapper/select/SelectHydrator.d.ts +6 -0
  156. package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
  157. package/dist/types/mapper/select/WhereBuilder.d.ts.map +1 -1
  158. package/dist/types/mapper/select/handlers/FieldsVisitor.d.ts.map +1 -1
  159. package/dist/types/mapper/select/handlers/FieldsVisitorFactory.d.ts.map +1 -1
  160. package/dist/types/mapper/select/handlers/MetaHandler.d.ts.map +1 -1
  161. package/dist/types/mapper/select/optimizer/ConditionOptimizer.d.ts.map +1 -1
  162. package/dist/types/mapper/select/optimizer/WhereOptimizer.d.ts.map +1 -1
  163. package/dist/types/mapper/select/optimizer/WhereReplacer.d.ts.map +1 -1
  164. package/dist/types/mapper/select/optimizer/helpers.d.ts +1 -1
  165. package/dist/types/mapper/select/optimizer/helpers.d.ts.map +1 -1
  166. package/dist/types/mapper/update/SqlUpdateInputProcessor.d.ts.map +1 -1
  167. package/dist/types/mapper/update/UpdateBuilder.d.ts.map +1 -1
  168. package/dist/types/mapper/update/UpdateBuilderFactory.d.ts.map +1 -1
  169. package/dist/types/mapper/update/Updater.d.ts.map +1 -1
  170. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts +2 -2
  171. package/dist/types/mapper/update/relations/ManyHasManyUpdateInputProcessor.d.ts.map +1 -1
  172. package/dist/types/mapper/update/relations/ManyHasOneUpdateInputProcessor.d.ts.map +1 -1
  173. package/dist/types/mapper/update/relations/OneHasManyUpdateInputProcessor.d.ts.map +1 -1
  174. package/dist/types/mapper/update/relations/OneHasOneInverseUpdateInputProcessor.d.ts.map +1 -1
  175. package/dist/types/mapper/update/relations/OneHasOneOwningUpdateInputProcessor.d.ts.map +1 -1
  176. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  177. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  178. package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
  179. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  180. package/dist/types/resolvers/RefreshViewResolver.d.ts.map +1 -1
  181. package/dist/types/resolvers/ValidationResolver.d.ts.map +1 -1
  182. package/dist/types/schema/ColumnTypeResolver.d.ts.map +1 -1
  183. package/dist/types/schema/ConditionTypeProvider.d.ts.map +1 -1
  184. package/dist/types/schema/EntityTypeProvider.d.ts.map +1 -1
  185. package/dist/types/schema/EnumsProvider.d.ts.map +1 -1
  186. package/dist/types/schema/FieldAccessVisitor.d.ts.map +1 -1
  187. package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
  188. package/dist/types/schema/GraphQlSchemaBuilderFactory.d.ts.map +1 -1
  189. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  190. package/dist/types/schema/OperationExtension.d.ts.map +1 -1
  191. package/dist/types/schema/OrderByTypeProvider.d.ts.map +1 -1
  192. package/dist/types/schema/PaginatedFieldConfigFactory.d.ts.map +1 -1
  193. package/dist/types/schema/QueryProvider.d.ts.map +1 -1
  194. package/dist/types/schema/RefreshViewMutationProvider.d.ts.map +1 -1
  195. package/dist/types/schema/ValidationQueriesProvider.d.ts.map +1 -1
  196. package/dist/types/schema/WhereTypeProvider.d.ts.map +1 -1
  197. package/dist/types/schema/entities/FieldArgsVisitor.d.ts.map +1 -1
  198. package/dist/types/schema/entities/FieldTypeVisitor.d.ts.map +1 -1
  199. package/dist/types/schema/mutations/ConnectOrCreateRelationInputProvider.d.ts.map +1 -1
  200. package/dist/types/schema/mutations/CreateEntityInputFieldVisitor.d.ts.map +1 -1
  201. package/dist/types/schema/mutations/CreateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  202. package/dist/types/schema/mutations/CreateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  203. package/dist/types/schema/mutations/CreateEntityRelationInputProvider.d.ts.map +1 -1
  204. package/dist/types/schema/mutations/EntityInputProvider.d.ts.map +1 -1
  205. package/dist/types/schema/mutations/UpdateEntityInputFieldVisitor.d.ts.map +1 -1
  206. package/dist/types/schema/mutations/UpdateEntityRelationAllowedOperationsVisitor.d.ts.map +1 -1
  207. package/dist/types/schema/mutations/UpdateEntityRelationInputFieldVisitor.d.ts.map +1 -1
  208. package/dist/types/schema/mutations/UpdateEntityRelationInputProvider.d.ts.map +1 -1
  209. package/dist/types/schema/utils.d.ts.map +1 -1
  210. package/dist/types/tsconfig.tsbuildinfo +1 -1
  211. package/dist/types/utils/Mutex.d.ts.map +1 -1
  212. package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
  213. package/dist/types/utils/accessor.d.ts.map +1 -1
  214. package/dist/types/utils/isIt.d.ts.map +1 -1
  215. package/dist/types/utils/paginationUtils.d.ts.map +1 -1
  216. package/dist/types/utils/promises.d.ts.map +1 -1
  217. package/dist/types/utils/singletonFactory.d.ts.map +1 -1
  218. package/dist/types/utils/strings.d.ts.map +1 -1
  219. package/dist/types/utils/tuple.d.ts.map +1 -1
  220. package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
  221. package/dist/types/utils/viewComputedId.d.ts.map +1 -1
  222. package/package.json +9 -9
  223. package/src/ExecutionContainer.ts +7 -2
  224. package/src/acl/PredicatesInjector.ts +1 -104
  225. package/src/mapper/Mapper.ts +9 -5
  226. package/src/mapper/MapperFactory.ts +7 -3
  227. package/src/mapper/select/ConditionBuilder.ts +12 -1
  228. package/src/mapper/select/RelationFetcher.ts +2 -4
  229. package/src/mapper/select/SelectHydrator.ts +43 -16
  230. package/src/resolvers/MutationResolver.ts +59 -36
  231. package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +97 -0
  232. package/tests/cases/integration/graphQlRequests/query/pagination/hasManyLimit.test.ts +48 -2
  233. package/tests/cases/integration/graphQlRequests/query/relations/oneHasMany.test.ts +3 -3
  234. package/tests/cases/integration/graphQlRequests/query/sorting/randomSort.test.ts +1 -1
  235. package/tests/cases/integration/graphQlSchema/schema-acl-allowed.gql +1 -0
  236. package/tests/cases/integration/graphQlSchema/schema-acl-create-only.gql +1 -0
  237. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-create.gql +1 -0
  238. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-delete.gql +1 -0
  239. package/tests/cases/integration/graphQlSchema/schema-acl-restricted-update.gql +1 -0
  240. package/tests/cases/integration/graphQlSchema/schema-acl.gql +1 -0
  241. package/tests/cases/integration/graphQlSchema/schema-aliased-type.gql +1 -0
  242. package/tests/cases/integration/graphQlSchema/schema-array.gql +1 -0
  243. package/tests/cases/integration/graphQlSchema/schema-basic.gql +1 -0
  244. package/tests/cases/integration/graphQlSchema/schema-bug-66.gql +1 -0
  245. package/tests/cases/integration/graphQlSchema/schema-column-types.gql +1 -0
  246. package/tests/cases/integration/graphQlSchema/schema-custom-primary.gql +1 -0
  247. package/tests/cases/integration/graphQlSchema/schema-has-many-reduction.gql +1 -0
  248. package/tests/cases/integration/graphQlSchema/schema-new-builder.gql +1 -0
  249. package/tests/cases/integration/graphQlSchema/schema-no-root-ops.gql +1 -0
  250. package/tests/cases/unit/predicatesInjector.test.ts +15 -67
  251. package/tests/src/test.ts +3 -1
@@ -0,0 +1,97 @@
1
+ import { test } from 'bun:test'
2
+ import { execute, failedTransaction, sqlTransaction } from '../../../../src/test.js'
3
+ import { SchemaBuilder } from '@contember/schema-definition'
4
+ import { Model } from '@contember/schema'
5
+ import { RequestMemoryBudget } from '@contember/database'
6
+ import { GQL, SQL } from '../../../../src/tags.js'
7
+ import { testUuid } from '../../../../src/testUuid.js'
8
+
9
+ const insertAuthor = (id: string) => ({
10
+ sql: SQL`with "root_" as
11
+ (select ? :: uuid as "id", ? :: text as "name")
12
+ insert into "public"."author" ("id", "name")
13
+ select "root_"."id", "root_"."name"
14
+ from "root_"
15
+ returning "id"`,
16
+ parameters: [id, 'John'],
17
+ response: { rows: [{ id }] },
18
+ })
19
+
20
+ const selectAuthor = (id: string) => ({
21
+ sql: SQL`select "root_"."id" as "root_id"
22
+ from "public"."author" as "root_"
23
+ where "root_"."id" = ?`,
24
+ parameters: [id],
25
+ response: { rows: [{ root_id: id }] },
26
+ })
27
+
28
+ test('an exhausted memory budget fails every field of a mutation transaction', async () => {
29
+ const exhausted = {
30
+ ok: false,
31
+ errors: [{ type: 'ResourceExhausted', message: 'Request memory budget exceeded' }],
32
+ validation: { valid: true, errors: [] },
33
+ }
34
+ await execute({
35
+ schema: new SchemaBuilder()
36
+ .entity('Author', entity => entity.column('name', c => c.type(Model.ColumnType.String)))
37
+ .buildSchema(),
38
+ memoryBudget: new RequestMemoryBudget({ warnBytes: 200, maxBytes: 200 }),
39
+ query: GQL`
40
+ mutation {
41
+ transaction {
42
+ ok
43
+ errorMessage
44
+ errors { type message }
45
+ validation { valid errors { message { text } } }
46
+ first: createAuthor(data: {name: "John"}) { ok errors { type message } validation { valid errors { message { text } } } node { id } }
47
+ second: createAuthor(data: {name: "John"}) { ok errors { type message } validation { valid errors { message { text } } } node { id } }
48
+ }
49
+ }`,
50
+ executes: [
51
+ ...failedTransaction([insertAuthor(testUuid(1)), selectAuthor(testUuid(1)), insertAuthor(testUuid(2)), selectAuthor(testUuid(2))]),
52
+ ],
53
+ return: {
54
+ data: {
55
+ transaction: {
56
+ ...exhausted,
57
+ errorMessage: 'Request memory budget exceeded',
58
+ first: { ...exhausted, node: null },
59
+ second: { ...exhausted, node: null },
60
+ },
61
+ },
62
+ },
63
+ })
64
+ })
65
+
66
+ test('an exhausted memory budget fails its own mutation and keeps the committed sibling', async () => {
67
+ const exhausted = {
68
+ ok: false,
69
+ errors: [{ type: 'ResourceExhausted', message: 'Request memory budget exceeded' }],
70
+ node: null,
71
+ }
72
+ await execute({
73
+ schema: new SchemaBuilder()
74
+ .entity('Author', entity => entity.column('name', c => c.type(Model.ColumnType.String)))
75
+ .buildSchema(),
76
+ // One hydrated author is estimated at 112 bytes, so the second result node exceeds the budget.
77
+ memoryBudget: new RequestMemoryBudget({ warnBytes: 200, maxBytes: 200 }),
78
+ query: GQL`
79
+ mutation {
80
+ first: createAuthor(data: {name: "John"}) { ok errors { type message } node { id } }
81
+ second: createAuthor(data: {name: "John"}) { ok errors { type message } node { id } }
82
+ third: createAuthor(data: {name: "John"}) { ok errors { type message } node { id } }
83
+ }`,
84
+ executes: [
85
+ ...sqlTransaction([insertAuthor(testUuid(1)), selectAuthor(testUuid(1))]),
86
+ // Every transaction draws one uuid for its own id, so the second author gets the third one.
87
+ ...failedTransaction([insertAuthor(testUuid(3)), selectAuthor(testUuid(3))]),
88
+ ],
89
+ return: {
90
+ data: {
91
+ first: { ok: true, errors: [], node: { id: testUuid(1) } },
92
+ second: exhausted,
93
+ third: exhausted,
94
+ },
95
+ },
96
+ })
97
+ })
@@ -55,7 +55,8 @@ test('many has many with where, limit and orderBy', async () => {
55
55
  "data".*
56
56
  from "data"
57
57
  where
58
- "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?`,
58
+ "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
59
+ order by "data"."rowNumber_" asc`,
59
60
  parameters: [testUuid(1), testUuid(2), 'cs', 1, 3],
60
61
  response: {
61
62
  rows: [
@@ -173,7 +174,8 @@ test('one has many with where, limit and orderBy', async () => {
173
174
  order by "root_"."title" asc, "root_"."id" asc)
174
175
  select "data".*
175
176
  from "data"
176
- where "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?`,
177
+ where "data"."rowNumber_" > ? and "data"."rowNumber_" <= ?
178
+ order by "data"."rowNumber_" asc`,
177
179
  parameters: ['cs', testUuid(1), testUuid(2), 1, 3],
178
180
  response: {
179
181
  rows: [
@@ -216,3 +218,47 @@ test('one has many with where, limit and orderBy', async () => {
216
218
  },
217
219
  })
218
220
  })
221
+
222
+ test('one has many with nulls first in a limited page', async () => {
223
+ await execute({
224
+ schema: new SchemaBuilder()
225
+ .entity('Author', entity => entity.oneHasMany('posts', relation => relation.target('Post', entity => entity.column('title')).ownedBy('author')))
226
+ .buildSchema(),
227
+ query: GQL`
228
+ query {
229
+ listAuthor {
230
+ posts(orderBy: [{title: ascNullsFirst}], limit: 1) {
231
+ id
232
+ title
233
+ }
234
+ }
235
+ }`,
236
+ executes: [
237
+ {
238
+ sql: SQL`select "root_"."id" as "root_id", "root_"."id" as "root_id" from "public"."author" as "root_"`,
239
+ response: { rows: [{ root_id: testUuid(1) }] },
240
+ },
241
+ {
242
+ sql: SQL`with "data" as
243
+ (select "root_"."author_id" as "__grouping_key",
244
+ "root_"."id" as "root_id",
245
+ "root_"."title" as "root_title",
246
+ row_number() over(partition by "root_"."author_id"
247
+ order by "root_"."title" asc nulls first, "root_"."id" asc) as "rowNumber_"
248
+ from "public"."post" as "root_"
249
+ where "root_"."author_id" in (?)
250
+ order by "root_"."title" asc nulls first, "root_"."id" asc)
251
+ select "data".* from "data"
252
+ where "data"."rowNumber_" <= ?
253
+ order by "data"."rowNumber_" asc`,
254
+ parameters: [testUuid(1), 1],
255
+ response: { rows: [{ __grouping_key: testUuid(1), root_id: testUuid(2), root_title: null }] },
256
+ },
257
+ ],
258
+ return: {
259
+ data: {
260
+ listAuthor: [{ posts: [{ id: testUuid(2), title: null }] }],
261
+ },
262
+ },
263
+ })
264
+ })
@@ -221,7 +221,7 @@ test('Posts with paginated comments (one has many)', async () => {
221
221
  where "root_"."deleted_at" is null
222
222
  and "root_"."post_id" in (?, ?)
223
223
  order by "root_"."id" asc)
224
- select "data".* from "data" where "data"."rowNumber_" <= ?`,
224
+ select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
225
225
  parameters: [testUuid(1), testUuid(2), 1],
226
226
  response: {
227
227
  rows: [
@@ -375,7 +375,7 @@ test('Posts with paginated comments without count (one has many)', async () => {
375
375
  where "root_"."deleted_at" is null
376
376
  and "root_"."post_id" in (?, ?)
377
377
  order by "root_"."id" asc)
378
- select "data".* from "data" where "data"."rowNumber_" <= ?`,
378
+ select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
379
379
  parameters: [testUuid(1), testUuid(2), 1],
380
380
  response: {
381
381
  rows: [
@@ -471,7 +471,7 @@ test('Posts with paginated comments (one has many)', async () => {
471
471
  where "root_"."deleted_at" is null
472
472
  and "root_"."post_id" in (?)
473
473
  order by "root_"."id" asc)
474
- select "data".* from "data" where "data"."rowNumber_" <= ?`,
474
+ select "data".* from "data" where "data"."rowNumber_" <= ? order by "data"."rowNumber_" asc`,
475
475
  parameters: [testUuid(1), 1],
476
476
  response: {
477
477
  rows: [
@@ -136,7 +136,7 @@ test('sorts posts by random on has many relation', async () => {
136
136
  inner join "rand_seed" on true
137
137
  where "junction_"."category_id" in (?, ?)
138
138
  order by random() asc)
139
- select "data".* from "data" where "data"."rownumber_" <= ?`,
139
+ select "data".* from "data" where "data"."rownumber_" <= ? order by "data"."rownumber_" asc`,
140
140
  parameters: [4555 / Math.pow(2, 31), testUuid(1), testUuid(2), 1],
141
141
  response: {
142
142
  rows: [
@@ -351,6 +351,7 @@ enum _MutationErrorType {
351
351
  NonUniqueWhereInput
352
352
  InvalidDataInput
353
353
  SqlError
354
+ ResourceExhausted
354
355
  }
355
356
 
356
357
  type OneHasManyEntityDeleteResult implements MutationResult {
@@ -189,6 +189,7 @@ enum _MutationErrorType {
189
189
  NonUniqueWhereInput
190
190
  InvalidDataInput
191
191
  SqlError
192
+ ResourceExhausted
192
193
  }
193
194
 
194
195
  type CategoryCreateResult implements MutationResult {
@@ -274,6 +274,7 @@ enum _MutationErrorType {
274
274
  NonUniqueWhereInput
275
275
  InvalidDataInput
276
276
  SqlError
277
+ ResourceExhausted
277
278
  }
278
279
 
279
280
  type OneHasManyEntityUpdateResult implements MutationResult {
@@ -341,6 +341,7 @@ enum _MutationErrorType {
341
341
  NonUniqueWhereInput
342
342
  InvalidDataInput
343
343
  SqlError
344
+ ResourceExhausted
344
345
  }
345
346
 
346
347
  type OneHasManyEntityUpdateResult implements MutationResult {
@@ -286,6 +286,7 @@ enum _MutationErrorType {
286
286
  NonUniqueWhereInput
287
287
  InvalidDataInput
288
288
  SqlError
289
+ ResourceExhausted
289
290
  }
290
291
 
291
292
  type OneHasManyEntityDeleteResult implements MutationResult {
@@ -189,6 +189,7 @@ enum _MutationErrorType {
189
189
  NonUniqueWhereInput
190
190
  InvalidDataInput
191
191
  SqlError
192
+ ResourceExhausted
192
193
  }
193
194
 
194
195
  type TestUpdateResult implements MutationResult {
@@ -192,6 +192,7 @@ enum _MutationErrorType {
192
192
  NonUniqueWhereInput
193
193
  InvalidDataInput
194
194
  SqlError
195
+ ResourceExhausted
195
196
  }
196
197
 
197
198
  type AuthorDeleteResult implements MutationResult {
@@ -214,6 +214,7 @@ enum _MutationErrorType {
214
214
  NonUniqueWhereInput
215
215
  InvalidDataInput
216
216
  SqlError
217
+ ResourceExhausted
217
218
  }
218
219
 
219
220
  type FooDeleteResult implements MutationResult {
@@ -711,6 +711,7 @@ enum _MutationErrorType {
711
711
  NonUniqueWhereInput
712
712
  InvalidDataInput
713
713
  SqlError
714
+ ResourceExhausted
714
715
  }
715
716
 
716
717
  type AuthorDeleteResult implements MutationResult {
@@ -472,6 +472,7 @@ enum _MutationErrorType {
472
472
  NonUniqueWhereInput
473
473
  InvalidDataInput
474
474
  SqlError
475
+ ResourceExhausted
475
476
  }
476
477
 
477
478
  type VideoDeleteResult implements MutationResult {
@@ -380,6 +380,7 @@ enum _MutationErrorType {
380
380
  NonUniqueWhereInput
381
381
  InvalidDataInput
382
382
  SqlError
383
+ ResourceExhausted
383
384
  }
384
385
 
385
386
  type ColumnsDeleteResult implements MutationResult {
@@ -721,6 +721,7 @@ enum _MutationErrorType {
721
721
  NonUniqueWhereInput
722
722
  InvalidDataInput
723
723
  SqlError
724
+ ResourceExhausted
724
725
  }
725
726
 
726
727
  type AuthorDeleteResult implements MutationResult {
@@ -385,6 +385,7 @@ enum _MutationErrorType {
385
385
  NonUniqueWhereInput
386
386
  InvalidDataInput
387
387
  SqlError
388
+ ResourceExhausted
388
389
  }
389
390
 
390
391
  type PostLocaleDeleteResult implements MutationResult {
@@ -783,6 +783,7 @@ enum _MutationErrorType {
783
783
  NonUniqueWhereInput
784
784
  InvalidDataInput
785
785
  SqlError
786
+ ResourceExhausted
786
787
  }
787
788
 
788
789
  type AuthorDeleteResult implements MutationResult {
@@ -267,6 +267,7 @@ enum _MutationErrorType {
267
267
  NonUniqueWhereInput
268
268
  InvalidDataInput
269
269
  SqlError
270
+ ResourceExhausted
270
271
  }
271
272
 
272
273
  type ArticleDeleteResult implements MutationResult {
@@ -700,27 +700,13 @@ describe('predicates injector - multi-level back-reference', () => {
700
700
 
701
701
  it('should NOT simplify when filtering via non-ancestor relation', () => {
702
702
  // If we query Employee directly (not through Company->Department chain)
703
- // the predicate should NOT be simplified AND nested predicates should be applied
703
+ // the predicate should NOT be simplified — it is applied verbatim.
704
+ // Relation hops inside the predicate are the author's rule (as-definer semantics),
705
+ // so Department's/Company's own read predicates are NOT re-applied inside it.
704
706
  const injected = injector.inject(schema.model.entities.Employee, {})
705
707
 
706
- // Full predicate with nested entity predicates applied:
707
- // - Employee predicate: { department: { company: { isActive: true } } }
708
- // - Department predicate: { company: { isActive: true } } is added
709
- // - Company predicate: { isActive: true } is added inside company traversal
710
708
  assert.deepStrictEqual(injected, {
711
- department: {
712
- and: [
713
- {
714
- company: {
715
- and: [
716
- { isActive: { eq: true } }, // from Employee predicate
717
- { isActive: { eq: true } }, // Company's own predicate
718
- ],
719
- },
720
- },
721
- { company: { isActive: { eq: true } } }, // Department's predicate
722
- ],
723
- },
709
+ department: { company: { isActive: { eq: true } } },
724
710
  })
725
711
  })
726
712
 
@@ -864,21 +850,13 @@ describe('predicates injector - subsidiary edge case', () => {
864
850
  it('should correctly handle predicate when Company in predicate is NOT in path', () => {
865
851
  // Query Department directly (not through Company chain)
866
852
  // Department's predicate: { company: { isActive: true } }
867
- // Since we didn't traverse through Company, the predicate MUST be fully applied
868
- // AND Company's own predicate should also be applied
853
+ // Since we didn't traverse through Company, the predicate MUST be fully applied —
854
+ // verbatim, without re-applying Company's own predicate inside it (as-definer semantics)
869
855
 
870
856
  const injected = injector.inject(schema.model.entities.Department, {})
871
857
 
872
- // Full predicate with nested Company predicate:
873
- // - Department predicate: { company: { isActive: true } }
874
- // - Company predicate: { isActive: true } is also added when traversing company
875
858
  assert.deepStrictEqual(injected, {
876
- company: {
877
- and: [
878
- { isActive: { eq: true } }, // from Department predicate
879
- { isActive: { eq: true } }, // Company's own predicate
880
- ],
881
- },
859
+ company: { isActive: { eq: true } },
882
860
  })
883
861
  })
884
862
 
@@ -1012,8 +990,8 @@ describe('predicates injector - SECURITY: inconsistent predicates must NOT be si
1012
990
  // Company predicate: { isActive: true } - verified when querying Company
1013
991
  // Employee predicate: { department: { company: { name: 'Acme' } } } - checks DIFFERENT field!
1014
992
  //
1015
- // SECURITY: The name='Acme' condition MUST be preserved (not simplified).
1016
- // But Department and Company predicates CAN be simplified because we came through them.
993
+ // SECURITY: The name='Acme' condition MUST be preserved (not simplified) —
994
+ // Employee itself is not a back-reference, so its predicate is applied verbatim.
1017
995
 
1018
996
  const companyDepartmentsRelation = acceptFieldVisitor(schema.model, schema.model.entities.Company, 'departments', {
1019
997
  visitColumn: () => {
@@ -1032,50 +1010,20 @@ describe('predicates injector - SECURITY: inconsistent predicates must NOT be si
1032
1010
 
1033
1011
  const injected = injector.inject(schema.model.entities.Employee, {}, departmentEmployeesRelation, ancestorPath)
1034
1012
 
1035
- // The name='Acme' condition is preserved (not simplified)
1036
- // Department's predicate is simplified to { id: always } (we came from Department)
1037
- // Company's predicate is simplified to { id: always } (we came through Company)
1038
1013
  assert.deepStrictEqual(injected, {
1039
- department: {
1040
- and: [
1041
- {
1042
- company: {
1043
- and: [
1044
- { name: { eq: 'Acme' } },
1045
- { id: { always: true } }, // Company predicate simplified
1046
- ],
1047
- },
1048
- },
1049
- { id: { always: true } }, // Department predicate simplified
1050
- ],
1051
- },
1014
+ department: { company: { name: { eq: 'Acme' } } },
1052
1015
  })
1053
1016
  })
1054
1017
 
1055
- it('direct Employee query: ALL nested predicates MUST be applied (no ancestor path)', () => {
1056
- // Query Employee DIRECTLY (not through Company -> Department path)
1057
- // In this case, neither Company nor Department was verified at any parent level.
1058
- // So BOTH Department's and Company's predicates MUST be applied.
1018
+ it('direct Employee query: predicate is applied verbatim (as-definer, no nested re-application)', () => {
1019
+ // Query Employee DIRECTLY (not through Company -> Department path).
1020
+ // The predicate is the author's rule: its relation hops are NOT additionally
1021
+ // guarded by Department's/Company's own read predicates (as-definer semantics).
1059
1022
 
1060
1023
  const injected = injector.inject(schema.model.entities.Employee, {})
1061
1024
 
1062
- // Employee's condition (name='Acme') is preserved
1063
- // Department's predicate { company: { isActive: true } } is applied
1064
- // Company's predicate { isActive: true } is applied inside the traversal
1065
1025
  assert.deepStrictEqual(injected, {
1066
- department: {
1067
- and: [
1068
- {
1069
- company: {
1070
- and: [
1071
- { name: { eq: 'Acme' } },
1072
- { isActive: { eq: true } }, // Company predicate
1073
- ],
1074
- },
1075
- },
1076
- { company: { isActive: { eq: true } } }, // Department predicate
1077
- ],
1078
- },
1026
+ department: { company: { name: { eq: 'Acme' } } },
1079
1027
  })
1080
1028
  })
1081
1029
 
package/tests/src/test.ts CHANGED
@@ -2,7 +2,7 @@ import { Acl, Model, Schema, Settings, Validation } from '@contember/schema'
2
2
  import { Authorizator, ExecutionContainerFactory, GraphQlSchemaBuilderFactory } from '../../src/index.js'
3
3
  import { AllowAllPermissionFactory, emptySchema } from '@contember/schema-utils'
4
4
  import { executeGraphQlTest } from './testGraphql.js'
5
- import { Client, emptyDatabaseMetadata } from '@contember/database'
5
+ import { Client, emptyDatabaseMetadata, RequestMemoryBudget } from '@contember/database'
6
6
  import { createConnectionMock } from '@contember/database-tester'
7
7
  import { createUuidGenerator, testUuid } from './testUuid.js'
8
8
 
@@ -20,6 +20,7 @@ export interface Test {
20
20
  variables?: Acl.VariablesMap
21
21
  query: string
22
22
  queryVariables?: Record<string, any>
23
+ memoryBudget?: RequestMemoryBudget
23
24
  executes: SqlQuery[]
24
25
  return: object
25
26
  }
@@ -108,6 +109,7 @@ export const execute = async (test: Test) => {
108
109
  id: 1,
109
110
  },
110
111
  db,
112
+ memoryBudget: test.memoryBudget,
111
113
  identityVariables: test.variables || {},
112
114
  identityId: '00000000-0000-0000-0000-000000000000',
113
115
  systemSchema: 'system',