@constructive-io/graphql-codegen 2.32.0 → 3.0.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 (270) hide show
  1. package/README.md +429 -1691
  2. package/cli/index.d.ts +5 -2
  3. package/cli/index.js +98 -581
  4. package/cli/shared.d.ts +35 -0
  5. package/cli/shared.js +106 -0
  6. package/{esm/cli → core}/codegen/barrel.d.ts +1 -1
  7. package/{cli → core}/codegen/barrel.js +1 -4
  8. package/{esm/cli → core}/codegen/index.d.ts +15 -5
  9. package/{cli → core}/codegen/index.js +44 -24
  10. package/{cli → core}/codegen/invalidation.d.ts +2 -2
  11. package/{esm/cli → core}/codegen/mutation-keys.d.ts +2 -2
  12. package/{cli → core}/codegen/orm/client-generator.js +2 -3
  13. package/{esm/cli → core}/codegen/orm/index.d.ts +9 -2
  14. package/{cli → core}/codegen/orm/index.js +3 -2
  15. package/{cli → core}/codegen/query-keys.d.ts +2 -2
  16. package/core/codegen/shared/index.d.ts +39 -0
  17. package/core/codegen/shared/index.js +118 -0
  18. package/core/config/index.d.ts +5 -0
  19. package/core/config/index.js +13 -0
  20. package/core/config/loader.d.ts +18 -0
  21. package/{cli/commands/init.js → core/config/loader.js} +7 -94
  22. package/core/config/resolver.d.ts +46 -0
  23. package/core/config/resolver.js +104 -0
  24. package/core/database/index.d.ts +43 -0
  25. package/core/database/index.js +85 -0
  26. package/core/generate.d.ts +22 -0
  27. package/core/generate.js +192 -0
  28. package/core/index.d.ts +13 -1
  29. package/core/index.js +22 -2
  30. package/{cli → core}/introspect/fetch-schema.js +58 -9
  31. package/core/introspect/source/api-schemas.d.ts +44 -0
  32. package/core/introspect/source/api-schemas.js +122 -0
  33. package/core/introspect/source/database.d.ts +32 -0
  34. package/core/introspect/source/database.js +91 -0
  35. package/core/introspect/source/index.d.ts +112 -0
  36. package/core/introspect/source/index.js +173 -0
  37. package/core/introspect/source/pgpm-module.d.ts +83 -0
  38. package/core/introspect/source/pgpm-module.js +200 -0
  39. package/core/output/index.d.ts +4 -0
  40. package/core/output/index.js +9 -0
  41. package/core/output/writer.d.ts +38 -0
  42. package/core/output/writer.js +156 -0
  43. package/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
  44. package/{cli/commands/shared.js → core/pipeline/index.js} +4 -0
  45. package/{cli → core}/watch/orchestrator.d.ts +25 -3
  46. package/{cli → core}/watch/orchestrator.js +35 -27
  47. package/{cli → core}/watch/types.d.ts +1 -1
  48. package/esm/cli/index.d.ts +5 -2
  49. package/esm/cli/index.js +97 -547
  50. package/esm/cli/shared.d.ts +35 -0
  51. package/esm/cli/shared.js +101 -0
  52. package/{cli → esm/core}/codegen/barrel.d.ts +1 -1
  53. package/esm/{cli → core}/codegen/barrel.js +1 -4
  54. package/{cli → esm/core}/codegen/index.d.ts +15 -5
  55. package/esm/{cli → core}/codegen/index.js +44 -24
  56. package/esm/{cli → core}/codegen/invalidation.d.ts +2 -2
  57. package/{cli → esm/core}/codegen/mutation-keys.d.ts +2 -2
  58. package/esm/{cli → core}/codegen/orm/client-generator.js +2 -3
  59. package/{cli → esm/core}/codegen/orm/index.d.ts +9 -2
  60. package/esm/{cli → core}/codegen/orm/index.js +3 -2
  61. package/esm/{cli → core}/codegen/query-keys.d.ts +2 -2
  62. package/esm/core/codegen/shared/index.d.ts +39 -0
  63. package/esm/core/codegen/shared/index.js +79 -0
  64. package/esm/core/config/index.d.ts +5 -0
  65. package/esm/core/config/index.js +5 -0
  66. package/esm/core/config/loader.d.ts +18 -0
  67. package/esm/core/config/loader.js +71 -0
  68. package/esm/core/config/resolver.d.ts +46 -0
  69. package/esm/core/config/resolver.js +100 -0
  70. package/esm/core/database/index.d.ts +43 -0
  71. package/esm/core/database/index.js +48 -0
  72. package/esm/core/generate.d.ts +22 -0
  73. package/esm/core/generate.js +186 -0
  74. package/esm/core/index.d.ts +13 -1
  75. package/esm/core/index.js +20 -1
  76. package/esm/{cli → core}/introspect/fetch-schema.js +55 -9
  77. package/esm/core/introspect/source/api-schemas.d.ts +44 -0
  78. package/esm/core/introspect/source/api-schemas.js +117 -0
  79. package/esm/core/introspect/source/database.d.ts +32 -0
  80. package/esm/core/introspect/source/database.js +87 -0
  81. package/esm/core/introspect/source/index.d.ts +112 -0
  82. package/esm/core/introspect/source/index.js +154 -0
  83. package/esm/core/introspect/source/pgpm-module.d.ts +83 -0
  84. package/esm/core/introspect/source/pgpm-module.js +194 -0
  85. package/esm/core/output/index.d.ts +4 -0
  86. package/esm/core/output/index.js +4 -0
  87. package/esm/core/output/writer.d.ts +38 -0
  88. package/esm/core/output/writer.js +119 -0
  89. package/esm/{cli/commands/shared.d.ts → core/pipeline/index.d.ts} +5 -3
  90. package/esm/{cli/commands/shared.js → core/pipeline/index.js} +1 -0
  91. package/esm/{cli → core}/watch/orchestrator.d.ts +25 -3
  92. package/esm/{cli → core}/watch/orchestrator.js +35 -27
  93. package/esm/{cli → core}/watch/types.d.ts +1 -1
  94. package/esm/index.d.ts +8 -3
  95. package/esm/index.js +9 -3
  96. package/esm/types/config.d.ts +101 -138
  97. package/esm/types/config.js +8 -35
  98. package/esm/types/index.d.ts +2 -2
  99. package/esm/types/index.js +1 -1
  100. package/index.d.ts +8 -3
  101. package/index.js +18 -8
  102. package/package.json +18 -11
  103. package/types/config.d.ts +101 -138
  104. package/types/config.js +9 -38
  105. package/types/index.d.ts +2 -2
  106. package/types/index.js +3 -3
  107. package/cli/commands/generate-orm.d.ts +0 -53
  108. package/cli/commands/generate-orm.js +0 -292
  109. package/cli/commands/generate.d.ts +0 -66
  110. package/cli/commands/generate.js +0 -431
  111. package/cli/commands/index.d.ts +0 -9
  112. package/cli/commands/index.js +0 -14
  113. package/cli/commands/init.d.ts +0 -35
  114. package/cli/introspect/source/index.d.ts +0 -48
  115. package/cli/introspect/source/index.js +0 -72
  116. package/esm/cli/commands/generate-orm.d.ts +0 -53
  117. package/esm/cli/commands/generate-orm.js +0 -289
  118. package/esm/cli/commands/generate.d.ts +0 -66
  119. package/esm/cli/commands/generate.js +0 -393
  120. package/esm/cli/commands/index.d.ts +0 -9
  121. package/esm/cli/commands/index.js +0 -6
  122. package/esm/cli/commands/init.d.ts +0 -35
  123. package/esm/cli/commands/init.js +0 -158
  124. package/esm/cli/introspect/source/index.d.ts +0 -48
  125. package/esm/cli/introspect/source/index.js +0 -54
  126. /package/{cli → core}/codegen/babel-ast.d.ts +0 -0
  127. /package/{cli → core}/codegen/babel-ast.js +0 -0
  128. /package/{cli → core}/codegen/client.d.ts +0 -0
  129. /package/{cli → core}/codegen/client.js +0 -0
  130. /package/{cli → core}/codegen/custom-mutations.d.ts +0 -0
  131. /package/{cli → core}/codegen/custom-mutations.js +0 -0
  132. /package/{cli → core}/codegen/custom-queries.d.ts +0 -0
  133. /package/{cli → core}/codegen/custom-queries.js +0 -0
  134. /package/{cli → core}/codegen/gql-ast.d.ts +0 -0
  135. /package/{cli → core}/codegen/gql-ast.js +0 -0
  136. /package/{cli → core}/codegen/invalidation.js +0 -0
  137. /package/{cli → core}/codegen/mutation-keys.js +0 -0
  138. /package/{cli → core}/codegen/mutations.d.ts +0 -0
  139. /package/{cli → core}/codegen/mutations.js +0 -0
  140. /package/{cli → core}/codegen/orm/barrel.d.ts +0 -0
  141. /package/{cli → core}/codegen/orm/barrel.js +0 -0
  142. /package/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
  143. /package/{cli → core}/codegen/orm/client.d.ts +0 -0
  144. /package/{cli → core}/codegen/orm/client.js +0 -0
  145. /package/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
  146. /package/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
  147. /package/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
  148. /package/{cli → core}/codegen/orm/input-types-generator.js +0 -0
  149. /package/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
  150. /package/{cli → core}/codegen/orm/model-generator.js +0 -0
  151. /package/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
  152. /package/{cli → core}/codegen/orm/query-builder.js +0 -0
  153. /package/{cli → core}/codegen/orm/query-builder.ts +0 -0
  154. /package/{cli → core}/codegen/orm/select-types.d.ts +0 -0
  155. /package/{cli → core}/codegen/orm/select-types.js +0 -0
  156. /package/{cli → core}/codegen/queries.d.ts +0 -0
  157. /package/{cli → core}/codegen/queries.js +0 -0
  158. /package/{cli → core}/codegen/query-keys.js +0 -0
  159. /package/{cli → core}/codegen/scalars.d.ts +0 -0
  160. /package/{cli → core}/codegen/scalars.js +0 -0
  161. /package/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
  162. /package/{cli → core}/codegen/schema-gql-ast.js +0 -0
  163. /package/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
  164. /package/{cli → core}/codegen/schema-types-generator.js +0 -0
  165. /package/{cli → core}/codegen/type-resolver.d.ts +0 -0
  166. /package/{cli → core}/codegen/type-resolver.js +0 -0
  167. /package/{cli → core}/codegen/types.d.ts +0 -0
  168. /package/{cli → core}/codegen/types.js +0 -0
  169. /package/{cli → core}/codegen/utils.d.ts +0 -0
  170. /package/{cli → core}/codegen/utils.js +0 -0
  171. /package/{cli → core}/introspect/fetch-schema.d.ts +0 -0
  172. /package/{cli → core}/introspect/index.d.ts +0 -0
  173. /package/{cli → core}/introspect/index.js +0 -0
  174. /package/{cli → core}/introspect/infer-tables.d.ts +0 -0
  175. /package/{cli → core}/introspect/infer-tables.js +0 -0
  176. /package/{cli → core}/introspect/schema-query.d.ts +0 -0
  177. /package/{cli → core}/introspect/schema-query.js +0 -0
  178. /package/{cli → core}/introspect/source/endpoint.d.ts +0 -0
  179. /package/{cli → core}/introspect/source/endpoint.js +0 -0
  180. /package/{cli → core}/introspect/source/file.d.ts +0 -0
  181. /package/{cli → core}/introspect/source/file.js +0 -0
  182. /package/{cli → core}/introspect/source/types.d.ts +0 -0
  183. /package/{cli → core}/introspect/source/types.js +0 -0
  184. /package/{cli → core}/introspect/transform-schema.d.ts +0 -0
  185. /package/{cli → core}/introspect/transform-schema.js +0 -0
  186. /package/{cli → core}/introspect/transform.d.ts +0 -0
  187. /package/{cli → core}/introspect/transform.js +0 -0
  188. /package/{cli → core}/watch/cache.d.ts +0 -0
  189. /package/{cli → core}/watch/cache.js +0 -0
  190. /package/{cli → core}/watch/debounce.d.ts +0 -0
  191. /package/{cli → core}/watch/debounce.js +0 -0
  192. /package/{cli → core}/watch/hash.d.ts +0 -0
  193. /package/{cli → core}/watch/hash.js +0 -0
  194. /package/{cli → core}/watch/index.d.ts +0 -0
  195. /package/{cli → core}/watch/index.js +0 -0
  196. /package/{cli → core}/watch/poller.d.ts +0 -0
  197. /package/{cli → core}/watch/poller.js +0 -0
  198. /package/{cli → core}/watch/types.js +0 -0
  199. /package/esm/{cli → core}/codegen/babel-ast.d.ts +0 -0
  200. /package/esm/{cli → core}/codegen/babel-ast.js +0 -0
  201. /package/esm/{cli → core}/codegen/client.d.ts +0 -0
  202. /package/esm/{cli → core}/codegen/client.js +0 -0
  203. /package/esm/{cli → core}/codegen/custom-mutations.d.ts +0 -0
  204. /package/esm/{cli → core}/codegen/custom-mutations.js +0 -0
  205. /package/esm/{cli → core}/codegen/custom-queries.d.ts +0 -0
  206. /package/esm/{cli → core}/codegen/custom-queries.js +0 -0
  207. /package/esm/{cli → core}/codegen/gql-ast.d.ts +0 -0
  208. /package/esm/{cli → core}/codegen/gql-ast.js +0 -0
  209. /package/esm/{cli → core}/codegen/invalidation.js +0 -0
  210. /package/esm/{cli → core}/codegen/mutation-keys.js +0 -0
  211. /package/esm/{cli → core}/codegen/mutations.d.ts +0 -0
  212. /package/esm/{cli → core}/codegen/mutations.js +0 -0
  213. /package/esm/{cli → core}/codegen/orm/barrel.d.ts +0 -0
  214. /package/esm/{cli → core}/codegen/orm/barrel.js +0 -0
  215. /package/esm/{cli → core}/codegen/orm/client-generator.d.ts +0 -0
  216. /package/esm/{cli → core}/codegen/orm/client.d.ts +0 -0
  217. /package/esm/{cli → core}/codegen/orm/client.js +0 -0
  218. /package/esm/{cli → core}/codegen/orm/custom-ops-generator.d.ts +0 -0
  219. /package/esm/{cli → core}/codegen/orm/custom-ops-generator.js +0 -0
  220. /package/esm/{cli → core}/codegen/orm/input-types-generator.d.ts +0 -0
  221. /package/esm/{cli → core}/codegen/orm/input-types-generator.js +0 -0
  222. /package/esm/{cli → core}/codegen/orm/model-generator.d.ts +0 -0
  223. /package/esm/{cli → core}/codegen/orm/model-generator.js +0 -0
  224. /package/esm/{cli → core}/codegen/orm/query-builder.d.ts +0 -0
  225. /package/esm/{cli → core}/codegen/orm/query-builder.js +0 -0
  226. /package/esm/{cli → core}/codegen/orm/select-types.d.ts +0 -0
  227. /package/esm/{cli → core}/codegen/orm/select-types.js +0 -0
  228. /package/esm/{cli → core}/codegen/queries.d.ts +0 -0
  229. /package/esm/{cli → core}/codegen/queries.js +0 -0
  230. /package/esm/{cli → core}/codegen/query-keys.js +0 -0
  231. /package/esm/{cli → core}/codegen/scalars.d.ts +0 -0
  232. /package/esm/{cli → core}/codegen/scalars.js +0 -0
  233. /package/esm/{cli → core}/codegen/schema-gql-ast.d.ts +0 -0
  234. /package/esm/{cli → core}/codegen/schema-gql-ast.js +0 -0
  235. /package/esm/{cli → core}/codegen/schema-types-generator.d.ts +0 -0
  236. /package/esm/{cli → core}/codegen/schema-types-generator.js +0 -0
  237. /package/esm/{cli → core}/codegen/type-resolver.d.ts +0 -0
  238. /package/esm/{cli → core}/codegen/type-resolver.js +0 -0
  239. /package/esm/{cli → core}/codegen/types.d.ts +0 -0
  240. /package/esm/{cli → core}/codegen/types.js +0 -0
  241. /package/esm/{cli → core}/codegen/utils.d.ts +0 -0
  242. /package/esm/{cli → core}/codegen/utils.js +0 -0
  243. /package/esm/{cli → core}/introspect/fetch-schema.d.ts +0 -0
  244. /package/esm/{cli → core}/introspect/index.d.ts +0 -0
  245. /package/esm/{cli → core}/introspect/index.js +0 -0
  246. /package/esm/{cli → core}/introspect/infer-tables.d.ts +0 -0
  247. /package/esm/{cli → core}/introspect/infer-tables.js +0 -0
  248. /package/esm/{cli → core}/introspect/schema-query.d.ts +0 -0
  249. /package/esm/{cli → core}/introspect/schema-query.js +0 -0
  250. /package/esm/{cli → core}/introspect/source/endpoint.d.ts +0 -0
  251. /package/esm/{cli → core}/introspect/source/endpoint.js +0 -0
  252. /package/esm/{cli → core}/introspect/source/file.d.ts +0 -0
  253. /package/esm/{cli → core}/introspect/source/file.js +0 -0
  254. /package/esm/{cli → core}/introspect/source/types.d.ts +0 -0
  255. /package/esm/{cli → core}/introspect/source/types.js +0 -0
  256. /package/esm/{cli → core}/introspect/transform-schema.d.ts +0 -0
  257. /package/esm/{cli → core}/introspect/transform-schema.js +0 -0
  258. /package/esm/{cli → core}/introspect/transform.d.ts +0 -0
  259. /package/esm/{cli → core}/introspect/transform.js +0 -0
  260. /package/esm/{cli → core}/watch/cache.d.ts +0 -0
  261. /package/esm/{cli → core}/watch/cache.js +0 -0
  262. /package/esm/{cli → core}/watch/debounce.d.ts +0 -0
  263. /package/esm/{cli → core}/watch/debounce.js +0 -0
  264. /package/esm/{cli → core}/watch/hash.d.ts +0 -0
  265. /package/esm/{cli → core}/watch/hash.js +0 -0
  266. /package/esm/{cli → core}/watch/index.d.ts +0 -0
  267. /package/esm/{cli → core}/watch/index.js +0 -0
  268. /package/esm/{cli → core}/watch/poller.d.ts +0 -0
  269. /package/esm/{cli → core}/watch/poller.js +0 -0
  270. /package/esm/{cli → core}/watch/types.js +0 -0
package/cli/index.js CHANGED
@@ -1,588 +1,114 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.options = exports.commands = void 0;
3
5
  /**
4
6
  * CLI entry point for graphql-codegen
7
+ *
8
+ * This is a thin wrapper around the core generate() function.
9
+ * All business logic is in the core modules.
5
10
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || (function () {
23
- var ownKeys = function(o) {
24
- ownKeys = Object.getOwnPropertyNames || function (o) {
25
- var ar = [];
26
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
27
- return ar;
28
- };
29
- return ownKeys(o);
30
- };
31
- return function (mod) {
32
- if (mod && mod.__esModule) return mod;
33
- var result = {};
34
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
35
- __setModuleDefault(result, mod);
36
- return result;
37
- };
38
- })();
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.options = exports.commands = void 0;
41
11
  const inquirerer_1 = require("inquirerer");
42
- const init_1 = require("./commands/init");
43
- const generate_1 = require("./commands/generate");
44
- const generate_orm_1 = require("./commands/generate-orm");
45
- const watch_1 = require("./watch");
46
- const config_1 = require("../types/config");
47
- const usageText = `
48
- graphql-codegen - CLI for generating GraphQL SDK from PostGraphile endpoints or schema files
12
+ const generate_1 = require("../core/generate");
13
+ const config_1 = require("../core/config");
14
+ const shared_1 = require("./shared");
15
+ const usage = `
16
+ graphql-codegen - GraphQL SDK generator for Constructive databases
49
17
 
50
18
  Usage:
51
- graphql-codegen <command> [options]
19
+ graphql-codegen [options]
52
20
 
53
- Commands:
54
- init Initialize a new graphql-codegen configuration file
55
- generate Generate SDK from GraphQL endpoint or schema file
56
- generate-orm Generate Prisma-like ORM client from GraphQL endpoint or schema file
57
- introspect Introspect a GraphQL endpoint or schema file and print table info
21
+ Source Options (choose one):
22
+ -c, --config <path> Path to config file
23
+ -e, --endpoint <url> GraphQL endpoint URL
24
+ -s, --schema-file <path> Path to GraphQL schema file
58
25
 
59
- Options:
60
- --help, -h Show this help message
61
- --version, -v Show version number
26
+ Database Options:
27
+ --schemas <list> Comma-separated PostgreSQL schemas
28
+ --api-names <list> Comma-separated API names (mutually exclusive with --schemas)
62
29
 
63
- Run 'graphql-codegen <command> --help' for more information on a command.
64
- `;
65
- const initUsageText = `
66
- graphql-codegen init - Initialize a new graphql-codegen configuration file
67
-
68
- Usage:
69
- graphql-codegen init [options]
30
+ Generator Options:
31
+ --react-query Generate React Query hooks
32
+ --orm Generate ORM client
33
+ -o, --output <dir> Output directory
34
+ -t, --target <name> Target name (for multi-target configs)
35
+ -a, --authorization <token> Authorization header value
36
+ --dry-run Preview without writing files
37
+ -v, --verbose Show detailed output
70
38
 
71
- Options:
72
- --directory, -d <dir> Target directory for the config file (default: .)
73
- --force, -f Force overwrite existing config
74
- --endpoint, -e <url> GraphQL endpoint URL to pre-populate
75
- --output, -o <dir> Output directory to pre-populate (default: ./generated)
76
- --help, -h Show this help message
39
+ -h, --help Show this help message
40
+ --version Show version number
77
41
  `;
78
- const generateUsageText = `
79
- graphql-codegen generate - Generate SDK from GraphQL endpoint or schema file
80
-
81
- Usage:
82
- graphql-codegen generate [options]
83
-
84
- Options:
85
- --config, -c <path> Path to config file
86
- --target, -t <name> Target name in config file
87
- --endpoint, -e <url> GraphQL endpoint URL (overrides config)
88
- --schema, -s <path> Path to GraphQL schema file (.graphql)
89
- --output, -o <dir> Output directory (overrides config)
90
- --authorization, -a <header> Authorization header value
91
- --verbose, -v Verbose output
92
- --dry-run Dry run - show what would be generated without writing files
93
- --watch, -w Watch mode - poll endpoint for schema changes (in-memory)
94
- --poll-interval <ms> Polling interval in milliseconds (default: 3000)
95
- --debounce <ms> Debounce delay before regenerating (default: 800)
96
- --touch <file> File to touch on schema change
97
- --no-clear Do not clear terminal on regeneration
98
- --help, -h Show this help message
99
- `;
100
- const generateOrmUsageText = `
101
- graphql-codegen generate-orm - Generate Prisma-like ORM client from GraphQL endpoint or schema file
102
-
103
- Usage:
104
- graphql-codegen generate-orm [options]
105
-
106
- Options:
107
- --config, -c <path> Path to config file
108
- --target, -t <name> Target name in config file
109
- --endpoint, -e <url> GraphQL endpoint URL (overrides config)
110
- --schema, -s <path> Path to GraphQL schema file (.graphql)
111
- --output, -o <dir> Output directory (overrides config)
112
- --authorization, -a <header> Authorization header value
113
- --verbose, -v Verbose output
114
- --dry-run Dry run - show what would be generated without writing files
115
- --skip-custom-operations Skip custom operations (only generate table CRUD)
116
- --watch, -w Watch mode - poll endpoint for schema changes (in-memory)
117
- --poll-interval <ms> Polling interval in milliseconds (default: 3000)
118
- --debounce <ms> Debounce delay before regenerating (default: 800)
119
- --touch <file> File to touch on schema change
120
- --no-clear Do not clear terminal on regeneration
121
- --help, -h Show this help message
122
- `;
123
- const introspectUsageText = `
124
- graphql-codegen introspect - Introspect a GraphQL endpoint or schema file and print table info
125
-
126
- Usage:
127
- graphql-codegen introspect [options]
128
-
129
- Options:
130
- --endpoint, -e <url> GraphQL endpoint URL
131
- --schema, -s <path> Path to GraphQL schema file (.graphql)
132
- --authorization, -a <header> Authorization header value
133
- --json Output as JSON
134
- --help, -h Show this help message
135
- `;
136
- /**
137
- * Format duration in a human-readable way
138
- * - Under 1 second: show milliseconds (e.g., "123ms")
139
- * - Over 1 second: show seconds with 2 decimal places (e.g., "1.23s")
140
- */
141
- function formatDuration(ms) {
142
- if (ms < 1000) {
143
- return `${Math.round(ms)}ms`;
144
- }
145
- return `${(ms / 1000).toFixed(2)}s`;
146
- }
147
- /**
148
- * Load configuration for watch mode, merging CLI options with config file
149
- */
150
- async function loadWatchConfig(options) {
151
- let configPath = options.config;
152
- if (!configPath) {
153
- configPath = (0, init_1.findConfigFile)() ?? undefined;
154
- }
155
- let baseConfig = {};
156
- if (configPath) {
157
- const loadResult = await (0, init_1.loadConfigFile)(configPath);
158
- if (!loadResult.success) {
159
- console.error('x', loadResult.error);
160
- return null;
161
- }
162
- baseConfig = loadResult.config;
163
- }
164
- if ((0, config_1.isMultiConfig)(baseConfig)) {
165
- if (!options.target) {
166
- console.error('x Watch mode requires --target when using multiple targets.');
167
- return null;
168
- }
169
- if (!baseConfig.targets[options.target]) {
170
- console.error(`x Target "${options.target}" not found in config file.`);
171
- return null;
172
- }
173
- }
174
- else if (options.target) {
175
- console.error('x Config file does not define targets. Remove --target.');
176
- return null;
177
- }
178
- const sourceOverrides = {};
179
- if (options.endpoint) {
180
- sourceOverrides.endpoint = options.endpoint;
181
- sourceOverrides.schema = undefined;
182
- }
183
- const watchOverrides = {
184
- watch: {
185
- ...(options.pollInterval !== undefined && {
186
- pollInterval: options.pollInterval,
187
- }),
188
- ...(options.debounce !== undefined && { debounce: options.debounce }),
189
- ...(options.touch !== undefined && { touchFile: options.touch }),
190
- ...(options.clear !== undefined && { clearScreen: options.clear }),
191
- },
192
- };
193
- let mergedTarget;
194
- if ((0, config_1.isMultiConfig)(baseConfig)) {
195
- const defaults = baseConfig.defaults ?? {};
196
- const targetConfig = baseConfig.targets[options.target];
197
- mergedTarget = (0, config_1.mergeConfig)(defaults, targetConfig);
198
- }
199
- else {
200
- mergedTarget = baseConfig;
201
- }
202
- mergedTarget = (0, config_1.mergeConfig)(mergedTarget, sourceOverrides);
203
- mergedTarget = (0, config_1.mergeConfig)(mergedTarget, watchOverrides);
204
- if (!mergedTarget.endpoint) {
205
- console.error('x No endpoint specified. Watch mode only supports live endpoints.');
206
- return null;
207
- }
208
- if (mergedTarget.schema) {
209
- console.error('x Watch mode is only supported with an endpoint, not schema.');
210
- return null;
211
- }
212
- return (0, config_1.resolveConfig)(mergedTarget);
213
- }
214
- /**
215
- * Init command handler
216
- */
217
- async function handleInit(argv) {
218
- if (argv.help || argv.h) {
219
- console.log(initUsageText);
42
+ const commands = async (argv, prompter, _options) => {
43
+ if (argv.version) {
44
+ const pkg = (0, inquirerer_1.getPackageJson)(__dirname);
45
+ console.log(pkg.version);
220
46
  process.exit(0);
221
47
  }
222
- const startTime = performance.now();
223
- const result = await (0, init_1.initCommand)({
224
- directory: argv.directory || argv.d || '.',
225
- force: !!(argv.force || argv.f),
226
- endpoint: argv.endpoint || argv.e,
227
- output: argv.output || argv.o || './generated',
228
- });
229
- const duration = formatDuration(performance.now() - startTime);
230
- if (result.success) {
231
- console.log('[ok]', result.message, `(${duration})`);
232
- }
233
- else {
234
- console.error('x', result.message, `(${duration})`);
235
- process.exit(1);
236
- }
237
- }
238
- /**
239
- * Generate command handler
240
- */
241
- async function handleGenerate(argv) {
242
48
  if (argv.help || argv.h) {
243
- console.log(generateUsageText);
49
+ console.log(usage);
244
50
  process.exit(0);
245
51
  }
246
- const startTime = performance.now();
247
- const config = argv.config || argv.c;
248
- const target = argv.target || argv.t;
249
- const endpoint = argv.endpoint || argv.e;
250
- const schema = argv.schema || argv.s;
251
- const output = argv.output || argv.o;
252
- const authorization = argv.authorization || argv.a;
253
- const verbose = !!(argv.verbose || argv.v);
254
- const dryRun = !!(argv['dry-run'] || argv.dryRun);
255
- const watch = !!(argv.watch || argv.w);
256
- const pollInterval = argv['poll-interval'] !== undefined
257
- ? parseInt(argv['poll-interval'], 10)
258
- : undefined;
259
- const debounce = argv.debounce !== undefined
260
- ? parseInt(argv.debounce, 10)
261
- : undefined;
262
- const touch = argv.touch;
263
- const clear = argv.clear !== false;
264
- if (endpoint && schema) {
265
- console.error('x Cannot use both --endpoint and --schema. Choose one source.');
266
- process.exit(1);
267
- }
268
- if (watch) {
269
- if (schema) {
270
- console.error('x Watch mode is only supported with --endpoint, not --schema.');
271
- process.exit(1);
272
- }
273
- const watchConfig = await loadWatchConfig({
274
- config,
275
- target,
276
- endpoint,
277
- output,
278
- pollInterval,
279
- debounce,
280
- touch,
281
- clear,
282
- });
283
- if (!watchConfig) {
284
- process.exit(1);
285
- }
286
- await (0, watch_1.startWatch)({
287
- config: watchConfig,
288
- generatorType: 'generate',
289
- verbose,
290
- authorization,
291
- configPath: config,
292
- target,
293
- outputDir: output,
294
- });
295
- return;
296
- }
297
- const result = await (0, generate_1.generateReactQuery)({
298
- config,
299
- target,
300
- endpoint,
301
- schema,
302
- output,
303
- authorization,
304
- verbose,
305
- dryRun,
306
- });
307
- const duration = formatDuration(performance.now() - startTime);
308
- const targetResults = result.targets ?? [];
309
- const hasNamedTargets = targetResults.length > 0 &&
310
- (targetResults.length > 1 || targetResults[0]?.name !== 'default');
311
- if (hasNamedTargets) {
312
- console.log(result.success ? '[ok]' : 'x', result.message);
313
- targetResults.forEach((t) => {
314
- const status = t.success ? '[ok]' : 'x';
315
- console.log(`\n${status} ${t.message}`);
316
- if (t.tables && t.tables.length > 0) {
317
- console.log(' Tables:');
318
- t.tables.forEach((table) => console.log(` - ${table}`));
319
- }
320
- if (t.filesWritten && t.filesWritten.length > 0) {
321
- console.log(' Files written:');
322
- t.filesWritten.forEach((file) => console.log(` - ${file}`));
323
- }
324
- if (!t.success && t.errors) {
325
- t.errors.forEach((error) => console.error(` - ${error}`));
326
- }
327
- });
328
- if (!result.success) {
329
- process.exit(1);
330
- }
331
- return;
332
- }
333
- if (result.success) {
334
- console.log('[ok]', result.message, `(${duration})`);
335
- if (result.tables && result.tables.length > 0) {
336
- console.log('\nTables:');
337
- result.tables.forEach((t) => console.log(` - ${t}`));
338
- }
339
- if (result.filesWritten && result.filesWritten.length > 0) {
340
- console.log('\nFiles written:');
341
- result.filesWritten.forEach((f) => console.log(` - ${f}`));
342
- }
343
- }
344
- else {
345
- console.error('x', result.message, `(${duration})`);
346
- if (result.errors) {
347
- result.errors.forEach((e) => console.error(' -', e));
348
- }
349
- process.exit(1);
350
- }
351
- }
352
- /**
353
- * Generate ORM command handler
354
- */
355
- async function handleGenerateOrm(argv) {
356
- if (argv.help || argv.h) {
357
- console.log(generateOrmUsageText);
358
- process.exit(0);
359
- }
360
- const startTime = performance.now();
361
- const config = argv.config || argv.c;
362
- const target = argv.target || argv.t;
363
- const endpoint = argv.endpoint || argv.e;
364
- const schema = argv.schema || argv.s;
365
- const output = argv.output || argv.o;
366
- const authorization = argv.authorization || argv.a;
367
- const verbose = !!(argv.verbose || argv.v);
368
- const dryRun = !!(argv['dry-run'] || argv.dryRun);
369
- const skipCustomOperations = !!(argv['skip-custom-operations'] || argv.skipCustomOperations);
370
- const watch = !!(argv.watch || argv.w);
371
- const pollInterval = argv['poll-interval'] !== undefined
372
- ? parseInt(argv['poll-interval'], 10)
373
- : undefined;
374
- const debounce = argv.debounce !== undefined
375
- ? parseInt(argv.debounce, 10)
376
- : undefined;
377
- const touch = argv.touch;
378
- const clear = argv.clear !== false;
379
- if (endpoint && schema) {
380
- console.error('x Cannot use both --endpoint and --schema. Choose one source.');
381
- process.exit(1);
382
- }
383
- if (watch) {
384
- if (schema) {
385
- console.error('x Watch mode is only supported with --endpoint, not --schema.');
386
- process.exit(1);
387
- }
388
- const watchConfig = await loadWatchConfig({
389
- config,
390
- target,
391
- endpoint,
392
- output,
393
- pollInterval,
394
- debounce,
395
- touch,
396
- clear,
397
- });
398
- if (!watchConfig) {
52
+ const configPath = (argv.config || argv.c || (0, config_1.findConfigFile)());
53
+ const targetName = (argv.target || argv.t);
54
+ // If config file exists, load and run
55
+ if (configPath) {
56
+ const loaded = await (0, config_1.loadConfigFile)(configPath);
57
+ if (!loaded.success) {
58
+ console.error('x', loaded.error);
399
59
  process.exit(1);
400
60
  }
401
- await (0, watch_1.startWatch)({
402
- config: watchConfig,
403
- generatorType: 'generate-orm',
404
- verbose,
405
- authorization,
406
- configPath: config,
407
- target,
408
- outputDir: output,
409
- skipCustomOperations,
410
- });
411
- return;
412
- }
413
- const result = await (0, generate_orm_1.generateOrm)({
414
- config,
415
- target,
416
- endpoint,
417
- schema,
418
- output,
419
- authorization,
420
- verbose,
421
- dryRun,
422
- skipCustomOperations,
423
- });
424
- const duration = formatDuration(performance.now() - startTime);
425
- const targetResults = result.targets ?? [];
426
- const hasNamedTargets = targetResults.length > 0 &&
427
- (targetResults.length > 1 || targetResults[0]?.name !== 'default');
428
- if (hasNamedTargets) {
429
- console.log(result.success ? '[ok]' : 'x', result.message);
430
- targetResults.forEach((t) => {
431
- const status = t.success ? '[ok]' : 'x';
432
- console.log(`\n${status} ${t.message}`);
433
- if (t.tables && t.tables.length > 0) {
434
- console.log(' Tables:');
435
- t.tables.forEach((table) => console.log(` - ${table}`));
436
- }
437
- if (t.customQueries && t.customQueries.length > 0) {
438
- console.log(' Custom Queries:');
439
- t.customQueries.forEach((query) => console.log(` - ${query}`));
440
- }
441
- if (t.customMutations && t.customMutations.length > 0) {
442
- console.log(' Custom Mutations:');
443
- t.customMutations.forEach((mutation) => console.log(` - ${mutation}`));
61
+ const config = loaded.config;
62
+ // Check if it's a multi-target config (no source fields at top level)
63
+ const isMulti = !('endpoint' in config || 'schemaFile' in config || 'db' in config);
64
+ if (isMulti) {
65
+ // Multi-target: simple for loop over targets
66
+ const targets = config;
67
+ const names = targetName ? [targetName] : Object.keys(targets);
68
+ if (targetName && !targets[targetName]) {
69
+ console.error('x', `Target "${targetName}" not found. Available: ${Object.keys(targets).join(', ')}`);
70
+ process.exit(1);
444
71
  }
445
- if (t.filesWritten && t.filesWritten.length > 0) {
446
- console.log(' Files written:');
447
- t.filesWritten.forEach((file) => console.log(` - ${file}`));
72
+ let hasError = false;
73
+ for (const name of names) {
74
+ console.log(`\n[${name}]`);
75
+ const result = await (0, generate_1.generate)(targets[name]);
76
+ (0, shared_1.printResult)(result);
77
+ if (!result.success)
78
+ hasError = true;
448
79
  }
449
- if (!t.success && t.errors) {
450
- t.errors.forEach((error) => console.error(` - ${error}`));
451
- }
452
- });
453
- if (!result.success) {
80
+ prompter.close();
81
+ if (hasError)
82
+ process.exit(1);
83
+ return argv;
84
+ }
85
+ // Single config
86
+ const result = await (0, generate_1.generate)(config);
87
+ (0, shared_1.printResult)(result);
88
+ if (!result.success)
454
89
  process.exit(1);
455
- }
456
- return;
457
- }
458
- if (result.success) {
459
- console.log('[ok]', result.message, `(${duration})`);
460
- if (result.tables && result.tables.length > 0) {
461
- console.log('\nTables:');
462
- result.tables.forEach((t) => console.log(` - ${t}`));
463
- }
464
- if (result.customQueries && result.customQueries.length > 0) {
465
- console.log('\nCustom Queries:');
466
- result.customQueries.forEach((q) => console.log(` - ${q}`));
467
- }
468
- if (result.customMutations && result.customMutations.length > 0) {
469
- console.log('\nCustom Mutations:');
470
- result.customMutations.forEach((m) => console.log(` - ${m}`));
471
- }
472
- if (result.filesWritten && result.filesWritten.length > 0) {
473
- console.log('\nFiles written:');
474
- result.filesWritten.forEach((f) => console.log(` - ${f}`));
475
- }
476
- }
477
- else {
478
- console.error('x', result.message, `(${duration})`);
479
- if (result.errors) {
480
- result.errors.forEach((e) => console.error(' -', e));
481
- }
482
- process.exit(1);
483
- }
484
- }
485
- /**
486
- * Introspect command handler
487
- */
488
- async function handleIntrospect(argv) {
489
- if (argv.help || argv.h) {
490
- console.log(introspectUsageText);
491
- process.exit(0);
492
- }
493
- const startTime = performance.now();
494
- const endpoint = argv.endpoint || argv.e;
495
- const schema = argv.schema || argv.s;
496
- const authorization = argv.authorization || argv.a;
497
- const json = !!argv.json;
498
- if (!endpoint && !schema) {
499
- console.error('x Either --endpoint or --schema must be provided.');
500
- process.exit(1);
501
- }
502
- if (endpoint && schema) {
503
- console.error('x Cannot use both --endpoint and --schema. Choose one source.');
504
- process.exit(1);
505
- }
506
- const { createSchemaSource } = await Promise.resolve().then(() => __importStar(require('./introspect/source')));
507
- const { inferTablesFromIntrospection } = await Promise.resolve().then(() => __importStar(require('./introspect/infer-tables')));
508
- try {
509
- const source = createSchemaSource({
510
- endpoint,
511
- schema,
512
- authorization,
513
- });
514
- console.log('Fetching schema from', source.describe(), '...');
515
- const { introspection } = await source.fetch();
516
- const tables = inferTablesFromIntrospection(introspection);
517
- const duration = formatDuration(performance.now() - startTime);
518
- if (json) {
519
- console.log(JSON.stringify(tables, null, 2));
520
- }
521
- else {
522
- console.log(`\n[ok] Found ${tables.length} tables (${duration}):\n`);
523
- tables.forEach((table) => {
524
- const fieldCount = table.fields.length;
525
- const relationCount = table.relations.belongsTo.length +
526
- table.relations.hasOne.length +
527
- table.relations.hasMany.length +
528
- table.relations.manyToMany.length;
529
- console.log(` ${table.name} (${fieldCount} fields, ${relationCount} relations)`);
530
- });
531
- }
532
- }
533
- catch (err) {
534
- const duration = formatDuration(performance.now() - startTime);
535
- console.error('x Failed to introspect schema:', err instanceof Error ? err.message : err, `(${duration})`);
536
- process.exit(1);
537
- }
538
- }
539
- const createCommandMap = () => {
540
- return {
541
- init: handleInit,
542
- generate: handleGenerate,
543
- 'generate-orm': handleGenerateOrm,
544
- introspect: handleIntrospect,
545
- };
546
- };
547
- const commands = async (argv, prompter, _options) => {
548
- if (argv.version || argv.v) {
549
- const pkg = (0, inquirerer_1.getPackageJson)(__dirname);
550
- console.log(pkg.version);
551
- process.exit(0);
552
- }
553
- const { first: command, newArgv } = (0, inquirerer_1.extractFirst)(argv);
554
- if ((argv.help || argv.h) && !command) {
555
- console.log(usageText);
556
- process.exit(0);
557
- }
558
- if (command === 'help') {
559
- console.log(usageText);
560
- process.exit(0);
561
- }
562
- const commandMap = createCommandMap();
563
- if (!command) {
564
- const answer = await prompter.prompt(argv, [
565
- {
566
- type: 'autocomplete',
567
- name: 'command',
568
- message: 'What do you want to do?',
569
- options: Object.keys(commandMap),
570
- },
571
- ]);
572
- const selectedCommand = answer.command;
573
- const commandFn = commandMap[selectedCommand];
574
- if (commandFn) {
575
- await commandFn(newArgv);
576
- }
577
90
  prompter.close();
578
91
  return argv;
579
92
  }
580
- const commandFn = commandMap[command];
581
- if (!commandFn) {
582
- console.log(usageText);
583
- await (0, inquirerer_1.cliExitWithError)(`Unknown command: ${command}`);
584
- }
585
- await commandFn(newArgv);
93
+ // No config file - prompt for options using shared questions
94
+ const answers = await prompter.prompt(argv, shared_1.codegenQuestions);
95
+ // Build db config if schemas or apiNames provided
96
+ const db = (answers.schemas || answers.apiNames) ? {
97
+ schemas: answers.schemas,
98
+ apiNames: answers.apiNames,
99
+ } : undefined;
100
+ const result = await (0, generate_1.generate)({
101
+ endpoint: answers.endpoint,
102
+ schemaFile: answers.schemaFile,
103
+ db,
104
+ output: answers.output,
105
+ authorization: answers.authorization,
106
+ reactQuery: answers.reactQuery,
107
+ orm: answers.orm,
108
+ dryRun: answers.dryRun,
109
+ verbose: answers.verbose,
110
+ });
111
+ (0, shared_1.printResult)(result);
586
112
  prompter.close();
587
113
  return argv;
588
114
  };
@@ -590,35 +116,26 @@ exports.commands = commands;
590
116
  exports.options = {
591
117
  minimistOpts: {
592
118
  alias: {
593
- v: 'version',
594
119
  h: 'help',
595
120
  c: 'config',
596
- t: 'target',
597
121
  e: 'endpoint',
598
- s: 'schema',
122
+ s: 'schema-file',
599
123
  o: 'output',
124
+ t: 'target',
600
125
  a: 'authorization',
601
- d: 'directory',
602
- f: 'force',
603
- w: 'watch',
604
- },
605
- boolean: ['help', 'version', 'force', 'verbose', 'dry-run', 'watch', 'json', 'skip-custom-operations', 'clear'],
606
- string: ['config', 'target', 'endpoint', 'schema', 'output', 'authorization', 'directory', 'touch', 'poll-interval', 'debounce'],
607
- default: {
608
- clear: true,
126
+ v: 'verbose',
609
127
  },
128
+ boolean: [
129
+ 'help', 'version', 'verbose', 'dry-run', 'react-query', 'orm', 'keep-db',
130
+ ],
131
+ string: [
132
+ 'config', 'endpoint', 'schema-file', 'output', 'target', 'authorization',
133
+ 'pgpm-module-path', 'pgpm-workspace-path', 'pgpm-module-name',
134
+ 'schemas', 'api-names',
135
+ ],
610
136
  },
611
137
  };
612
138
  if (require.main === module) {
613
- if (process.argv.includes('--version') || process.argv.includes('-v')) {
614
- const pkg = (0, inquirerer_1.getPackageJson)(__dirname);
615
- console.log(pkg.version);
616
- process.exit(0);
617
- }
618
- const app = new inquirerer_1.CLI(exports.commands, exports.options);
619
- app.run().then(() => {
620
- }).catch((error) => {
621
- console.error('Unexpected error:', error);
622
- process.exit(1);
623
- });
139
+ const cli = new inquirerer_1.CLI(exports.commands, exports.options);
140
+ cli.run();
624
141
  }