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

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 (273) hide show
  1. package/CLAUDE.md +12 -7
  2. package/dist/development/index.cjs +23 -0
  3. package/dist/development/index.cjs.map +1 -1
  4. package/dist/development/index.js +25 -2
  5. package/dist/development/index.js.map +1 -1
  6. package/dist/development/src/ExecutionContainer.cjs +4 -3
  7. package/dist/development/src/ExecutionContainer.cjs.map +1 -1
  8. package/dist/development/src/ExecutionContainer.js +4 -3
  9. package/dist/development/src/ExecutionContainer.js.map +1 -1
  10. package/dist/development/src/acl/Authorizator.cjs +6 -1
  11. package/dist/development/src/acl/Authorizator.cjs.map +1 -1
  12. package/dist/development/src/acl/Authorizator.js +6 -1
  13. package/dist/development/src/acl/Authorizator.js.map +1 -1
  14. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
  15. package/dist/development/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
  16. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
  17. package/dist/development/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
  18. package/dist/development/src/introspection/introspection.schema.cjs +2 -2
  19. package/dist/development/src/introspection/introspection.schema.cjs.map +1 -1
  20. package/dist/development/src/introspection/introspection.schema.js +2 -2
  21. package/dist/development/src/introspection/introspection.schema.js.map +1 -1
  22. package/dist/development/src/mapper/select/SelectHydrator.cjs +56 -15
  23. package/dist/development/src/mapper/select/SelectHydrator.cjs.map +1 -1
  24. package/dist/development/src/mapper/select/SelectHydrator.js +56 -15
  25. package/dist/development/src/mapper/select/SelectHydrator.js.map +1 -1
  26. package/dist/development/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  27. package/dist/development/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  28. package/dist/development/src/resolvers/MutationResolver.cjs +17 -39
  29. package/dist/development/src/resolvers/MutationResolver.cjs.map +1 -1
  30. package/dist/development/src/resolvers/MutationResolver.js +18 -40
  31. package/dist/development/src/resolvers/MutationResolver.js.map +1 -1
  32. package/dist/development/src/resolvers/ReadHelpers.cjs +4 -5
  33. package/dist/development/src/resolvers/ReadHelpers.cjs.map +1 -1
  34. package/dist/development/src/resolvers/ReadHelpers.js +4 -5
  35. package/dist/development/src/resolvers/ReadHelpers.js.map +1 -1
  36. package/dist/development/src/resolvers/ReadResolver.cjs +8 -17
  37. package/dist/development/src/resolvers/ReadResolver.cjs.map +1 -1
  38. package/dist/development/src/resolvers/ReadResolver.js +8 -17
  39. package/dist/development/src/resolvers/ReadResolver.js.map +1 -1
  40. package/dist/development/src/schema/GraphQlSchemaBuilder.cjs +16 -6
  41. package/dist/development/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  42. package/dist/development/src/schema/GraphQlSchemaBuilder.js +16 -6
  43. package/dist/development/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  44. package/dist/development/src/schema/MutationProvider.cjs +21 -8
  45. package/dist/development/src/schema/MutationProvider.cjs.map +1 -1
  46. package/dist/development/src/schema/MutationProvider.js +21 -8
  47. package/dist/development/src/schema/MutationProvider.js.map +1 -1
  48. package/dist/development/src/schema/QueryProvider.cjs +6 -6
  49. package/dist/development/src/schema/QueryProvider.cjs.map +1 -1
  50. package/dist/development/src/schema/QueryProvider.js +6 -6
  51. package/dist/development/src/schema/QueryProvider.js.map +1 -1
  52. package/dist/development/src/schema-json/GraphQLJsBridge.cjs +108 -0
  53. package/dist/development/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
  54. package/dist/development/src/schema-json/GraphQLJsBridge.js +108 -0
  55. package/dist/development/src/schema-json/GraphQLJsBridge.js.map +1 -0
  56. package/dist/development/src/schema-json/JsonColumnTypes.cjs +102 -0
  57. package/dist/development/src/schema-json/JsonColumnTypes.cjs.map +1 -0
  58. package/dist/development/src/schema-json/JsonColumnTypes.js +102 -0
  59. package/dist/development/src/schema-json/JsonColumnTypes.js.map +1 -0
  60. package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
  61. package/dist/development/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
  62. package/dist/development/src/schema-json/JsonContentSchemaBuilder.js +418 -0
  63. package/dist/development/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
  64. package/dist/development/src/schema-json/JsonContentSchemaShared.cjs +18 -0
  65. package/dist/development/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
  66. package/dist/development/src/schema-json/JsonContentSchemaShared.js +18 -0
  67. package/dist/development/src/schema-json/JsonContentSchemaShared.js.map +1 -0
  68. package/dist/development/src/schema-json/JsonEntityTypes.cjs +206 -0
  69. package/dist/development/src/schema-json/JsonEntityTypes.cjs.map +1 -0
  70. package/dist/development/src/schema-json/JsonEntityTypes.js +206 -0
  71. package/dist/development/src/schema-json/JsonEntityTypes.js.map +1 -0
  72. package/dist/development/src/schema-json/JsonFilterTypes.cjs +152 -0
  73. package/dist/development/src/schema-json/JsonFilterTypes.cjs.map +1 -0
  74. package/dist/development/src/schema-json/JsonFilterTypes.js +152 -0
  75. package/dist/development/src/schema-json/JsonFilterTypes.js.map +1 -0
  76. package/dist/development/src/schema-json/JsonInputTypes.cjs +256 -0
  77. package/dist/development/src/schema-json/JsonInputTypes.cjs.map +1 -0
  78. package/dist/development/src/schema-json/JsonInputTypes.js +256 -0
  79. package/dist/development/src/schema-json/JsonInputTypes.js.map +1 -0
  80. package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
  81. package/dist/development/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
  82. package/dist/development/src/schema-json/JsonIntrospectionExtension.js +36 -0
  83. package/dist/development/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
  84. package/dist/development/src/schema-json/JsonQueryAstFactory.cjs +107 -0
  85. package/dist/development/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
  86. package/dist/development/src/schema-json/JsonQueryAstFactory.js +107 -0
  87. package/dist/development/src/schema-json/JsonQueryAstFactory.js.map +1 -0
  88. package/dist/development/src/schema-json/JsonTypeRegistry.cjs +230 -0
  89. package/dist/development/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
  90. package/dist/development/src/schema-json/JsonTypeRegistry.js +230 -0
  91. package/dist/development/src/schema-json/JsonTypeRegistry.js.map +1 -0
  92. package/dist/development/src/utils/ResolveInfoUtils.cjs.map +1 -1
  93. package/dist/development/src/utils/ResolveInfoUtils.js.map +1 -1
  94. package/dist/development/src/utils/uniqueWhereFields.cjs +10 -0
  95. package/dist/development/src/utils/uniqueWhereFields.cjs.map +1 -1
  96. package/dist/development/src/utils/uniqueWhereFields.js +10 -0
  97. package/dist/development/src/utils/uniqueWhereFields.js.map +1 -1
  98. package/dist/production/index.cjs +23 -0
  99. package/dist/production/index.cjs.map +1 -1
  100. package/dist/production/index.js +25 -2
  101. package/dist/production/index.js.map +1 -1
  102. package/dist/production/src/ExecutionContainer.cjs +4 -3
  103. package/dist/production/src/ExecutionContainer.cjs.map +1 -1
  104. package/dist/production/src/ExecutionContainer.js +4 -3
  105. package/dist/production/src/ExecutionContainer.js.map +1 -1
  106. package/dist/production/src/acl/Authorizator.cjs +6 -1
  107. package/dist/production/src/acl/Authorizator.cjs.map +1 -1
  108. package/dist/production/src/acl/Authorizator.js +6 -1
  109. package/dist/production/src/acl/Authorizator.js.map +1 -1
  110. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.cjs +1 -1
  111. package/dist/production/src/extensions/hasManyToHasOneReducer/HasManyToHasOneRelationReducerVisitor.js +1 -1
  112. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.cjs +1 -1
  113. package/dist/production/src/extensions/paginatedHasMany/PaginatedHasManyFieldProviderVisitor.js +1 -1
  114. package/dist/production/src/introspection/introspection.schema.cjs +2 -2
  115. package/dist/production/src/introspection/introspection.schema.cjs.map +1 -1
  116. package/dist/production/src/introspection/introspection.schema.js +2 -2
  117. package/dist/production/src/introspection/introspection.schema.js.map +1 -1
  118. package/dist/production/src/mapper/select/SelectHydrator.cjs +56 -15
  119. package/dist/production/src/mapper/select/SelectHydrator.cjs.map +1 -1
  120. package/dist/production/src/mapper/select/SelectHydrator.js +56 -15
  121. package/dist/production/src/mapper/select/SelectHydrator.js.map +1 -1
  122. package/dist/production/src/resolvers/GraphQlQueryAstFactory.cjs.map +1 -1
  123. package/dist/production/src/resolvers/GraphQlQueryAstFactory.js.map +1 -1
  124. package/dist/production/src/resolvers/MutationResolver.cjs +17 -39
  125. package/dist/production/src/resolvers/MutationResolver.cjs.map +1 -1
  126. package/dist/production/src/resolvers/MutationResolver.js +18 -40
  127. package/dist/production/src/resolvers/MutationResolver.js.map +1 -1
  128. package/dist/production/src/resolvers/ReadHelpers.cjs +4 -5
  129. package/dist/production/src/resolvers/ReadHelpers.cjs.map +1 -1
  130. package/dist/production/src/resolvers/ReadHelpers.js +4 -5
  131. package/dist/production/src/resolvers/ReadHelpers.js.map +1 -1
  132. package/dist/production/src/resolvers/ReadResolver.cjs +8 -17
  133. package/dist/production/src/resolvers/ReadResolver.cjs.map +1 -1
  134. package/dist/production/src/resolvers/ReadResolver.js +8 -17
  135. package/dist/production/src/resolvers/ReadResolver.js.map +1 -1
  136. package/dist/production/src/schema/GraphQlSchemaBuilder.cjs +16 -6
  137. package/dist/production/src/schema/GraphQlSchemaBuilder.cjs.map +1 -1
  138. package/dist/production/src/schema/GraphQlSchemaBuilder.js +16 -6
  139. package/dist/production/src/schema/GraphQlSchemaBuilder.js.map +1 -1
  140. package/dist/production/src/schema/MutationProvider.cjs +21 -8
  141. package/dist/production/src/schema/MutationProvider.cjs.map +1 -1
  142. package/dist/production/src/schema/MutationProvider.js +21 -8
  143. package/dist/production/src/schema/MutationProvider.js.map +1 -1
  144. package/dist/production/src/schema/QueryProvider.cjs +6 -6
  145. package/dist/production/src/schema/QueryProvider.cjs.map +1 -1
  146. package/dist/production/src/schema/QueryProvider.js +6 -6
  147. package/dist/production/src/schema/QueryProvider.js.map +1 -1
  148. package/dist/production/src/schema-json/GraphQLJsBridge.cjs +108 -0
  149. package/dist/production/src/schema-json/GraphQLJsBridge.cjs.map +1 -0
  150. package/dist/production/src/schema-json/GraphQLJsBridge.js +108 -0
  151. package/dist/production/src/schema-json/GraphQLJsBridge.js.map +1 -0
  152. package/dist/production/src/schema-json/JsonColumnTypes.cjs +102 -0
  153. package/dist/production/src/schema-json/JsonColumnTypes.cjs.map +1 -0
  154. package/dist/production/src/schema-json/JsonColumnTypes.js +102 -0
  155. package/dist/production/src/schema-json/JsonColumnTypes.js.map +1 -0
  156. package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs +418 -0
  157. package/dist/production/src/schema-json/JsonContentSchemaBuilder.cjs.map +1 -0
  158. package/dist/production/src/schema-json/JsonContentSchemaBuilder.js +418 -0
  159. package/dist/production/src/schema-json/JsonContentSchemaBuilder.js.map +1 -0
  160. package/dist/production/src/schema-json/JsonContentSchemaShared.cjs +18 -0
  161. package/dist/production/src/schema-json/JsonContentSchemaShared.cjs.map +1 -0
  162. package/dist/production/src/schema-json/JsonContentSchemaShared.js +18 -0
  163. package/dist/production/src/schema-json/JsonContentSchemaShared.js.map +1 -0
  164. package/dist/production/src/schema-json/JsonEntityTypes.cjs +206 -0
  165. package/dist/production/src/schema-json/JsonEntityTypes.cjs.map +1 -0
  166. package/dist/production/src/schema-json/JsonEntityTypes.js +206 -0
  167. package/dist/production/src/schema-json/JsonEntityTypes.js.map +1 -0
  168. package/dist/production/src/schema-json/JsonFilterTypes.cjs +152 -0
  169. package/dist/production/src/schema-json/JsonFilterTypes.cjs.map +1 -0
  170. package/dist/production/src/schema-json/JsonFilterTypes.js +152 -0
  171. package/dist/production/src/schema-json/JsonFilterTypes.js.map +1 -0
  172. package/dist/production/src/schema-json/JsonInputTypes.cjs +256 -0
  173. package/dist/production/src/schema-json/JsonInputTypes.cjs.map +1 -0
  174. package/dist/production/src/schema-json/JsonInputTypes.js +256 -0
  175. package/dist/production/src/schema-json/JsonInputTypes.js.map +1 -0
  176. package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs +36 -0
  177. package/dist/production/src/schema-json/JsonIntrospectionExtension.cjs.map +1 -0
  178. package/dist/production/src/schema-json/JsonIntrospectionExtension.js +36 -0
  179. package/dist/production/src/schema-json/JsonIntrospectionExtension.js.map +1 -0
  180. package/dist/production/src/schema-json/JsonQueryAstFactory.cjs +107 -0
  181. package/dist/production/src/schema-json/JsonQueryAstFactory.cjs.map +1 -0
  182. package/dist/production/src/schema-json/JsonQueryAstFactory.js +107 -0
  183. package/dist/production/src/schema-json/JsonQueryAstFactory.js.map +1 -0
  184. package/dist/production/src/schema-json/JsonTypeRegistry.cjs +230 -0
  185. package/dist/production/src/schema-json/JsonTypeRegistry.cjs.map +1 -0
  186. package/dist/production/src/schema-json/JsonTypeRegistry.js +230 -0
  187. package/dist/production/src/schema-json/JsonTypeRegistry.js.map +1 -0
  188. package/dist/production/src/utils/ResolveInfoUtils.cjs.map +1 -1
  189. package/dist/production/src/utils/ResolveInfoUtils.js.map +1 -1
  190. package/dist/production/src/utils/uniqueWhereFields.cjs +10 -0
  191. package/dist/production/src/utils/uniqueWhereFields.cjs.map +1 -1
  192. package/dist/production/src/utils/uniqueWhereFields.js +10 -0
  193. package/dist/production/src/utils/uniqueWhereFields.js.map +1 -1
  194. package/dist/tests/src/test.d.ts +10 -2
  195. package/dist/tests/src/test.d.ts.map +1 -1
  196. package/dist/tests/src/testGraphql.d.ts +18 -5
  197. package/dist/tests/src/testGraphql.d.ts.map +1 -1
  198. package/dist/tests/tsconfig.tsbuildinfo +1 -1
  199. package/dist/types/ExecutionContainer.d.ts +1 -0
  200. package/dist/types/ExecutionContainer.d.ts.map +1 -1
  201. package/dist/types/acl/Authorizator.d.ts.map +1 -1
  202. package/dist/types/index.d.ts +1 -0
  203. package/dist/types/index.d.ts.map +1 -1
  204. package/dist/types/mapper/select/SelectHydrator.d.ts +4 -1
  205. package/dist/types/mapper/select/SelectHydrator.d.ts.map +1 -1
  206. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts +4 -3
  207. package/dist/types/resolvers/GraphQlQueryAstFactory.d.ts.map +1 -1
  208. package/dist/types/resolvers/MutationResolver.d.ts +14 -11
  209. package/dist/types/resolvers/MutationResolver.d.ts.map +1 -1
  210. package/dist/types/resolvers/ReadHelpers.d.ts +1 -2
  211. package/dist/types/resolvers/ReadHelpers.d.ts.map +1 -1
  212. package/dist/types/resolvers/ReadResolver.d.ts +8 -10
  213. package/dist/types/resolvers/ReadResolver.d.ts.map +1 -1
  214. package/dist/types/schema/GraphQlSchemaBuilder.d.ts.map +1 -1
  215. package/dist/types/schema/MutationProvider.d.ts.map +1 -1
  216. package/dist/types/schema-json/GraphQLJsBridge.d.ts +12 -0
  217. package/dist/types/schema-json/GraphQLJsBridge.d.ts.map +1 -0
  218. package/dist/types/schema-json/JsonColumnTypes.d.ts +23 -0
  219. package/dist/types/schema-json/JsonColumnTypes.d.ts.map +1 -0
  220. package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts +56 -0
  221. package/dist/types/schema-json/JsonContentSchemaBuilder.d.ts.map +1 -0
  222. package/dist/types/schema-json/JsonContentSchemaShared.d.ts +19 -0
  223. package/dist/types/schema-json/JsonContentSchemaShared.d.ts.map +1 -0
  224. package/dist/types/schema-json/JsonEntityTypes.d.ts +29 -0
  225. package/dist/types/schema-json/JsonEntityTypes.d.ts.map +1 -0
  226. package/dist/types/schema-json/JsonFilterTypes.d.ts +21 -0
  227. package/dist/types/schema-json/JsonFilterTypes.d.ts.map +1 -0
  228. package/dist/types/schema-json/JsonInputTypes.d.ts +36 -0
  229. package/dist/types/schema-json/JsonInputTypes.d.ts.map +1 -0
  230. package/dist/types/schema-json/JsonIntrospectionExtension.d.ts +5 -0
  231. package/dist/types/schema-json/JsonIntrospectionExtension.d.ts.map +1 -0
  232. package/dist/types/schema-json/JsonQueryAstFactory.d.ts +18 -0
  233. package/dist/types/schema-json/JsonQueryAstFactory.d.ts.map +1 -0
  234. package/dist/types/schema-json/JsonTypeRegistry.d.ts +57 -0
  235. package/dist/types/schema-json/JsonTypeRegistry.d.ts.map +1 -0
  236. package/dist/types/schema-json/index.d.ts +7 -0
  237. package/dist/types/schema-json/index.d.ts.map +1 -0
  238. package/dist/types/tsconfig.tsbuildinfo +1 -1
  239. package/dist/types/utils/ResolveInfoUtils.d.ts +4 -2
  240. package/dist/types/utils/ResolveInfoUtils.d.ts.map +1 -1
  241. package/dist/types/utils/uniqueWhereFields.d.ts.map +1 -1
  242. package/package.json +11 -10
  243. package/src/ExecutionContainer.ts +5 -3
  244. package/src/acl/Authorizator.ts +7 -1
  245. package/src/index.ts +1 -0
  246. package/src/mapper/select/SelectHydrator.ts +72 -17
  247. package/src/resolvers/GraphQlQueryAstFactory.ts +2 -2
  248. package/src/resolvers/MutationResolver.ts +22 -45
  249. package/src/resolvers/ReadHelpers.ts +1 -4
  250. package/src/resolvers/ReadResolver.ts +7 -18
  251. package/src/schema/GraphQlSchemaBuilder.ts +18 -7
  252. package/src/schema/MutationProvider.ts +21 -8
  253. package/src/schema/QueryProvider.ts +6 -6
  254. package/src/schema-json/GraphQLJsBridge.ts +142 -0
  255. package/src/schema-json/JsonColumnTypes.ts +116 -0
  256. package/src/schema-json/JsonContentSchemaBuilder.ts +501 -0
  257. package/src/schema-json/JsonContentSchemaShared.ts +19 -0
  258. package/src/schema-json/JsonEntityTypes.ts +237 -0
  259. package/src/schema-json/JsonFilterTypes.ts +159 -0
  260. package/src/schema-json/JsonInputTypes.ts +305 -0
  261. package/src/schema-json/JsonIntrospectionExtension.ts +37 -0
  262. package/src/schema-json/JsonQueryAstFactory.ts +128 -0
  263. package/src/schema-json/JsonTypeRegistry.ts +286 -0
  264. package/src/schema-json/index.ts +6 -0
  265. package/src/tsconfig.json +1 -0
  266. package/src/utils/ResolveInfoUtils.ts +2 -2
  267. package/src/utils/uniqueWhereFields.ts +14 -0
  268. package/tests/cases/integration/graphQlRequests/insert/memoryBudget.test.ts +2 -3
  269. package/tests/cases/integration/graphQlRequests/query/graphqlFeatures/alias.test.ts +44 -1
  270. package/tests/cases/integration/graphQlSchema/graphQlSchemaBuilder.test.ts +25 -29
  271. package/tests/src/test.ts +44 -10
  272. package/tests/src/testGraphql.ts +43 -20
  273. package/tests/tsconfig.json +1 -0
@@ -0,0 +1,305 @@
1
+ import { Acl, Input, Model } from '@contember/schema'
2
+ import { acceptFieldVisitor, getEntity } from '@contember/schema-utils'
3
+ import { InputField } from '@contember/graphql-json'
4
+ import { Authorizator } from '../acl/index.js'
5
+ import { GqlTypeName, inputFieldDescription } from '../schema/utils.js'
6
+ import {
7
+ CreateEntityRelationAllowedOperationsVisitor,
8
+ EntityInputType,
9
+ UpdateEntityRelationAllowedOperationsVisitor,
10
+ } from '../schema/mutations/index.js'
11
+ import { ImplementationException } from '../exception.js'
12
+ import { JsonColumnTypes } from './JsonColumnTypes.js'
13
+ import { JsonFilterTypes } from './JsonFilterTypes.js'
14
+ import { inputField, JsonTypeRegistry, listOfNonNullRef, namedRef, nonNullRef } from './JsonTypeRegistry.js'
15
+
16
+ /** JSON counterpart of `EntityInputProvider` and the create/update input visitors in `schema/mutations`. */
17
+ export class JsonInputTypes {
18
+ private readonly createAllowedOperationsVisitor: CreateEntityRelationAllowedOperationsVisitor
19
+ private readonly updateAllowedOperationsVisitor: UpdateEntityRelationAllowedOperationsVisitor
20
+ /**
21
+ * Inputs by their arguments. Every `Without<relation>` variant of an input asks again for the relation inputs of
22
+ * its fields, and every relation input for the inputs of its target; on real models that repeated work dominated.
23
+ */
24
+ private readonly inputs = new Map<string, string | undefined>()
25
+ private readonly relationInputs = new Map<string, string | undefined>()
26
+
27
+ constructor(
28
+ private readonly schema: Model.Schema,
29
+ private readonly authorizator: Authorizator,
30
+ private readonly registry: JsonTypeRegistry,
31
+ private readonly columnTypes: JsonColumnTypes,
32
+ private readonly filterTypes: JsonFilterTypes,
33
+ ) {
34
+ this.createAllowedOperationsVisitor = new CreateEntityRelationAllowedOperationsVisitor(authorizator)
35
+ this.updateAllowedOperationsVisitor = new UpdateEntityRelationAllowedOperationsVisitor(authorizator)
36
+ }
37
+
38
+ public getInput(operation: EntityInputType, entityName: string, withoutRelation?: string): string | undefined {
39
+ const key = `${operation}\0${entityName}\0${withoutRelation ?? ''}`
40
+ if (this.inputs.has(key)) {
41
+ return this.inputs.get(key)
42
+ }
43
+ const input = this.createInput(operation, entityName, withoutRelation)
44
+ this.inputs.set(key, input)
45
+ return input
46
+ }
47
+
48
+ private createInput(operation: EntityInputType, entityName: string, withoutRelation: string | undefined): string | undefined {
49
+ const entity = getEntity(this.schema, entityName)
50
+ if (entity.view) {
51
+ return undefined
52
+ }
53
+ const aclOperation = operation === EntityInputType.create ? Acl.Operation.create : Acl.Operation.update
54
+ if (this.authorizator.getEntityPermission(aclOperation, entity.name) === 'no') {
55
+ return undefined
56
+ }
57
+ const withoutSuffix = withoutRelation ? GqlTypeName`Without${withoutRelation}` : ''
58
+ const name = GqlTypeName`${entityName}${withoutSuffix}${operation}Input`
59
+ return this.registry.inputObject(name, () => {
60
+ const fields: Record<string, InputField> = {}
61
+ for (const fieldName of Object.keys(entity.fields)) {
62
+ if (fieldName === withoutRelation) {
63
+ continue
64
+ }
65
+ const field = operation === EntityInputType.create
66
+ ? this.getCreateField(entity, fieldName)
67
+ : this.getUpdateField(entity, fieldName)
68
+ if (field !== undefined) {
69
+ fields[fieldName] = field
70
+ }
71
+ }
72
+ fields['_dummy_field_'] = [namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool))]
73
+ return fields
74
+ })
75
+ }
76
+
77
+ private getCreateField(entity: Model.Entity, fieldName: string): InputField | undefined {
78
+ return acceptFieldVisitor<InputField | undefined>(this.schema, entity, fieldName, {
79
+ visitColumn: ({ column }) => {
80
+ if (entity.primary === column.name && !this.authorizator.isCustomPrimaryAllowed(entity.name)) {
81
+ return undefined
82
+ }
83
+ if (this.authorizator.getFieldPermissions(Acl.Operation.create, entity.name, column.name) === 'no') {
84
+ return undefined
85
+ }
86
+ return inputField(this.columnTypes.getType(column).type, inputFieldDescription(column))
87
+ },
88
+ visitHasOne: context => {
89
+ const type = this.memoizeRelationInput('create', context, () => this.getCreateRelationInput(context, false))
90
+ return type === undefined ? undefined : inputField(namedRef(type), inputFieldDescription(context.relation))
91
+ },
92
+ visitHasMany: context => {
93
+ const type = this.memoizeRelationInput('create', context, () => this.getCreateRelationInput(context, true))
94
+ return type === undefined ? undefined : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation))
95
+ },
96
+ })
97
+ }
98
+
99
+ private getUpdateField(entity: Model.Entity, fieldName: string): InputField | undefined {
100
+ return acceptFieldVisitor<InputField | undefined>(this.schema, entity, fieldName, {
101
+ visitColumn: ({ column }) => {
102
+ if (entity.primary === column.name) {
103
+ return undefined
104
+ }
105
+ if (this.authorizator.getFieldPermissions(Acl.Operation.update, entity.name, column.name) === 'no') {
106
+ return undefined
107
+ }
108
+ return inputField(this.columnTypes.getType(column).type, inputFieldDescription(column))
109
+ },
110
+ visitHasOne: context => {
111
+ const type = this.memoizeRelationInput('update', context, () => this.getUpdateHasOneRelationInput(context))
112
+ return type === undefined ? undefined : inputField(namedRef(type), inputFieldDescription(context.relation))
113
+ },
114
+ visitHasMany: context => {
115
+ const type = this.memoizeRelationInput('update', context, () => this.getUpdateHasManyRelationInput(context))
116
+ return type === undefined ? undefined : inputField(listOfNonNullRef(type), inputFieldDescription(context.relation))
117
+ },
118
+ })
119
+ }
120
+
121
+ private memoizeRelationInput(
122
+ operation: 'create' | 'update',
123
+ { entity, relation }: Model.AnyRelationContext,
124
+ create: () => string | undefined,
125
+ ): string | undefined {
126
+ const key = `${operation}\0${entity.name}\0${relation.name}`
127
+ if (this.relationInputs.has(key)) {
128
+ return this.relationInputs.get(key)
129
+ }
130
+ const input = create()
131
+ this.relationInputs.set(key, input)
132
+ return input
133
+ }
134
+
135
+ private getCreateRelationInput(
136
+ { entity, relation, targetEntity, targetRelation }: Model.AnyRelationContext,
137
+ withAliasField: boolean,
138
+ ): string | undefined {
139
+ const allowedOperations = acceptFieldVisitor(this.schema, entity, relation.name, this.createAllowedOperationsVisitor)
140
+ const fields: Record<string, InputField> = {}
141
+
142
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)
143
+ if (allowedOperations.includes(Input.CreateRelationOperation.connect) && uniqueWhere) {
144
+ fields[Input.CreateRelationOperation.connect] = [namedRef(uniqueWhere)]
145
+ }
146
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name)
147
+ if (allowedOperations.includes(Input.CreateRelationOperation.create) && createInput !== undefined) {
148
+ fields[Input.CreateRelationOperation.create] = [namedRef(createInput)]
149
+ }
150
+ if (allowedOperations.includes(Input.CreateRelationOperation.connectOrCreate) && uniqueWhere !== undefined && createInput !== undefined) {
151
+ fields[Input.CreateRelationOperation.connectOrCreate] = [namedRef(this.getConnectOrCreateInput(entity, relation.name))]
152
+ }
153
+ if (Object.keys(fields).length === 0) {
154
+ return undefined
155
+ }
156
+ if (withAliasField) {
157
+ fields.alias = [namedRef(this.columnTypes.getScalar(Model.ColumnType.String))]
158
+ }
159
+ return this.registry.inputObject(GqlTypeName`${entity.name}Create${relation.name}EntityRelationInput`, () => fields)
160
+ }
161
+
162
+ private getUpdateHasOneRelationInput({ targetRelation, targetEntity, relation, entity }: Model.AnyHasOneRelationContext): string | undefined {
163
+ const withoutRelation = targetRelation ? targetRelation.name : undefined
164
+ const whereInput = this.getUniqueWhereInput(targetEntity)
165
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation)
166
+ const updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation)
167
+ const boolean = namedRef(this.columnTypes.getScalar(Model.ColumnType.Bool))
168
+
169
+ const fields = this.filterAllowedOperations(entity, relation, {
170
+ [Input.UpdateRelationOperation.connect]: whereInput ? [namedRef(whereInput)] : undefined,
171
+ [Input.UpdateRelationOperation.create]: createInput ? [namedRef(createInput)] : undefined,
172
+ [Input.UpdateRelationOperation.connectOrCreate]: createInput && whereInput
173
+ ? [namedRef(this.getConnectOrCreateInput(entity, relation.name))]
174
+ : undefined,
175
+ [Input.UpdateRelationOperation.update]: updateInput ? [namedRef(updateInput)] : undefined,
176
+ [Input.UpdateRelationOperation.upsert]: updateInput && createInput
177
+ ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({
178
+ update: [nonNullRef(updateInput)],
179
+ create: [nonNullRef(createInput)],
180
+ })))]
181
+ : undefined,
182
+ [Input.UpdateRelationOperation.disconnect]: [boolean],
183
+ [Input.UpdateRelationOperation.delete]: [boolean],
184
+ })
185
+ if (Object.keys(fields).length === 0) {
186
+ return undefined
187
+ }
188
+ return this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields)
189
+ }
190
+
191
+ private getUpdateHasManyRelationInput({ entity, relation, targetEntity, targetRelation }: Model.AnyHasManyRelationContext): string | undefined {
192
+ const withoutRelation = targetRelation ? targetRelation.name : undefined
193
+ const whereInput = this.getUniqueWhereInput(targetEntity)
194
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, withoutRelation)
195
+ const updateInput = this.getInput(EntityInputType.update, targetEntity.name, withoutRelation)
196
+
197
+ const create: InputField | undefined = createInput ? [namedRef(createInput)] : undefined
198
+ const update: InputField | undefined = updateInput && whereInput
199
+ ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}RelationInput`, () => ({
200
+ by: [nonNullRef(whereInput)],
201
+ data: [nonNullRef(updateInput)],
202
+ })))]
203
+ : undefined
204
+ const upsert: InputField | undefined = updateInput && createInput && whereInput
205
+ ? [namedRef(this.registry.inputObject(GqlTypeName`${entity.name}Upsert${relation.name}RelationInput`, () => ({
206
+ by: [nonNullRef(whereInput)],
207
+ update: [nonNullRef(updateInput)],
208
+ create: [nonNullRef(createInput)],
209
+ })))]
210
+ : undefined
211
+ const connect: InputField | undefined = whereInput ? [namedRef(whereInput)] : undefined
212
+ const connectOrCreate: InputField | undefined = createInput && whereInput
213
+ ? [namedRef(this.getConnectOrCreateInput(entity, relation.name))]
214
+ : undefined
215
+
216
+ const fields = this.filterAllowedOperations(entity, relation, {
217
+ [Input.UpdateRelationOperation.create]: create,
218
+ [Input.UpdateRelationOperation.update]: update,
219
+ [Input.UpdateRelationOperation.upsert]: upsert,
220
+ [Input.UpdateRelationOperation.connect]: connect,
221
+ [Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,
222
+ [Input.UpdateRelationOperation.disconnect]: connect,
223
+ [Input.UpdateRelationOperation.delete]: connect,
224
+ })
225
+ if (Object.keys(fields).length === 0) {
226
+ return undefined
227
+ }
228
+ const string = namedRef(this.columnTypes.getScalar(Model.ColumnType.String))
229
+
230
+ // `set` replaces the whole collection with the positive operations; orphans are removed via `orphanStrategy`.
231
+ const setItemFields = this.filterAllowedOperations(entity, relation, {
232
+ [Input.UpdateRelationOperation.create]: create,
233
+ [Input.UpdateRelationOperation.connect]: connect,
234
+ [Input.UpdateRelationOperation.connectOrCreate]: connectOrCreate,
235
+ [Input.UpdateRelationOperation.update]: update,
236
+ [Input.UpdateRelationOperation.upsert]: upsert,
237
+ })
238
+ // Orphans are found by diffing the current members read through the target's read predicate, so a role that
239
+ // cannot read the target would see an empty collection and `set` could only add: it is not offered at all.
240
+ const canReadTarget = this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) !== 'no'
241
+ if (canReadTarget && Object.keys(setItemFields).length > 0) {
242
+ const setItem = this.registry.inputObject(GqlTypeName`${entity.name}Set${relation.name}ItemRelationInput`, () => ({
243
+ ...setItemFields,
244
+ alias: [string],
245
+ }))
246
+ fields[Input.UpdateRelationOperation.set] = [listOfNonNullRef(setItem)]
247
+ // only offered when the role may delete the target, `disconnect` is the default
248
+ if (this.getAllowedOperations(entity, relation).includes(Input.UpdateRelationOperation.delete)) {
249
+ const strategies = [Input.OrphanRemovalStrategy.disconnect, Input.OrphanRemovalStrategy.delete]
250
+ fields.orphanStrategy = [namedRef(this.registry.enum('OrphanRemovalStrategy', strategies))]
251
+ }
252
+ }
253
+ fields.alias = [string]
254
+ return this.registry.inputObject(GqlTypeName`${entity.name}Update${relation.name}EntityRelationInput`, () => fields)
255
+ }
256
+
257
+ private getConnectOrCreateInput(entity: Model.Entity, relationName: string): string {
258
+ return acceptFieldVisitor<string>(this.schema, entity, relationName, {
259
+ visitColumn: () => {
260
+ throw new ImplementationException()
261
+ },
262
+ visitRelation: ({ targetEntity, targetRelation, relation }) => {
263
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)
264
+ const createInput = this.getInput(EntityInputType.create, targetEntity.name, targetRelation?.name)
265
+ if (!uniqueWhere || !createInput) {
266
+ throw new ImplementationException()
267
+ }
268
+ return this.registry.inputObject(GqlTypeName`${entity.name}ConnectOrCreate${relation.name}RelationInput`, () => ({
269
+ connect: [nonNullRef(uniqueWhere)],
270
+ create: [nonNullRef(createInput)],
271
+ }))
272
+ },
273
+ })
274
+ }
275
+
276
+ private getUniqueWhereInput(targetEntity: Model.Entity): string | undefined {
277
+ if (this.authorizator.getEntityPermission(Acl.Operation.read, targetEntity.name) === 'no') {
278
+ return undefined
279
+ }
280
+ const uniqueWhere = this.filterTypes.getEntityUniqueWhereType(targetEntity.name)
281
+ if (!uniqueWhere) {
282
+ throw new ImplementationException()
283
+ }
284
+ return uniqueWhere
285
+ }
286
+
287
+ private getAllowedOperations(entity: Model.Entity, relation: Model.Relation): readonly Input.UpdateRelationOperation[] {
288
+ return acceptFieldVisitor(this.schema, entity, relation.name, this.updateAllowedOperationsVisitor)
289
+ }
290
+
291
+ private filterAllowedOperations(
292
+ entity: Model.Entity,
293
+ relation: Model.Relation,
294
+ fields: Record<string, InputField | undefined>,
295
+ ): Record<string, InputField> {
296
+ const allowedOperations: readonly string[] = this.getAllowedOperations(entity, relation)
297
+ const result: Record<string, InputField> = {}
298
+ for (const [key, value] of Object.entries(fields)) {
299
+ if (value !== undefined && allowedOperations.includes(key)) {
300
+ result[key] = value
301
+ }
302
+ }
303
+ return result
304
+ }
305
+ }
@@ -0,0 +1,37 @@
1
+ import { printSchema } from 'graphql'
2
+ import { buildSchema, Schema, TypeKind } from '@contember/graphql-json'
3
+ import introspectionSchema, { createSchemaConfig } from '../introspection/introspection.schema.js'
4
+ import { IntrospectionSchemaFactory } from '../introspection/index.js'
5
+ import { JsonSchemaExtension } from './JsonContentSchemaBuilder.js'
6
+ import { getCustomScalars } from './GraphQLJsBridge.js'
7
+
8
+ let introspectionTypes: Schema | undefined
9
+ const getIntrospectionTypes = (): Schema => {
10
+ introspectionTypes ??= buildSchema(printSchema(introspectionSchema))
11
+ return introspectionTypes
12
+ }
13
+
14
+ /** The `schema` query of the content API. Its types are static, so they are converted from graphql-js once. */
15
+ export const createJsonIntrospectionExtension = (introspectionSchemaFactory: IntrospectionSchemaFactory): JsonSchemaExtension => {
16
+ const { q: queryTypeName, t: allTypes } = getIntrospectionTypes()
17
+ const queryType = allTypes[queryTypeName]
18
+ if (!queryType || queryType[0] !== TypeKind.OBJECT) {
19
+ throw new Error('Introspection schema has no query type')
20
+ }
21
+ const schemaField = queryType[1].schema
22
+ if (!schemaField) {
23
+ throw new Error('Introspection schema has no schema field')
24
+ }
25
+ const types = Object.fromEntries(Object.entries(allTypes).filter(([name]) => name !== queryTypeName))
26
+ return {
27
+ types,
28
+ includedTypes: (createSchemaConfig().types ?? []).map(it => it.name),
29
+ scalars: getCustomScalars(introspectionSchema),
30
+ queries: {
31
+ schema: {
32
+ type: schemaField[0],
33
+ resolve: () => introspectionSchemaFactory.create(),
34
+ },
35
+ },
36
+ }
37
+ }
@@ -0,0 +1,128 @@
1
+ import { FieldNode as GraphQlFieldNode, Kind, SelectionSetNode } from 'graphql'
2
+ import { getArgumentValues, InterfaceType, ObjectType, ResolveInfo, ScalarMap, Schema, TypeKind } from '@contember/graphql-json'
3
+ import { FieldNode, ObjectNode } from '../inputProcessing/index.js'
4
+ import { isDeepStrictEqual } from 'node:util'
5
+ import { ResolveInfoUtils } from '../utils/index.js'
6
+ import { FieldExtensions } from './JsonTypeRegistry.js'
7
+ import type { NodeFilter } from '../resolvers/GraphQlQueryAstFactory.js'
8
+
9
+ type AnyNode = ObjectNode | FieldNode
10
+
11
+ /**
12
+ * Turns the resolved field into Contember's query tree. The schema comes from the resolve info, so one factory
13
+ * serves every role schema of a model.
14
+ */
15
+ export class JsonQueryAstFactory {
16
+ constructor(
17
+ private readonly scalars: ScalarMap,
18
+ private readonly extensions: Record<string, Record<string, FieldExtensions>>,
19
+ ) {}
20
+
21
+ public create<Args = any>(info: ResolveInfo, filter?: NodeFilter): ObjectNode<Args> {
22
+ const node = ResolveInfoUtils.extractFieldNode(info)
23
+ const result = this.createFromNode(info, info.parentType, node, [], filter ?? (() => true))
24
+ if (!(result instanceof ObjectNode)) {
25
+ throw new Error(`JsonQueryAstFactory: field ${info.parentType}.${info.fieldName} has no selection`)
26
+ }
27
+ return result
28
+ }
29
+
30
+ private createFromNode(
31
+ info: ResolveInfo,
32
+ parentTypeName: string,
33
+ node: GraphQlFieldNode,
34
+ path: string[],
35
+ filter: NodeFilter,
36
+ ): AnyNode | null {
37
+ if (!filter(node, path)) {
38
+ return null
39
+ }
40
+ const name = node.name.value
41
+ const alias = node.alias ? node.alias.value : name
42
+ if (!node.selectionSet) {
43
+ return new FieldNode(name, alias, {})
44
+ }
45
+ const field = this.getCompositeType(info.schema, parentTypeName)[1][name]
46
+ if (!field) {
47
+ throw new Error(`JsonQueryAstFactory: unknown field ${parentTypeName}.${name}`)
48
+ }
49
+ const fieldTypeName = field[0][1]
50
+ const fieldType = info.schema.t[fieldTypeName]
51
+ if (!fieldType || fieldType[0] !== TypeKind.OBJECT) {
52
+ throw new Error(`JsonQueryAstFactory: ${fieldTypeName} is not an object type`)
53
+ }
54
+ const fields = this.processSelectionSet(info, fieldTypeName, node.selectionSet, [...path, alias], filter)
55
+ return new ObjectNode(
56
+ name,
57
+ alias,
58
+ fields,
59
+ getArgumentValues(info.schema, field, node, info.variableValues, this.scalars),
60
+ this.extensions[parentTypeName]?.[name] ?? {},
61
+ path,
62
+ )
63
+ }
64
+
65
+ private processSelectionSet(
66
+ info: ResolveInfo,
67
+ parentTypeName: string,
68
+ selectionSet: SelectionSetNode,
69
+ path: string[],
70
+ filter: NodeFilter,
71
+ ): AnyNode[] {
72
+ const fields: AnyNode[] = []
73
+ for (const subNode of selectionSet.selections) {
74
+ if (subNode.kind === Kind.FIELD) {
75
+ const field = this.createFromNode(info, parentTypeName, subNode, path, filter)
76
+ if (field !== null) {
77
+ fields.push(field)
78
+ }
79
+ } else if (subNode.kind === Kind.FRAGMENT_SPREAD) {
80
+ const fragmentDefinition = info.fragments[subNode.name.value]
81
+ if (!fragmentDefinition) {
82
+ throw new Error(`JsonQueryAstFactory: Fragment definition ${subNode.name.value} not found`)
83
+ }
84
+ const typeName = fragmentDefinition.typeCondition.name.value
85
+ this.getCompositeType(info.schema, typeName)
86
+ fields.push(...this.processSelectionSet(info, typeName, fragmentDefinition.selectionSet, path, filter))
87
+ } else {
88
+ throw new Error('InlineFragment are not supported yet')
89
+ }
90
+ }
91
+ return mergeFieldList(fields)
92
+ }
93
+
94
+ private getCompositeType(schema: Schema, typeName: string): ObjectType | InterfaceType {
95
+ const type = schema.t[typeName]
96
+ if (!type || (type[0] !== TypeKind.OBJECT && type[0] !== TypeKind.INTERFACE)) {
97
+ throw new Error('JsonQueryAstFactory: subfield is expected to be an object or interface type')
98
+ }
99
+ return type
100
+ }
101
+ }
102
+
103
+ const mergeFieldList = (nodes: AnyNode[]): AnyNode[] => {
104
+ // a Map, so aliases such as `toString` or `__proto__` do not hit Object.prototype
105
+ const result = new Map<string, AnyNode>()
106
+ for (const node of nodes) {
107
+ const existing = result.get(node.alias)
108
+ result.set(node.alias, existing ? mergeFields(existing, node) : node)
109
+ }
110
+ return [...result.values()]
111
+ }
112
+
113
+ const mergeFields = (left: AnyNode, right: AnyNode): AnyNode => {
114
+ if (left.constructor !== right.constructor) {
115
+ throw new Error(`JsonQueryAstFactory: cannot merge ${left.constructor.name} and ${right.constructor.name}`)
116
+ }
117
+ if (left.name !== right.name) {
118
+ throw new Error(`JsonQueryAstFactory: incompatible fields ${left.name} and ${right.name}`)
119
+ }
120
+ if (left instanceof ObjectNode && right instanceof ObjectNode) {
121
+ if (!isDeepStrictEqual(left.args, right.args)) {
122
+ throw new Error(`JsonQueryAstFactory: incompatible args`)
123
+ }
124
+ const fields = mergeFieldList([...left.fields, ...right.fields])
125
+ return new ObjectNode(left.name, left.alias, fields, left.args, left.extensions, left.path)
126
+ }
127
+ return left
128
+ }