@constructive-io/graphql-codegen 2.19.0 → 2.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -0,0 +1,176 @@
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.initCommand = initCommand;
37
+ exports.findConfigFile = findConfigFile;
38
+ exports.loadConfigFile = loadConfigFile;
39
+ /**
40
+ * Init command - creates a new graphql-codegen configuration file
41
+ */
42
+ const fs = __importStar(require("node:fs"));
43
+ const path = __importStar(require("node:path"));
44
+ const jiti_1 = require("jiti");
45
+ const CONFIG_FILENAME = 'graphql-codegen.config.ts';
46
+ const CONFIG_TEMPLATE = `import { defineConfig } from '@constructive-io/graphql-codegen';
47
+
48
+ export default defineConfig({
49
+ // GraphQL endpoint URL (PostGraphile with _meta plugin)
50
+ endpoint: '{{ENDPOINT}}',
51
+
52
+ // Output directory for generated files
53
+ output: '{{OUTPUT}}',
54
+
55
+ // Optional: Tables to include/exclude (supports glob patterns)
56
+ // tables: {
57
+ // include: ['*'],
58
+ // exclude: ['_*', 'pg_*'],
59
+ // },
60
+
61
+ // Optional: Authorization header for authenticated endpoints
62
+ // headers: {
63
+ // Authorization: 'Bearer YOUR_TOKEN',
64
+ // },
65
+
66
+ // Optional: Watch mode settings (in-memory caching, no file I/O)
67
+ // watch: {
68
+ // pollInterval: 3000, // ms
69
+ // debounce: 800, // ms
70
+ // clearScreen: true,
71
+ // touchFile: '.trigger', // Optional: file to touch on change
72
+ // },
73
+ });
74
+ `;
75
+ /**
76
+ * Execute the init command
77
+ */
78
+ async function initCommand(options = {}) {
79
+ const { directory = process.cwd(), force = false, endpoint = '', output = './generated' } = options;
80
+ const configPath = path.join(directory, CONFIG_FILENAME);
81
+ // Check if config already exists
82
+ if (fs.existsSync(configPath) && !force) {
83
+ return {
84
+ success: false,
85
+ message: `Configuration file already exists: ${configPath}\nUse --force to overwrite.`,
86
+ };
87
+ }
88
+ // Generate config content
89
+ const content = CONFIG_TEMPLATE
90
+ .replace('{{ENDPOINT}}', endpoint || 'http://localhost:5000/graphql')
91
+ .replace('{{OUTPUT}}', output);
92
+ try {
93
+ // Ensure directory exists
94
+ fs.mkdirSync(directory, { recursive: true });
95
+ // Write config file
96
+ fs.writeFileSync(configPath, content, 'utf-8');
97
+ return {
98
+ success: true,
99
+ message: `Created configuration file: ${configPath}`,
100
+ configPath,
101
+ };
102
+ }
103
+ catch (err) {
104
+ const message = err instanceof Error ? err.message : 'Unknown error';
105
+ return {
106
+ success: false,
107
+ message: `Failed to create configuration file: ${message}`,
108
+ };
109
+ }
110
+ }
111
+ /**
112
+ * Find the nearest config file by walking up directories
113
+ */
114
+ function findConfigFile(startDir = process.cwd()) {
115
+ let currentDir = startDir;
116
+ while (true) {
117
+ const configPath = path.join(currentDir, CONFIG_FILENAME);
118
+ if (fs.existsSync(configPath)) {
119
+ return configPath;
120
+ }
121
+ const parentDir = path.dirname(currentDir);
122
+ if (parentDir === currentDir) {
123
+ // Reached root
124
+ return null;
125
+ }
126
+ currentDir = parentDir;
127
+ }
128
+ }
129
+ /**
130
+ * Load and validate a config file
131
+ *
132
+ * Uses jiti to support TypeScript config files (.ts) in addition to
133
+ * JavaScript (.js, .mjs, .cjs) without requiring the user to have
134
+ * tsx or ts-node installed.
135
+ */
136
+ async function loadConfigFile(configPath) {
137
+ if (!fs.existsSync(configPath)) {
138
+ return {
139
+ success: false,
140
+ error: `Config file not found: ${configPath}`,
141
+ };
142
+ }
143
+ try {
144
+ // Use jiti to load TypeScript/ESM config files seamlessly
145
+ // jiti handles .ts, .js, .mjs, .cjs and ESM/CJS interop
146
+ const jiti = (0, jiti_1.createJiti)(__filename, {
147
+ interopDefault: true,
148
+ debug: process.env.JITI_DEBUG === '1',
149
+ });
150
+ // jiti.import() with { default: true } returns mod?.default ?? mod
151
+ const config = await jiti.import(configPath, { default: true });
152
+ if (!config || typeof config !== 'object') {
153
+ return {
154
+ success: false,
155
+ error: 'Config file must export a configuration object',
156
+ };
157
+ }
158
+ if (!('endpoint' in config)) {
159
+ return {
160
+ success: false,
161
+ error: 'Config file missing required "endpoint" property',
162
+ };
163
+ }
164
+ return {
165
+ success: true,
166
+ config,
167
+ };
168
+ }
169
+ catch (err) {
170
+ const message = err instanceof Error ? err.message : 'Unknown error';
171
+ return {
172
+ success: false,
173
+ error: `Failed to load config file: ${message}`,
174
+ };
175
+ }
176
+ }
package/cli/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /**
2
+ * CLI entry point for graphql-codegen
3
+ */
4
+ export {};
package/cli/index.js ADDED
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+ /**
3
+ * CLI entry point for graphql-codegen
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const commander_1 = require("commander");
40
+ const init_1 = require("./commands/init");
41
+ const generate_1 = require("./commands/generate");
42
+ const generate_orm_1 = require("./commands/generate-orm");
43
+ const watch_1 = require("./watch");
44
+ const config_1 = require("../types/config");
45
+ const program = new commander_1.Command();
46
+ /**
47
+ * Load configuration for watch mode, merging CLI options with config file
48
+ */
49
+ async function loadWatchConfig(options) {
50
+ // Find config file
51
+ let configPath = options.config;
52
+ if (!configPath) {
53
+ configPath = (0, init_1.findConfigFile)() ?? undefined;
54
+ }
55
+ let baseConfig = {};
56
+ if (configPath) {
57
+ const loadResult = await (0, init_1.loadConfigFile)(configPath);
58
+ if (!loadResult.success) {
59
+ console.error('✗', loadResult.error);
60
+ return null;
61
+ }
62
+ baseConfig = loadResult.config;
63
+ }
64
+ // Merge CLI options with config
65
+ const mergedConfig = {
66
+ endpoint: options.endpoint || baseConfig.endpoint || '',
67
+ output: baseConfig.output,
68
+ headers: baseConfig.headers,
69
+ tables: baseConfig.tables,
70
+ queries: baseConfig.queries,
71
+ mutations: baseConfig.mutations,
72
+ excludeFields: baseConfig.excludeFields,
73
+ hooks: baseConfig.hooks,
74
+ postgraphile: baseConfig.postgraphile,
75
+ codegen: baseConfig.codegen,
76
+ orm: baseConfig.orm,
77
+ watch: {
78
+ ...baseConfig.watch,
79
+ // CLI options override config
80
+ ...(options.pollInterval !== undefined && { pollInterval: options.pollInterval }),
81
+ ...(options.debounce !== undefined && { debounce: options.debounce }),
82
+ ...(options.touch !== undefined && { touchFile: options.touch }),
83
+ ...(options.clear !== undefined && { clearScreen: options.clear }),
84
+ },
85
+ };
86
+ if (!mergedConfig.endpoint) {
87
+ console.error('✗ No endpoint specified. Use --endpoint or create a config file with "graphql-codegen init".');
88
+ return null;
89
+ }
90
+ return (0, config_1.resolveConfig)(mergedConfig);
91
+ }
92
+ program
93
+ .name('graphql-codegen')
94
+ .description('CLI for generating GraphQL SDK from PostGraphile endpoints')
95
+ .version('2.17.48');
96
+ // Init command
97
+ program
98
+ .command('init')
99
+ .description('Initialize a new graphql-codegen configuration file')
100
+ .option('-d, --directory <dir>', 'Target directory for the config file', '.')
101
+ .option('-f, --force', 'Force overwrite existing config', false)
102
+ .option('-e, --endpoint <url>', 'GraphQL endpoint URL to pre-populate')
103
+ .option('-o, --output <dir>', 'Output directory to pre-populate', './generated')
104
+ .action(async (options) => {
105
+ const result = await (0, init_1.initCommand)({
106
+ directory: options.directory,
107
+ force: options.force,
108
+ endpoint: options.endpoint,
109
+ output: options.output,
110
+ });
111
+ if (result.success) {
112
+ console.log('✓', result.message);
113
+ }
114
+ else {
115
+ console.error('✗', result.message);
116
+ process.exit(1);
117
+ }
118
+ });
119
+ // Generate command
120
+ program
121
+ .command('generate')
122
+ .description('Generate SDK from GraphQL endpoint')
123
+ .option('-c, --config <path>', 'Path to config file')
124
+ .option('-e, --endpoint <url>', 'GraphQL endpoint URL (overrides config)')
125
+ .option('-o, --output <dir>', 'Output directory (overrides config)')
126
+ .option('-a, --authorization <header>', 'Authorization header value')
127
+ .option('-v, --verbose', 'Verbose output', false)
128
+ .option('--dry-run', 'Dry run - show what would be generated without writing files', false)
129
+ .option('-w, --watch', 'Watch mode - poll endpoint for schema changes (in-memory)', false)
130
+ .option('--poll-interval <ms>', 'Polling interval in milliseconds (default: 3000)', parseInt)
131
+ .option('--debounce <ms>', 'Debounce delay before regenerating (default: 800)', parseInt)
132
+ .option('--touch <file>', 'File to touch on schema change')
133
+ .option('--no-clear', 'Do not clear terminal on regeneration')
134
+ .action(async (options) => {
135
+ // Watch mode
136
+ if (options.watch) {
137
+ const config = await loadWatchConfig(options);
138
+ if (!config) {
139
+ process.exit(1);
140
+ }
141
+ await (0, watch_1.startWatch)({
142
+ config,
143
+ generatorType: 'generate',
144
+ verbose: options.verbose,
145
+ authorization: options.authorization,
146
+ outputDir: options.output,
147
+ });
148
+ return;
149
+ }
150
+ // Normal one-shot generation
151
+ const result = await (0, generate_1.generateCommand)({
152
+ config: options.config,
153
+ endpoint: options.endpoint,
154
+ output: options.output,
155
+ authorization: options.authorization,
156
+ verbose: options.verbose,
157
+ dryRun: options.dryRun,
158
+ });
159
+ if (result.success) {
160
+ console.log('✓', result.message);
161
+ if (result.tables && result.tables.length > 0) {
162
+ console.log('\nTables:');
163
+ result.tables.forEach((t) => console.log(` - ${t}`));
164
+ }
165
+ if (result.filesWritten && result.filesWritten.length > 0) {
166
+ console.log('\nFiles written:');
167
+ result.filesWritten.forEach((f) => console.log(` - ${f}`));
168
+ }
169
+ }
170
+ else {
171
+ console.error('✗', result.message);
172
+ if (result.errors) {
173
+ result.errors.forEach((e) => console.error(' -', e));
174
+ }
175
+ process.exit(1);
176
+ }
177
+ });
178
+ // Generate ORM command
179
+ program
180
+ .command('generate-orm')
181
+ .description('Generate Prisma-like ORM client from GraphQL endpoint')
182
+ .option('-c, --config <path>', 'Path to config file')
183
+ .option('-e, --endpoint <url>', 'GraphQL endpoint URL (overrides config)')
184
+ .option('-o, --output <dir>', 'Output directory (overrides config)', './generated/orm')
185
+ .option('-a, --authorization <header>', 'Authorization header value')
186
+ .option('-v, --verbose', 'Verbose output', false)
187
+ .option('--dry-run', 'Dry run - show what would be generated without writing files', false)
188
+ .option('--skip-custom-operations', 'Skip custom operations (only generate table CRUD)', false)
189
+ .option('-w, --watch', 'Watch mode - poll endpoint for schema changes (in-memory)', false)
190
+ .option('--poll-interval <ms>', 'Polling interval in milliseconds (default: 3000)', parseInt)
191
+ .option('--debounce <ms>', 'Debounce delay before regenerating (default: 800)', parseInt)
192
+ .option('--touch <file>', 'File to touch on schema change')
193
+ .option('--no-clear', 'Do not clear terminal on regeneration')
194
+ .action(async (options) => {
195
+ // Watch mode
196
+ if (options.watch) {
197
+ const config = await loadWatchConfig(options);
198
+ if (!config) {
199
+ process.exit(1);
200
+ }
201
+ await (0, watch_1.startWatch)({
202
+ config,
203
+ generatorType: 'generate-orm',
204
+ verbose: options.verbose,
205
+ authorization: options.authorization,
206
+ outputDir: options.output,
207
+ skipCustomOperations: options.skipCustomOperations,
208
+ });
209
+ return;
210
+ }
211
+ // Normal one-shot generation
212
+ const result = await (0, generate_orm_1.generateOrmCommand)({
213
+ config: options.config,
214
+ endpoint: options.endpoint,
215
+ output: options.output,
216
+ authorization: options.authorization,
217
+ verbose: options.verbose,
218
+ dryRun: options.dryRun,
219
+ skipCustomOperations: options.skipCustomOperations,
220
+ });
221
+ if (result.success) {
222
+ console.log('✓', result.message);
223
+ if (result.tables && result.tables.length > 0) {
224
+ console.log('\nTables:');
225
+ result.tables.forEach((t) => console.log(` - ${t}`));
226
+ }
227
+ if (result.customQueries && result.customQueries.length > 0) {
228
+ console.log('\nCustom Queries:');
229
+ result.customQueries.forEach((q) => console.log(` - ${q}`));
230
+ }
231
+ if (result.customMutations && result.customMutations.length > 0) {
232
+ console.log('\nCustom Mutations:');
233
+ result.customMutations.forEach((m) => console.log(` - ${m}`));
234
+ }
235
+ if (result.filesWritten && result.filesWritten.length > 0) {
236
+ console.log('\nFiles written:');
237
+ result.filesWritten.forEach((f) => console.log(` - ${f}`));
238
+ }
239
+ }
240
+ else {
241
+ console.error('✗', result.message);
242
+ if (result.errors) {
243
+ result.errors.forEach((e) => console.error(' -', e));
244
+ }
245
+ process.exit(1);
246
+ }
247
+ });
248
+ // Introspect command (for debugging)
249
+ program
250
+ .command('introspect')
251
+ .description('Introspect a GraphQL endpoint and print table info')
252
+ .requiredOption('-e, --endpoint <url>', 'GraphQL endpoint URL')
253
+ .option('-a, --authorization <header>', 'Authorization header value')
254
+ .option('--json', 'Output as JSON', false)
255
+ .action(async (options) => {
256
+ const { fetchMeta, validateEndpoint } = await Promise.resolve().then(() => __importStar(require('./introspect/fetch-meta')));
257
+ const { transformMetaToCleanTables, getTableNames } = await Promise.resolve().then(() => __importStar(require('./introspect/transform')));
258
+ // Validate endpoint
259
+ const validation = validateEndpoint(options.endpoint);
260
+ if (!validation.valid) {
261
+ console.error('✗ Invalid endpoint:', validation.error);
262
+ process.exit(1);
263
+ }
264
+ console.log('Fetching schema from', options.endpoint, '...');
265
+ const result = await fetchMeta({
266
+ endpoint: options.endpoint,
267
+ authorization: options.authorization,
268
+ });
269
+ if (!result.success) {
270
+ console.error('✗ Failed to fetch schema:', result.error);
271
+ process.exit(1);
272
+ }
273
+ const tables = transformMetaToCleanTables(result.data);
274
+ const tableNames = getTableNames(tables);
275
+ if (options.json) {
276
+ console.log(JSON.stringify(tables, null, 2));
277
+ }
278
+ else {
279
+ console.log(`\n✓ Found ${tables.length} tables:\n`);
280
+ tableNames.forEach((name) => {
281
+ const table = tables.find((t) => t.name === name);
282
+ const fieldCount = table.fields.length;
283
+ const relationCount = table.relations.belongsTo.length +
284
+ table.relations.hasOne.length +
285
+ table.relations.hasMany.length +
286
+ table.relations.manyToMany.length;
287
+ console.log(` ${name} (${fieldCount} fields, ${relationCount} relations)`);
288
+ });
289
+ }
290
+ });
291
+ program.parse();
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Fetch _meta query from a PostGraphile endpoint
3
+ */
4
+ import { type MetaQueryResponse } from './meta-query';
5
+ export interface FetchMetaOptions {
6
+ /** GraphQL endpoint URL */
7
+ endpoint: string;
8
+ /** Optional authorization header value (e.g., "Bearer token") */
9
+ authorization?: string;
10
+ /** Optional additional headers */
11
+ headers?: Record<string, string>;
12
+ /** Request timeout in milliseconds (default: 30000) */
13
+ timeout?: number;
14
+ }
15
+ export interface FetchMetaResult {
16
+ success: boolean;
17
+ data?: MetaQueryResponse;
18
+ error?: string;
19
+ statusCode?: number;
20
+ }
21
+ /**
22
+ * Fetch the _meta query from a PostGraphile endpoint
23
+ */
24
+ export declare function fetchMeta(options: FetchMetaOptions): Promise<FetchMetaResult>;
25
+ /**
26
+ * Validate that an endpoint URL is valid
27
+ */
28
+ export declare function validateEndpoint(endpoint: string): {
29
+ valid: boolean;
30
+ error?: string;
31
+ };
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchMeta = fetchMeta;
4
+ exports.validateEndpoint = validateEndpoint;
5
+ /**
6
+ * Fetch _meta query from a PostGraphile endpoint
7
+ */
8
+ const meta_query_1 = require("./meta-query");
9
+ /**
10
+ * Fetch the _meta query from a PostGraphile endpoint
11
+ */
12
+ async function fetchMeta(options) {
13
+ const { endpoint, authorization, headers = {}, timeout = 30000 } = options;
14
+ // Build headers
15
+ const requestHeaders = {
16
+ 'Content-Type': 'application/json',
17
+ Accept: 'application/json',
18
+ ...headers,
19
+ };
20
+ if (authorization) {
21
+ requestHeaders['Authorization'] = authorization;
22
+ }
23
+ // Create abort controller for timeout
24
+ const controller = new AbortController();
25
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
26
+ try {
27
+ const response = await fetch(endpoint, {
28
+ method: 'POST',
29
+ headers: requestHeaders,
30
+ body: JSON.stringify({
31
+ query: meta_query_1.META_QUERY,
32
+ variables: {},
33
+ }),
34
+ signal: controller.signal,
35
+ });
36
+ clearTimeout(timeoutId);
37
+ if (!response.ok) {
38
+ return {
39
+ success: false,
40
+ error: `HTTP ${response.status}: ${response.statusText}`,
41
+ statusCode: response.status,
42
+ };
43
+ }
44
+ const json = (await response.json());
45
+ // Check for GraphQL errors
46
+ if (json.errors && json.errors.length > 0) {
47
+ const errorMessages = json.errors.map((e) => e.message).join('; ');
48
+ return {
49
+ success: false,
50
+ error: `GraphQL errors: ${errorMessages}`,
51
+ statusCode: response.status,
52
+ };
53
+ }
54
+ // Check if _meta is present
55
+ if (!json.data?._meta) {
56
+ return {
57
+ success: false,
58
+ error: 'No _meta field in response. Make sure the endpoint has the PostGraphile meta plugin installed.',
59
+ statusCode: response.status,
60
+ };
61
+ }
62
+ return {
63
+ success: true,
64
+ data: json.data,
65
+ statusCode: response.status,
66
+ };
67
+ }
68
+ catch (err) {
69
+ clearTimeout(timeoutId);
70
+ if (err instanceof Error) {
71
+ if (err.name === 'AbortError') {
72
+ return {
73
+ success: false,
74
+ error: `Request timeout after ${timeout}ms`,
75
+ };
76
+ }
77
+ return {
78
+ success: false,
79
+ error: err.message,
80
+ };
81
+ }
82
+ return {
83
+ success: false,
84
+ error: 'Unknown error occurred',
85
+ };
86
+ }
87
+ }
88
+ /**
89
+ * Validate that an endpoint URL is valid
90
+ */
91
+ function validateEndpoint(endpoint) {
92
+ try {
93
+ const url = new URL(endpoint);
94
+ if (!['http:', 'https:'].includes(url.protocol)) {
95
+ return {
96
+ valid: false,
97
+ error: 'Endpoint must use http or https protocol',
98
+ };
99
+ }
100
+ return { valid: true };
101
+ }
102
+ catch {
103
+ return {
104
+ valid: false,
105
+ error: 'Invalid URL format',
106
+ };
107
+ }
108
+ }
@@ -0,0 +1,21 @@
1
+ import type { IntrospectionQueryResponse } from '../../types/introspection';
2
+ export interface FetchSchemaOptions {
3
+ /** GraphQL endpoint URL */
4
+ endpoint: string;
5
+ /** Optional authorization header value (e.g., "Bearer token") */
6
+ authorization?: string;
7
+ /** Optional additional headers */
8
+ headers?: Record<string, string>;
9
+ /** Request timeout in milliseconds (default: 30000) */
10
+ timeout?: number;
11
+ }
12
+ export interface FetchSchemaResult {
13
+ success: boolean;
14
+ data?: IntrospectionQueryResponse;
15
+ error?: string;
16
+ statusCode?: number;
17
+ }
18
+ /**
19
+ * Fetch the full schema introspection from a GraphQL endpoint
20
+ */
21
+ export declare function fetchSchema(options: FetchSchemaOptions): Promise<FetchSchemaResult>;