@constructive-io/graphql-codegen 2.19.0 → 2.20.1

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 (301) hide show
  1. package/README.md +1818 -113
  2. package/__tests__/codegen/input-types-generator.test.d.ts +1 -0
  3. package/__tests__/codegen/input-types-generator.test.js +635 -0
  4. package/cli/codegen/barrel.d.ts +27 -0
  5. package/cli/codegen/barrel.js +163 -0
  6. package/cli/codegen/client.d.ts +4 -0
  7. package/cli/codegen/client.js +170 -0
  8. package/cli/codegen/custom-mutations.d.ts +38 -0
  9. package/cli/codegen/custom-mutations.js +149 -0
  10. package/cli/codegen/custom-queries.d.ts +38 -0
  11. package/cli/codegen/custom-queries.js +358 -0
  12. package/cli/codegen/filters.d.ts +27 -0
  13. package/cli/codegen/filters.js +357 -0
  14. package/cli/codegen/gql-ast.d.ts +41 -0
  15. package/cli/codegen/gql-ast.js +329 -0
  16. package/cli/codegen/index.d.ts +71 -0
  17. package/cli/codegen/index.js +147 -0
  18. package/cli/codegen/mutations.d.ts +30 -0
  19. package/cli/codegen/mutations.js +410 -0
  20. package/cli/codegen/orm/barrel.d.ts +18 -0
  21. package/cli/codegen/orm/barrel.js +48 -0
  22. package/cli/codegen/orm/client-generator.d.ts +45 -0
  23. package/cli/codegen/orm/client-generator.js +646 -0
  24. package/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
  25. package/cli/codegen/orm/custom-ops-generator.js +350 -0
  26. package/cli/codegen/orm/index.d.ts +38 -0
  27. package/cli/codegen/orm/index.js +88 -0
  28. package/cli/codegen/orm/input-types-generator.d.ts +21 -0
  29. package/cli/codegen/orm/input-types-generator.js +705 -0
  30. package/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
  31. package/cli/codegen/orm/input-types-generator.test.js +75 -0
  32. package/cli/codegen/orm/model-generator.d.ts +32 -0
  33. package/cli/codegen/orm/model-generator.js +264 -0
  34. package/cli/codegen/orm/query-builder.d.ts +161 -0
  35. package/cli/codegen/orm/query-builder.js +366 -0
  36. package/cli/codegen/orm/select-types.d.ts +169 -0
  37. package/cli/codegen/orm/select-types.js +16 -0
  38. package/cli/codegen/orm/select-types.test.d.ts +11 -0
  39. package/cli/codegen/orm/select-types.test.js +22 -0
  40. package/cli/codegen/queries.d.ts +25 -0
  41. package/cli/codegen/queries.js +438 -0
  42. package/cli/codegen/scalars.d.ts +12 -0
  43. package/cli/codegen/scalars.js +71 -0
  44. package/cli/codegen/schema-gql-ast.d.ts +51 -0
  45. package/cli/codegen/schema-gql-ast.js +385 -0
  46. package/cli/codegen/ts-ast.d.ts +122 -0
  47. package/cli/codegen/ts-ast.js +280 -0
  48. package/cli/codegen/type-resolver.d.ts +96 -0
  49. package/cli/codegen/type-resolver.js +246 -0
  50. package/cli/codegen/types.d.ts +12 -0
  51. package/cli/codegen/types.js +69 -0
  52. package/cli/codegen/utils.d.ts +163 -0
  53. package/cli/codegen/utils.js +326 -0
  54. package/cli/commands/generate-orm.d.ts +37 -0
  55. package/cli/commands/generate-orm.js +195 -0
  56. package/cli/commands/generate.d.ts +39 -0
  57. package/cli/commands/generate.js +299 -0
  58. package/cli/commands/index.d.ts +7 -0
  59. package/cli/commands/index.js +12 -0
  60. package/cli/commands/init.d.ts +35 -0
  61. package/cli/commands/init.js +176 -0
  62. package/cli/index.d.ts +4 -0
  63. package/cli/index.js +291 -0
  64. package/cli/introspect/fetch-meta.d.ts +31 -0
  65. package/cli/introspect/fetch-meta.js +108 -0
  66. package/cli/introspect/fetch-schema.d.ts +21 -0
  67. package/cli/introspect/fetch-schema.js +86 -0
  68. package/cli/introspect/index.d.ts +8 -0
  69. package/cli/introspect/index.js +16 -0
  70. package/cli/introspect/meta-query.d.ts +111 -0
  71. package/cli/introspect/meta-query.js +191 -0
  72. package/cli/introspect/schema-query.d.ts +20 -0
  73. package/cli/introspect/schema-query.js +123 -0
  74. package/cli/introspect/transform-schema.d.ts +74 -0
  75. package/cli/introspect/transform-schema.js +269 -0
  76. package/cli/introspect/transform-schema.test.d.ts +1 -0
  77. package/cli/introspect/transform-schema.test.js +67 -0
  78. package/cli/introspect/transform.d.ts +21 -0
  79. package/cli/introspect/transform.js +216 -0
  80. package/cli/watch/cache.d.ts +45 -0
  81. package/cli/watch/cache.js +111 -0
  82. package/cli/watch/debounce.d.ts +19 -0
  83. package/cli/watch/debounce.js +89 -0
  84. package/cli/watch/hash.d.ts +17 -0
  85. package/cli/watch/hash.js +48 -0
  86. package/cli/watch/index.d.ts +10 -0
  87. package/cli/watch/index.js +22 -0
  88. package/cli/watch/orchestrator.d.ts +63 -0
  89. package/cli/watch/orchestrator.js +228 -0
  90. package/cli/watch/poller.d.ts +65 -0
  91. package/cli/watch/poller.js +203 -0
  92. package/cli/watch/types.d.ts +67 -0
  93. package/cli/watch/types.js +5 -0
  94. package/client/error.d.ts +95 -0
  95. package/client/error.js +255 -0
  96. package/client/execute.d.ts +57 -0
  97. package/client/execute.js +124 -0
  98. package/client/index.d.ts +6 -0
  99. package/client/index.js +18 -0
  100. package/client/typed-document.d.ts +31 -0
  101. package/client/typed-document.js +44 -0
  102. package/core/ast.d.ts +10 -0
  103. package/core/ast.js +593 -0
  104. package/core/custom-ast.d.ts +35 -0
  105. package/core/custom-ast.js +204 -0
  106. package/core/index.d.ts +8 -0
  107. package/core/index.js +33 -0
  108. package/core/meta-object/convert.d.ts +65 -0
  109. package/core/meta-object/convert.js +63 -0
  110. package/core/meta-object/format.json +93 -0
  111. package/core/meta-object/index.d.ts +2 -0
  112. package/core/meta-object/index.js +18 -0
  113. package/core/meta-object/validate.d.ts +9 -0
  114. package/core/meta-object/validate.js +34 -0
  115. package/core/query-builder.d.ts +46 -0
  116. package/core/query-builder.js +412 -0
  117. package/core/types.d.ts +139 -0
  118. package/core/types.js +28 -0
  119. package/esm/__tests__/codegen/input-types-generator.test.d.ts +1 -0
  120. package/esm/__tests__/codegen/input-types-generator.test.js +633 -0
  121. package/esm/cli/codegen/barrel.d.ts +27 -0
  122. package/esm/cli/codegen/barrel.js +156 -0
  123. package/esm/cli/codegen/client.d.ts +4 -0
  124. package/esm/cli/codegen/client.js +167 -0
  125. package/esm/cli/codegen/custom-mutations.d.ts +38 -0
  126. package/esm/cli/codegen/custom-mutations.js +145 -0
  127. package/esm/cli/codegen/custom-queries.d.ts +38 -0
  128. package/esm/cli/codegen/custom-queries.js +354 -0
  129. package/esm/cli/codegen/filters.d.ts +27 -0
  130. package/esm/cli/codegen/filters.js +351 -0
  131. package/esm/cli/codegen/gql-ast.d.ts +41 -0
  132. package/esm/cli/codegen/gql-ast.js +288 -0
  133. package/esm/cli/codegen/index.d.ts +71 -0
  134. package/esm/cli/codegen/index.js +124 -0
  135. package/esm/cli/codegen/mutations.d.ts +30 -0
  136. package/esm/cli/codegen/mutations.js +404 -0
  137. package/esm/cli/codegen/orm/barrel.d.ts +18 -0
  138. package/esm/cli/codegen/orm/barrel.js +44 -0
  139. package/esm/cli/codegen/orm/client-generator.d.ts +45 -0
  140. package/esm/cli/codegen/orm/client-generator.js +640 -0
  141. package/esm/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
  142. package/esm/cli/codegen/orm/custom-ops-generator.js +346 -0
  143. package/esm/cli/codegen/orm/index.d.ts +38 -0
  144. package/esm/cli/codegen/orm/index.js +75 -0
  145. package/esm/cli/codegen/orm/input-types-generator.d.ts +21 -0
  146. package/esm/cli/codegen/orm/input-types-generator.js +700 -0
  147. package/esm/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
  148. package/esm/cli/codegen/orm/input-types-generator.test.js +73 -0
  149. package/esm/cli/codegen/orm/model-generator.d.ts +32 -0
  150. package/esm/cli/codegen/orm/model-generator.js +260 -0
  151. package/esm/cli/codegen/orm/query-builder.d.ts +161 -0
  152. package/esm/cli/codegen/orm/query-builder.js +353 -0
  153. package/esm/cli/codegen/orm/select-types.d.ts +169 -0
  154. package/esm/cli/codegen/orm/select-types.js +15 -0
  155. package/esm/cli/codegen/orm/select-types.test.d.ts +11 -0
  156. package/esm/cli/codegen/orm/select-types.test.js +21 -0
  157. package/esm/cli/codegen/queries.d.ts +25 -0
  158. package/esm/cli/codegen/queries.js +433 -0
  159. package/esm/cli/codegen/scalars.d.ts +12 -0
  160. package/esm/cli/codegen/scalars.js +66 -0
  161. package/esm/cli/codegen/schema-gql-ast.d.ts +51 -0
  162. package/esm/cli/codegen/schema-gql-ast.js +343 -0
  163. package/esm/cli/codegen/ts-ast.d.ts +122 -0
  164. package/esm/cli/codegen/ts-ast.js +260 -0
  165. package/esm/cli/codegen/type-resolver.d.ts +96 -0
  166. package/esm/cli/codegen/type-resolver.js +224 -0
  167. package/esm/cli/codegen/types.d.ts +12 -0
  168. package/esm/cli/codegen/types.js +65 -0
  169. package/esm/cli/codegen/utils.d.ts +163 -0
  170. package/esm/cli/codegen/utils.js +288 -0
  171. package/esm/cli/commands/generate-orm.d.ts +37 -0
  172. package/esm/cli/commands/generate-orm.js +192 -0
  173. package/esm/cli/commands/generate.d.ts +39 -0
  174. package/esm/cli/commands/generate.js +262 -0
  175. package/esm/cli/commands/index.d.ts +7 -0
  176. package/esm/cli/commands/index.js +5 -0
  177. package/esm/cli/commands/init.d.ts +35 -0
  178. package/esm/cli/commands/init.js +138 -0
  179. package/esm/cli/index.d.ts +4 -0
  180. package/esm/cli/index.js +256 -0
  181. package/esm/cli/introspect/fetch-meta.d.ts +31 -0
  182. package/esm/cli/introspect/fetch-meta.js +104 -0
  183. package/esm/cli/introspect/fetch-schema.d.ts +21 -0
  184. package/esm/cli/introspect/fetch-schema.js +83 -0
  185. package/esm/cli/introspect/index.d.ts +8 -0
  186. package/esm/cli/introspect/index.js +6 -0
  187. package/esm/cli/introspect/meta-query.d.ts +111 -0
  188. package/esm/cli/introspect/meta-query.js +188 -0
  189. package/esm/cli/introspect/schema-query.d.ts +20 -0
  190. package/esm/cli/introspect/schema-query.js +120 -0
  191. package/esm/cli/introspect/transform-schema.d.ts +74 -0
  192. package/esm/cli/introspect/transform-schema.js +259 -0
  193. package/esm/cli/introspect/transform-schema.test.d.ts +1 -0
  194. package/esm/cli/introspect/transform-schema.test.js +65 -0
  195. package/esm/cli/introspect/transform.d.ts +21 -0
  196. package/esm/cli/introspect/transform.js +210 -0
  197. package/esm/cli/watch/cache.d.ts +45 -0
  198. package/esm/cli/watch/cache.js +73 -0
  199. package/esm/cli/watch/debounce.d.ts +19 -0
  200. package/esm/cli/watch/debounce.js +85 -0
  201. package/esm/cli/watch/hash.d.ts +17 -0
  202. package/esm/cli/watch/hash.js +43 -0
  203. package/esm/cli/watch/index.d.ts +10 -0
  204. package/esm/cli/watch/index.js +8 -0
  205. package/esm/cli/watch/orchestrator.d.ts +63 -0
  206. package/esm/cli/watch/orchestrator.js +223 -0
  207. package/esm/cli/watch/poller.d.ts +65 -0
  208. package/esm/cli/watch/poller.js +198 -0
  209. package/esm/cli/watch/types.d.ts +67 -0
  210. package/esm/cli/watch/types.js +4 -0
  211. package/esm/client/error.d.ts +95 -0
  212. package/esm/client/error.js +249 -0
  213. package/esm/client/execute.d.ts +57 -0
  214. package/esm/client/execute.js +120 -0
  215. package/esm/client/index.d.ts +6 -0
  216. package/esm/client/index.js +6 -0
  217. package/esm/client/typed-document.d.ts +31 -0
  218. package/esm/client/typed-document.js +40 -0
  219. package/esm/core/ast.d.ts +10 -0
  220. package/esm/core/ast.js +549 -0
  221. package/esm/core/custom-ast.d.ts +35 -0
  222. package/esm/core/custom-ast.js +161 -0
  223. package/esm/core/index.d.ts +8 -0
  224. package/esm/core/index.js +12 -0
  225. package/esm/core/meta-object/convert.d.ts +65 -0
  226. package/esm/core/meta-object/convert.js +60 -0
  227. package/esm/core/meta-object/format.json +93 -0
  228. package/esm/core/meta-object/index.d.ts +2 -0
  229. package/esm/core/meta-object/index.js +2 -0
  230. package/esm/core/meta-object/validate.d.ts +9 -0
  231. package/esm/core/meta-object/validate.js +28 -0
  232. package/esm/core/query-builder.d.ts +46 -0
  233. package/esm/core/query-builder.js +375 -0
  234. package/esm/core/types.d.ts +139 -0
  235. package/esm/core/types.js +24 -0
  236. package/esm/generators/field-selector.d.ts +30 -0
  237. package/esm/generators/field-selector.js +355 -0
  238. package/esm/generators/index.d.ts +6 -0
  239. package/esm/generators/index.js +9 -0
  240. package/esm/generators/mutations.d.ts +31 -0
  241. package/esm/generators/mutations.js +197 -0
  242. package/esm/generators/select.d.ts +50 -0
  243. package/esm/generators/select.js +636 -0
  244. package/esm/index.d.ts +12 -0
  245. package/esm/index.js +17 -3
  246. package/esm/react/index.d.ts +5 -0
  247. package/esm/react/index.js +6 -0
  248. package/esm/types/config.d.ts +199 -0
  249. package/esm/types/config.js +106 -0
  250. package/esm/types/index.d.ts +9 -0
  251. package/esm/types/index.js +4 -0
  252. package/esm/types/introspection.d.ts +121 -0
  253. package/esm/types/introspection.js +54 -0
  254. package/esm/types/mutation.d.ts +45 -0
  255. package/esm/types/mutation.js +4 -0
  256. package/esm/types/query.d.ts +82 -0
  257. package/esm/types/query.js +4 -0
  258. package/esm/types/schema.d.ts +253 -0
  259. package/esm/types/schema.js +5 -0
  260. package/esm/types/selection.d.ts +43 -0
  261. package/esm/types/selection.js +4 -0
  262. package/esm/utils/index.d.ts +4 -0
  263. package/esm/utils/index.js +4 -0
  264. package/generators/field-selector.d.ts +30 -0
  265. package/generators/field-selector.js +361 -0
  266. package/generators/index.d.ts +6 -0
  267. package/generators/index.js +27 -0
  268. package/generators/mutations.d.ts +31 -0
  269. package/generators/mutations.js +235 -0
  270. package/generators/select.d.ts +50 -0
  271. package/generators/select.js +679 -0
  272. package/index.d.ts +12 -3
  273. package/index.js +19 -3
  274. package/package.json +59 -38
  275. package/react/index.d.ts +5 -0
  276. package/react/index.js +9 -0
  277. package/types/config.d.ts +199 -0
  278. package/types/config.js +111 -0
  279. package/types/index.d.ts +9 -0
  280. package/types/index.js +10 -0
  281. package/types/introspection.d.ts +121 -0
  282. package/types/introspection.js +62 -0
  283. package/types/mutation.d.ts +45 -0
  284. package/types/mutation.js +5 -0
  285. package/types/query.d.ts +82 -0
  286. package/types/query.js +5 -0
  287. package/types/schema.d.ts +253 -0
  288. package/types/schema.js +6 -0
  289. package/types/selection.d.ts +43 -0
  290. package/types/selection.js +5 -0
  291. package/utils/index.d.ts +4 -0
  292. package/utils/index.js +7 -0
  293. package/codegen.d.ts +0 -13
  294. package/codegen.js +0 -293
  295. package/esm/codegen.js +0 -253
  296. package/esm/gql.js +0 -939
  297. package/esm/options.js +0 -27
  298. package/gql.d.ts +0 -188
  299. package/gql.js +0 -992
  300. package/options.d.ts +0 -45
  301. package/options.js +0 -31
package/core/ast.js ADDED
@@ -0,0 +1,593 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.deleteOne = exports.patchOne = exports.createOne = exports.getOne = exports.getMany = exports.getCount = exports.getAll = void 0;
37
+ exports.getSelections = getSelections;
38
+ const t = __importStar(require("gql-ast"));
39
+ const inflection = __importStar(require("inflection"));
40
+ const custom_ast_1 = require("./custom-ast");
41
+ const NON_MUTABLE_PROPS = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy'];
42
+ const objectToArray = (obj) => Object.keys(obj).map((k) => ({
43
+ key: k,
44
+ name: obj[k].name || k,
45
+ type: obj[k].type,
46
+ isNotNull: obj[k].isNotNull,
47
+ isArray: obj[k].isArray,
48
+ isArrayNotNull: obj[k].isArrayNotNull,
49
+ properties: obj[k].properties,
50
+ }));
51
+ const createGqlMutation = ({ operationName, mutationName, selectArgs, selections, variableDefinitions, modelName, useModel = true, }) => {
52
+ const opSel = !modelName
53
+ ? [
54
+ t.field({
55
+ name: operationName,
56
+ args: selectArgs,
57
+ selectionSet: t.selectionSet({ selections }),
58
+ }),
59
+ ]
60
+ : [
61
+ t.field({
62
+ name: operationName,
63
+ args: selectArgs,
64
+ selectionSet: t.selectionSet({
65
+ selections: useModel
66
+ ? [
67
+ t.field({
68
+ name: modelName,
69
+ selectionSet: t.selectionSet({ selections }),
70
+ }),
71
+ ]
72
+ : selections,
73
+ }),
74
+ }),
75
+ ];
76
+ return t.document({
77
+ definitions: [
78
+ t.operationDefinition({
79
+ operation: 'mutation',
80
+ name: mutationName,
81
+ variableDefinitions,
82
+ selectionSet: t.selectionSet({ selections: opSel }),
83
+ }),
84
+ ],
85
+ });
86
+ };
87
+ const getAll = ({ queryName, operationName, selection, }) => {
88
+ const selections = getSelections(selection);
89
+ const opSel = [
90
+ t.field({
91
+ name: operationName,
92
+ selectionSet: t.selectionSet({
93
+ selections: [
94
+ t.field({
95
+ name: 'totalCount',
96
+ }),
97
+ t.field({
98
+ name: 'nodes',
99
+ selectionSet: t.selectionSet({ selections }),
100
+ }),
101
+ ],
102
+ }),
103
+ }),
104
+ ];
105
+ const ast = t.document({
106
+ definitions: [
107
+ t.operationDefinition({
108
+ operation: 'query',
109
+ name: queryName,
110
+ selectionSet: t.selectionSet({ selections: opSel }),
111
+ }),
112
+ ],
113
+ });
114
+ return ast;
115
+ };
116
+ exports.getAll = getAll;
117
+ const getCount = ({ queryName, operationName, query, }) => {
118
+ const Singular = query.model;
119
+ const Filter = `${Singular}Filter`;
120
+ const Condition = `${Singular}Condition`;
121
+ const variableDefinitions = [
122
+ t.variableDefinition({
123
+ variable: t.variable({ name: 'condition' }),
124
+ type: t.namedType({ type: Condition }),
125
+ }),
126
+ t.variableDefinition({
127
+ variable: t.variable({ name: 'filter' }),
128
+ type: t.namedType({ type: Filter }),
129
+ }),
130
+ ];
131
+ const args = [
132
+ t.argument({ name: 'condition', value: t.variable({ name: 'condition' }) }),
133
+ t.argument({ name: 'filter', value: t.variable({ name: 'filter' }) }),
134
+ ];
135
+ // PostGraphile supports totalCount through connections
136
+ const opSel = [
137
+ t.field({
138
+ name: operationName,
139
+ args,
140
+ selectionSet: t.selectionSet({
141
+ selections: [
142
+ t.field({
143
+ name: 'totalCount',
144
+ }),
145
+ ],
146
+ }),
147
+ }),
148
+ ];
149
+ const ast = t.document({
150
+ definitions: [
151
+ t.operationDefinition({
152
+ operation: 'query',
153
+ name: queryName,
154
+ variableDefinitions,
155
+ selectionSet: t.selectionSet({ selections: opSel }),
156
+ }),
157
+ ],
158
+ });
159
+ return ast;
160
+ };
161
+ exports.getCount = getCount;
162
+ const getMany = ({ builder, queryName, operationName, query, selection, }) => {
163
+ const Singular = query.model;
164
+ const Plural = operationName.charAt(0).toUpperCase() + operationName.slice(1);
165
+ const Condition = `${Singular}Condition`;
166
+ const Filter = `${Singular}Filter`;
167
+ const OrderBy = `${Plural}OrderBy`;
168
+ const selections = getSelections(selection);
169
+ const variableDefinitions = [
170
+ t.variableDefinition({
171
+ variable: t.variable({ name: 'first' }),
172
+ type: t.namedType({ type: 'Int' }),
173
+ }),
174
+ t.variableDefinition({
175
+ variable: t.variable({ name: 'last' }),
176
+ type: t.namedType({ type: 'Int' }),
177
+ }),
178
+ t.variableDefinition({
179
+ variable: t.variable({ name: 'after' }),
180
+ type: t.namedType({ type: 'Cursor' }),
181
+ }),
182
+ t.variableDefinition({
183
+ variable: t.variable({ name: 'before' }),
184
+ type: t.namedType({ type: 'Cursor' }),
185
+ }),
186
+ t.variableDefinition({
187
+ variable: t.variable({ name: 'offset' }),
188
+ type: t.namedType({ type: 'Int' }),
189
+ }),
190
+ t.variableDefinition({
191
+ variable: t.variable({ name: 'condition' }),
192
+ type: t.namedType({ type: Condition }),
193
+ }),
194
+ t.variableDefinition({
195
+ variable: t.variable({ name: 'filter' }),
196
+ type: t.namedType({ type: Filter }),
197
+ }),
198
+ t.variableDefinition({
199
+ variable: t.variable({ name: 'orderBy' }),
200
+ type: t.listType({
201
+ type: t.nonNullType({ type: t.namedType({ type: OrderBy }) }),
202
+ }),
203
+ }),
204
+ ];
205
+ const args = [
206
+ t.argument({ name: 'first', value: t.variable({ name: 'first' }) }),
207
+ t.argument({ name: 'last', value: t.variable({ name: 'last' }) }),
208
+ t.argument({ name: 'offset', value: t.variable({ name: 'offset' }) }),
209
+ t.argument({ name: 'after', value: t.variable({ name: 'after' }) }),
210
+ t.argument({ name: 'before', value: t.variable({ name: 'before' }) }),
211
+ t.argument({
212
+ name: 'condition',
213
+ value: t.variable({ name: 'condition' }),
214
+ }),
215
+ t.argument({ name: 'filter', value: t.variable({ name: 'filter' }) }),
216
+ t.argument({ name: 'orderBy', value: t.variable({ name: 'orderBy' }) }),
217
+ ];
218
+ const pageInfoFields = [
219
+ t.field({ name: 'hasNextPage' }),
220
+ t.field({ name: 'hasPreviousPage' }),
221
+ t.field({ name: 'endCursor' }),
222
+ t.field({ name: 'startCursor' }),
223
+ ];
224
+ const dataField = builder?._edges
225
+ ? t.field({
226
+ name: 'edges',
227
+ selectionSet: t.selectionSet({
228
+ selections: [
229
+ t.field({ name: 'cursor' }),
230
+ t.field({
231
+ name: 'node',
232
+ selectionSet: t.selectionSet({ selections }),
233
+ }),
234
+ ],
235
+ }),
236
+ })
237
+ : t.field({
238
+ name: 'nodes',
239
+ selectionSet: t.selectionSet({ selections }),
240
+ });
241
+ const connectionFields = [
242
+ t.field({ name: 'totalCount' }),
243
+ t.field({
244
+ name: 'pageInfo',
245
+ selectionSet: t.selectionSet({ selections: pageInfoFields }),
246
+ }),
247
+ dataField,
248
+ ];
249
+ const ast = t.document({
250
+ definitions: [
251
+ t.operationDefinition({
252
+ operation: 'query',
253
+ name: queryName,
254
+ variableDefinitions,
255
+ selectionSet: t.selectionSet({
256
+ selections: [
257
+ t.field({
258
+ name: operationName,
259
+ args,
260
+ selectionSet: t.selectionSet({ selections: connectionFields }),
261
+ }),
262
+ ],
263
+ }),
264
+ }),
265
+ ],
266
+ });
267
+ return ast;
268
+ };
269
+ exports.getMany = getMany;
270
+ const getOne = ({ queryName, operationName, query, selection, }) => {
271
+ const variableDefinitions = Object.keys(query.properties)
272
+ .map((key) => ({ key, ...query.properties[key] }))
273
+ .filter((field) => field.isNotNull)
274
+ .map((field) => {
275
+ const { key: fieldName, type: fieldType, isNotNull, isArray, isArrayNotNull, } = field;
276
+ let type = t.namedType({ type: fieldType });
277
+ if (isNotNull)
278
+ type = t.nonNullType({ type });
279
+ if (isArray) {
280
+ type = t.listType({ type });
281
+ if (isArrayNotNull)
282
+ type = t.nonNullType({ type });
283
+ }
284
+ return t.variableDefinition({
285
+ variable: t.variable({ name: fieldName }),
286
+ type,
287
+ });
288
+ });
289
+ const props = objectToArray(query.properties);
290
+ const selectArgs = props
291
+ .filter((field) => field.isNotNull)
292
+ .map((field) => {
293
+ return t.argument({
294
+ name: field.name,
295
+ value: t.variable({ name: field.name }),
296
+ });
297
+ });
298
+ const selections = getSelections(selection);
299
+ const opSel = [
300
+ t.field({
301
+ name: operationName,
302
+ args: selectArgs,
303
+ selectionSet: t.selectionSet({ selections }),
304
+ }),
305
+ ];
306
+ const ast = t.document({
307
+ definitions: [
308
+ t.operationDefinition({
309
+ operation: 'query',
310
+ name: queryName,
311
+ variableDefinitions,
312
+ selectionSet: t.selectionSet({ selections: opSel }),
313
+ }),
314
+ ],
315
+ });
316
+ return ast;
317
+ };
318
+ exports.getOne = getOne;
319
+ const createOne = ({ mutationName, operationName, mutation, selection, }) => {
320
+ if (!mutation.properties?.input?.properties) {
321
+ throw new Error(`No input field for mutation: ${mutationName}`);
322
+ }
323
+ const modelName = inflection.camelize([inflection.singularize(mutation.model)].join('_'), true);
324
+ const inputProperties = mutation.properties.input
325
+ .properties;
326
+ const modelProperties = inputProperties[modelName];
327
+ if (!modelProperties.properties) {
328
+ throw new Error(`No properties found for model: ${modelName}`);
329
+ }
330
+ const allAttrs = objectToArray(modelProperties.properties);
331
+ const attrs = allAttrs.filter((field) => !NON_MUTABLE_PROPS.includes(field.name));
332
+ const variableDefinitions = getCreateVariablesAst(attrs);
333
+ const selectArgs = [
334
+ t.argument({
335
+ name: 'input',
336
+ value: t.objectValue({
337
+ fields: [
338
+ t.objectField({
339
+ name: modelName,
340
+ value: t.objectValue({
341
+ fields: attrs.map((field) => t.objectField({
342
+ name: field.name,
343
+ value: t.variable({ name: field.name }),
344
+ })),
345
+ }),
346
+ }),
347
+ ],
348
+ }),
349
+ }),
350
+ ];
351
+ const selections = selection
352
+ ? getSelections(selection)
353
+ : allAttrs.map((field) => t.field({ name: field.name }));
354
+ const ast = createGqlMutation({
355
+ operationName,
356
+ mutationName,
357
+ selectArgs,
358
+ selections,
359
+ variableDefinitions,
360
+ modelName,
361
+ });
362
+ return ast;
363
+ };
364
+ exports.createOne = createOne;
365
+ const patchOne = ({ mutationName, operationName, mutation, selection, }) => {
366
+ if (!mutation.properties?.input?.properties) {
367
+ throw new Error(`No input field for mutation: ${mutationName}`);
368
+ }
369
+ const modelName = inflection.camelize([inflection.singularize(mutation.model)].join('_'), true);
370
+ const inputProperties = mutation.properties.input
371
+ .properties;
372
+ const patchProperties = inputProperties['patch'];
373
+ const allAttrs = patchProperties?.properties
374
+ ? objectToArray(patchProperties.properties)
375
+ : [];
376
+ const patchAttrs = allAttrs.filter((prop) => !NON_MUTABLE_PROPS.includes(prop.name));
377
+ const patchByAttrs = objectToArray(inputProperties).filter((n) => n.name !== 'patch');
378
+ const patchers = patchByAttrs.map((p) => p.name);
379
+ const variableDefinitions = getUpdateVariablesAst(patchAttrs, patchers);
380
+ const selectArgs = [
381
+ t.argument({
382
+ name: 'input',
383
+ value: t.objectValue({
384
+ fields: [
385
+ ...patchByAttrs.map((field) => t.objectField({
386
+ name: field.name,
387
+ value: t.variable({ name: field.name }),
388
+ })),
389
+ t.objectField({
390
+ name: 'patch',
391
+ value: t.objectValue({
392
+ fields: patchAttrs
393
+ .filter((field) => !patchers.includes(field.name))
394
+ .map((field) => t.objectField({
395
+ name: field.name,
396
+ value: t.variable({ name: field.name }),
397
+ })),
398
+ }),
399
+ }),
400
+ ],
401
+ }),
402
+ }),
403
+ ];
404
+ const selections = selection
405
+ ? getSelections(selection)
406
+ : allAttrs.map((field) => t.field({ name: field.name }));
407
+ const ast = createGqlMutation({
408
+ operationName,
409
+ mutationName,
410
+ selectArgs,
411
+ selections,
412
+ variableDefinitions,
413
+ modelName,
414
+ });
415
+ return ast;
416
+ };
417
+ exports.patchOne = patchOne;
418
+ const deleteOne = ({ mutationName, operationName, mutation, }) => {
419
+ if (!mutation.properties?.input?.properties) {
420
+ throw new Error(`No input field for mutation: ${mutationName}`);
421
+ }
422
+ const modelName = inflection.camelize([inflection.singularize(mutation.model)].join('_'), true);
423
+ const inputProperties = mutation.properties.input
424
+ .properties;
425
+ const deleteAttrs = objectToArray(inputProperties);
426
+ const variableDefinitions = deleteAttrs.map((field) => {
427
+ const { name: fieldName, type: fieldType, isNotNull, isArray } = field;
428
+ let type = t.namedType({ type: fieldType });
429
+ if (isNotNull)
430
+ type = t.nonNullType({ type });
431
+ if (isArray) {
432
+ type = t.listType({ type });
433
+ // no need to check isArrayNotNull since we need this field for deletion
434
+ type = t.nonNullType({ type });
435
+ }
436
+ return t.variableDefinition({
437
+ variable: t.variable({ name: fieldName }),
438
+ type,
439
+ });
440
+ });
441
+ const selectArgs = [
442
+ t.argument({
443
+ name: 'input',
444
+ value: t.objectValue({
445
+ fields: deleteAttrs.map((f) => t.objectField({
446
+ name: f.name,
447
+ value: t.variable({ name: f.name }),
448
+ })),
449
+ }),
450
+ }),
451
+ ];
452
+ // so we can support column select grants plugin
453
+ const selections = [t.field({ name: 'clientMutationId' })];
454
+ const ast = createGqlMutation({
455
+ operationName,
456
+ mutationName,
457
+ selectArgs,
458
+ selections,
459
+ useModel: false,
460
+ variableDefinitions,
461
+ modelName,
462
+ });
463
+ return ast;
464
+ };
465
+ exports.deleteOne = deleteOne;
466
+ function getSelections(selection = []) {
467
+ const selectionAst = (field) => {
468
+ if (typeof field === 'string') {
469
+ return t.field({ name: field });
470
+ }
471
+ // Check if fieldDefn has MetaField shape (has type.pgType)
472
+ const fieldDefn = field.fieldDefn;
473
+ if (fieldDefn &&
474
+ 'type' in fieldDefn &&
475
+ fieldDefn.type &&
476
+ typeof fieldDefn.type === 'object' &&
477
+ 'pgType' in fieldDefn.type) {
478
+ const customAst = (0, custom_ast_1.getCustomAst)(fieldDefn);
479
+ if (customAst)
480
+ return customAst;
481
+ }
482
+ return t.field({ name: field.name });
483
+ };
484
+ return selection
485
+ .map((selectionDefn) => {
486
+ if (selectionDefn.isObject) {
487
+ const { name, selection, variables = {}, isBelongTo } = selectionDefn;
488
+ const args = Object.entries(variables).reduce((acc, variable) => {
489
+ const [argName, argValue] = variable;
490
+ const argAst = t.argument({
491
+ name: argName,
492
+ value: getComplexValueAst(argValue),
493
+ });
494
+ return argAst ? [...acc, argAst] : acc;
495
+ }, []);
496
+ const subSelections = selection?.map((field) => selectionAst(field)) || [];
497
+ const selectionSet = isBelongTo
498
+ ? t.selectionSet({ selections: subSelections })
499
+ : t.selectionSet({
500
+ selections: [
501
+ t.field({ name: 'totalCount' }),
502
+ t.field({
503
+ name: 'nodes',
504
+ selectionSet: t.selectionSet({ selections: subSelections }),
505
+ }),
506
+ ],
507
+ });
508
+ return t.field({
509
+ name,
510
+ args,
511
+ selectionSet,
512
+ });
513
+ }
514
+ else {
515
+ return selectionAst(selectionDefn);
516
+ }
517
+ })
518
+ .filter((node) => node !== null);
519
+ }
520
+ function getComplexValueAst(value) {
521
+ // Handle null
522
+ if (value === null) {
523
+ return t.nullValue();
524
+ }
525
+ // Handle primitives
526
+ if (typeof value === 'boolean') {
527
+ return t.booleanValue({ value });
528
+ }
529
+ if (typeof value === 'number') {
530
+ return t.intValue({ value: value.toString() });
531
+ }
532
+ if (typeof value === 'string') {
533
+ return t.stringValue({ value });
534
+ }
535
+ // Handle arrays
536
+ if (Array.isArray(value)) {
537
+ return t.listValue({
538
+ values: value.map((item) => getComplexValueAst(item)),
539
+ });
540
+ }
541
+ // Handle objects
542
+ if (typeof value === 'object' && value !== null) {
543
+ const obj = value;
544
+ return t.objectValue({
545
+ fields: Object.entries(obj).map(([key, val]) => t.objectField({
546
+ name: key,
547
+ value: getComplexValueAst(val),
548
+ })),
549
+ });
550
+ }
551
+ throw new Error(`Unsupported value type: ${typeof value}`);
552
+ }
553
+ function getCreateVariablesAst(attrs) {
554
+ return attrs.map((field) => {
555
+ const { name: fieldName, type: fieldType, isNotNull, isArray, isArrayNotNull, } = field;
556
+ let type = t.namedType({ type: fieldType });
557
+ if (isNotNull)
558
+ type = t.nonNullType({ type });
559
+ if (isArray) {
560
+ type = t.listType({ type });
561
+ if (isArrayNotNull)
562
+ type = t.nonNullType({ type });
563
+ }
564
+ return t.variableDefinition({
565
+ variable: t.variable({ name: fieldName }),
566
+ type,
567
+ });
568
+ });
569
+ }
570
+ function getUpdateVariablesAst(attrs, patchers) {
571
+ const patchVariables = attrs
572
+ .filter((field) => !patchers.includes(field.name))
573
+ .map((field) => {
574
+ const { name: fieldName, type: fieldType, isArray, isArrayNotNull } = field;
575
+ let type = t.namedType({ type: fieldType });
576
+ if (isArray) {
577
+ type = t.listType({ type });
578
+ if (isArrayNotNull)
579
+ type = t.nonNullType({ type });
580
+ }
581
+ return t.variableDefinition({
582
+ variable: t.variable({ name: fieldName }),
583
+ type,
584
+ });
585
+ });
586
+ const patcherVariables = patchers.map((patcher) => {
587
+ return t.variableDefinition({
588
+ variable: t.variable({ name: patcher }),
589
+ type: t.nonNullType({ type: t.namedType({ type: 'String' }) }),
590
+ });
591
+ });
592
+ return [...patchVariables, ...patcherVariables];
593
+ }
@@ -0,0 +1,35 @@
1
+ import type { FieldNode } from 'graphql';
2
+ import type { CleanField } from '../types/schema';
3
+ import type { MetaField } from './types';
4
+ /**
5
+ * Get custom AST for MetaField type - handles PostgreSQL types that need subfield selections
6
+ */
7
+ export declare function getCustomAst(fieldDefn?: MetaField): FieldNode | null;
8
+ /**
9
+ * Generate custom AST for CleanField type - handles GraphQL types that need subfield selections
10
+ */
11
+ export declare function getCustomAstForCleanField(field: CleanField): FieldNode;
12
+ /**
13
+ * Check if a CleanField requires subfield selection based on its GraphQL type
14
+ */
15
+ export declare function requiresSubfieldSelection(field: CleanField): boolean;
16
+ /**
17
+ * Generate AST for GeometryPoint type
18
+ */
19
+ export declare function geometryPointAst(name: string): FieldNode;
20
+ /**
21
+ * Generate AST for GeometryGeometryCollection type
22
+ */
23
+ export declare function geometryCollectionAst(name: string): FieldNode;
24
+ /**
25
+ * Generate AST for generic geometry type (returns geojson)
26
+ */
27
+ export declare function geometryAst(name: string): FieldNode;
28
+ /**
29
+ * Generate AST for interval type
30
+ */
31
+ export declare function intervalAst(name: string): FieldNode;
32
+ /**
33
+ * Check if an object has interval type shape
34
+ */
35
+ export declare function isIntervalType(obj: unknown): boolean;