@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
@@ -1,431 +0,0 @@
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.generateReactQuery = generateReactQuery;
37
- exports.writeGeneratedFiles = writeGeneratedFiles;
38
- exports.formatOutput = formatOutput;
39
- /**
40
- * Generate command - generates SDK from GraphQL schema
41
- *
42
- * This command:
43
- * 1. Fetches schema from endpoint or loads from file
44
- * 2. Infers table metadata from introspection (replaces _meta)
45
- * 3. Generates hooks for both table CRUD and custom operations
46
- */
47
- const fs = __importStar(require("node:fs"));
48
- const path = __importStar(require("node:path"));
49
- const node_child_process_1 = require("node:child_process");
50
- const config_1 = require("../../types/config");
51
- const source_1 = require("../introspect/source");
52
- const shared_1 = require("./shared");
53
- const init_1 = require("./init");
54
- const codegen_1 = require("../codegen");
55
- /**
56
- * Execute the generate command (generates React Query SDK)
57
- */
58
- async function generateReactQuery(options = {}) {
59
- if (options.verbose) {
60
- console.log('Loading configuration...');
61
- }
62
- const configResult = await loadConfig(options);
63
- if (!configResult.success) {
64
- return {
65
- success: false,
66
- message: configResult.error,
67
- };
68
- }
69
- const targets = configResult.targets ?? [];
70
- if (targets.length === 0) {
71
- return {
72
- success: false,
73
- message: 'No targets resolved from configuration.',
74
- };
75
- }
76
- const isMultiTarget = configResult.isMulti ?? targets.length > 1;
77
- const results = [];
78
- for (const target of targets) {
79
- const result = await generateForTarget(target, options, isMultiTarget);
80
- results.push(result);
81
- }
82
- if (!isMultiTarget) {
83
- const [result] = results;
84
- return {
85
- success: result.success,
86
- message: result.message,
87
- targets: results,
88
- tables: result.tables,
89
- customQueries: result.customQueries,
90
- customMutations: result.customMutations,
91
- filesWritten: result.filesWritten,
92
- errors: result.errors,
93
- };
94
- }
95
- const successCount = results.filter((result) => result.success).length;
96
- const failedCount = results.length - successCount;
97
- const summaryMessage = failedCount === 0
98
- ? `Generated SDK for ${results.length} targets.`
99
- : `Generated SDK for ${successCount} of ${results.length} targets.`;
100
- return {
101
- success: failedCount === 0,
102
- message: summaryMessage,
103
- targets: results,
104
- errors: failedCount > 0
105
- ? results.flatMap((result) => result.errors ?? [])
106
- : undefined,
107
- };
108
- }
109
- async function generateForTarget(target, options, isMultiTarget) {
110
- const config = target.config;
111
- const prefix = isMultiTarget ? `[${target.name}] ` : '';
112
- const log = options.verbose
113
- ? (message) => console.log(`${prefix}${message}`)
114
- : () => { };
115
- const formatMessage = (message) => isMultiTarget ? `Target "${target.name}": ${message}` : message;
116
- if (isMultiTarget) {
117
- console.log(`\nTarget "${target.name}"`);
118
- const sourceLabel = config.schema
119
- ? `schema: ${config.schema}`
120
- : `endpoint: ${config.endpoint}`;
121
- console.log(` Source: ${sourceLabel}`);
122
- console.log(` Output: ${config.output}`);
123
- }
124
- // 1. Validate source
125
- const sourceValidation = (0, source_1.validateSourceOptions)({
126
- endpoint: config.endpoint || undefined,
127
- schema: config.schema || undefined,
128
- });
129
- if (!sourceValidation.valid) {
130
- return {
131
- name: target.name,
132
- output: config.output,
133
- success: false,
134
- message: formatMessage(sourceValidation.error),
135
- };
136
- }
137
- const source = (0, source_1.createSchemaSource)({
138
- endpoint: config.endpoint || undefined,
139
- schema: config.schema || undefined,
140
- authorization: options.authorization || config.headers['Authorization'],
141
- headers: config.headers,
142
- });
143
- // 2. Run the codegen pipeline
144
- let pipelineResult;
145
- try {
146
- pipelineResult = await (0, shared_1.runCodegenPipeline)({
147
- source,
148
- config,
149
- verbose: options.verbose,
150
- skipCustomOperations: options.skipCustomOperations,
151
- });
152
- }
153
- catch (err) {
154
- return {
155
- name: target.name,
156
- output: config.output,
157
- success: false,
158
- message: formatMessage(`Failed to fetch schema: ${err instanceof Error ? err.message : 'Unknown error'}`),
159
- };
160
- }
161
- const { tables, customOperations, stats } = pipelineResult;
162
- // 3. Validate tables found
163
- const tablesValidation = (0, shared_1.validateTablesFound)(tables);
164
- if (!tablesValidation.valid) {
165
- return {
166
- name: target.name,
167
- output: config.output,
168
- success: false,
169
- message: formatMessage(tablesValidation.error),
170
- };
171
- }
172
- // 4. Generate code
173
- console.log(`${prefix}Generating code...`);
174
- const { files: generatedFiles, stats: genStats } = (0, codegen_1.generate)({
175
- tables,
176
- customOperations: {
177
- queries: customOperations.queries,
178
- mutations: customOperations.mutations,
179
- typeRegistry: customOperations.typeRegistry,
180
- },
181
- config,
182
- });
183
- console.log(`${prefix}Generated ${genStats.totalFiles} files`);
184
- log(` ${genStats.queryHooks} table query hooks`);
185
- log(` ${genStats.mutationHooks} table mutation hooks`);
186
- log(` ${genStats.customQueryHooks} custom query hooks`);
187
- log(` ${genStats.customMutationHooks} custom mutation hooks`);
188
- const customQueries = customOperations.queries.map((q) => q.name);
189
- const customMutations = customOperations.mutations.map((m) => m.name);
190
- if (options.dryRun) {
191
- return {
192
- name: target.name,
193
- output: config.output,
194
- success: true,
195
- message: formatMessage(`Dry run complete. Would generate ${generatedFiles.length} files for ${tables.length} tables and ${stats.customQueries + stats.customMutations} custom operations.`),
196
- tables: tables.map((t) => t.name),
197
- customQueries,
198
- customMutations,
199
- filesWritten: generatedFiles.map((f) => f.path),
200
- };
201
- }
202
- // 5. Write files
203
- log('Writing files...');
204
- const writeResult = await writeGeneratedFiles(generatedFiles, config.output, [
205
- 'queries',
206
- 'mutations',
207
- ]);
208
- if (!writeResult.success) {
209
- return {
210
- name: target.name,
211
- output: config.output,
212
- success: false,
213
- message: formatMessage(`Failed to write files: ${writeResult.errors?.join(', ')}`),
214
- errors: writeResult.errors,
215
- };
216
- }
217
- const totalOps = customQueries.length + customMutations.length;
218
- const customOpsMsg = totalOps > 0 ? ` and ${totalOps} custom operations` : '';
219
- return {
220
- name: target.name,
221
- output: config.output,
222
- success: true,
223
- message: formatMessage(`Generated SDK for ${tables.length} tables${customOpsMsg}. Files written to ${config.output}`),
224
- tables: tables.map((t) => t.name),
225
- customQueries,
226
- customMutations,
227
- filesWritten: writeResult.filesWritten,
228
- };
229
- }
230
- function buildTargetOverrides(options) {
231
- const overrides = {};
232
- if (options.endpoint) {
233
- overrides.endpoint = options.endpoint;
234
- overrides.schema = undefined;
235
- }
236
- if (options.schema) {
237
- overrides.schema = options.schema;
238
- overrides.endpoint = undefined;
239
- }
240
- if (options.output) {
241
- overrides.output = options.output;
242
- }
243
- return overrides;
244
- }
245
- async function loadConfig(options) {
246
- if (options.endpoint && options.schema) {
247
- return {
248
- success: false,
249
- error: 'Cannot use both --endpoint and --schema. Choose one source.',
250
- };
251
- }
252
- // Find config file
253
- let configPath = options.config;
254
- if (!configPath) {
255
- configPath = (0, init_1.findConfigFile)() ?? undefined;
256
- }
257
- let baseConfig = {};
258
- if (configPath) {
259
- const loadResult = await (0, init_1.loadConfigFile)(configPath);
260
- if (!loadResult.success) {
261
- return { success: false, error: loadResult.error };
262
- }
263
- baseConfig = loadResult.config;
264
- }
265
- const overrides = buildTargetOverrides(options);
266
- if ((0, config_1.isMultiConfig)(baseConfig)) {
267
- if (Object.keys(baseConfig.targets).length === 0) {
268
- return {
269
- success: false,
270
- error: 'Config file defines no targets.',
271
- };
272
- }
273
- if (!options.target &&
274
- (options.endpoint || options.schema || options.output)) {
275
- return {
276
- success: false,
277
- error: 'Multiple targets configured. Use --target with --endpoint, --schema, or --output.',
278
- };
279
- }
280
- if (options.target && !baseConfig.targets[options.target]) {
281
- return {
282
- success: false,
283
- error: `Target "${options.target}" not found in config file.`,
284
- };
285
- }
286
- const selectedTargets = options.target
287
- ? { [options.target]: baseConfig.targets[options.target] }
288
- : baseConfig.targets;
289
- const defaults = baseConfig.defaults ?? {};
290
- const resolvedTargets = [];
291
- for (const [name, target] of Object.entries(selectedTargets)) {
292
- let mergedTarget = (0, config_1.mergeConfig)(defaults, target);
293
- if (options.target && name === options.target) {
294
- mergedTarget = (0, config_1.mergeConfig)(mergedTarget, overrides);
295
- }
296
- if (!mergedTarget.endpoint && !mergedTarget.schema) {
297
- return {
298
- success: false,
299
- error: `Target "${name}" is missing an endpoint or schema.`,
300
- };
301
- }
302
- resolvedTargets.push({
303
- name,
304
- config: (0, config_1.resolveConfig)(mergedTarget),
305
- });
306
- }
307
- return {
308
- success: true,
309
- targets: resolvedTargets,
310
- isMulti: true,
311
- };
312
- }
313
- if (options.target) {
314
- return {
315
- success: false,
316
- error: 'Config file does not define targets. Remove --target to continue.',
317
- };
318
- }
319
- const mergedConfig = (0, config_1.mergeConfig)(baseConfig, overrides);
320
- if (!mergedConfig.endpoint && !mergedConfig.schema) {
321
- return {
322
- success: false,
323
- error: 'No source specified. Use --endpoint or --schema, or create a config file with "graphql-codegen init".',
324
- };
325
- }
326
- return {
327
- success: true,
328
- targets: [{ name: 'default', config: (0, config_1.resolveConfig)(mergedConfig) }],
329
- isMulti: false,
330
- };
331
- }
332
- async function writeGeneratedFiles(files, outputDir, subdirs, options = {}) {
333
- const { showProgress = true } = options;
334
- const errors = [];
335
- const written = [];
336
- const total = files.length;
337
- const isTTY = process.stdout.isTTY;
338
- // Ensure output directory exists
339
- try {
340
- fs.mkdirSync(outputDir, { recursive: true });
341
- }
342
- catch (err) {
343
- const message = err instanceof Error ? err.message : 'Unknown error';
344
- return {
345
- success: false,
346
- errors: [`Failed to create output directory: ${message}`],
347
- };
348
- }
349
- // Create subdirectories
350
- for (const subdir of subdirs) {
351
- const subdirPath = path.join(outputDir, subdir);
352
- try {
353
- fs.mkdirSync(subdirPath, { recursive: true });
354
- }
355
- catch (err) {
356
- const message = err instanceof Error ? err.message : 'Unknown error';
357
- errors.push(`Failed to create directory ${subdirPath}: ${message}`);
358
- }
359
- }
360
- if (errors.length > 0) {
361
- return { success: false, errors };
362
- }
363
- for (let i = 0; i < files.length; i++) {
364
- const file = files[i];
365
- const filePath = path.join(outputDir, file.path);
366
- // Show progress
367
- if (showProgress) {
368
- const progress = Math.round(((i + 1) / total) * 100);
369
- if (isTTY) {
370
- process.stdout.write(`\rWriting files: ${i + 1}/${total} (${progress}%)`);
371
- }
372
- else if (i % 100 === 0 || i === total - 1) {
373
- // Non-TTY: periodic updates for CI/CD
374
- console.log(`Writing files: ${i + 1}/${total}`);
375
- }
376
- }
377
- // Ensure parent directory exists
378
- const parentDir = path.dirname(filePath);
379
- try {
380
- fs.mkdirSync(parentDir, { recursive: true });
381
- }
382
- catch {
383
- // Ignore if already exists
384
- }
385
- try {
386
- fs.writeFileSync(filePath, file.content, 'utf-8');
387
- written.push(filePath);
388
- }
389
- catch (err) {
390
- const message = err instanceof Error ? err.message : 'Unknown error';
391
- errors.push(`Failed to write ${filePath}: ${message}`);
392
- }
393
- }
394
- // Clear progress line
395
- if (showProgress && isTTY) {
396
- process.stdout.write('\r' + ' '.repeat(40) + '\r');
397
- }
398
- // Format all generated files with prettier
399
- if (errors.length === 0) {
400
- if (showProgress) {
401
- console.log('Formatting generated files...');
402
- }
403
- const formatResult = formatOutput(outputDir);
404
- if (!formatResult.success && showProgress) {
405
- console.warn('Warning: Failed to format generated files:', formatResult.error);
406
- }
407
- }
408
- return {
409
- success: errors.length === 0,
410
- filesWritten: written,
411
- errors: errors.length > 0 ? errors : undefined,
412
- };
413
- }
414
- /**
415
- * Format generated files using prettier
416
- * Runs prettier on the output directory after all files are written
417
- */
418
- function formatOutput(outputDir) {
419
- const absoluteOutputDir = path.resolve(outputDir);
420
- try {
421
- (0, node_child_process_1.execSync)(`npx prettier --write --single-quote --trailing-comma all --tab-width 2 --semi "${absoluteOutputDir}"`, {
422
- stdio: 'pipe',
423
- encoding: 'utf-8',
424
- });
425
- return { success: true };
426
- }
427
- catch (err) {
428
- const message = err instanceof Error ? err.message : String(err);
429
- return { success: false, error: message };
430
- }
431
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * CLI commands exports
3
- */
4
- export { initCommand, findConfigFile, loadConfigFile } from './init';
5
- export type { InitOptions, InitResult } from './init';
6
- export { generateReactQuery } from './generate';
7
- export type { GenerateOptions, GenerateResult, GenerateTargetResult } from './generate';
8
- export { generateOrm } from './generate-orm';
9
- export type { GenerateOrmOptions, GenerateOrmResult, GenerateOrmTargetResult } from './generate-orm';
@@ -1,14 +0,0 @@
1
- "use strict";
2
- /**
3
- * CLI commands exports
4
- */
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.generateOrm = exports.generateReactQuery = exports.loadConfigFile = exports.findConfigFile = exports.initCommand = void 0;
7
- var init_1 = require("./init");
8
- Object.defineProperty(exports, "initCommand", { enumerable: true, get: function () { return init_1.initCommand; } });
9
- Object.defineProperty(exports, "findConfigFile", { enumerable: true, get: function () { return init_1.findConfigFile; } });
10
- Object.defineProperty(exports, "loadConfigFile", { enumerable: true, get: function () { return init_1.loadConfigFile; } });
11
- var generate_1 = require("./generate");
12
- Object.defineProperty(exports, "generateReactQuery", { enumerable: true, get: function () { return generate_1.generateReactQuery; } });
13
- var generate_orm_1 = require("./generate-orm");
14
- Object.defineProperty(exports, "generateOrm", { enumerable: true, get: function () { return generate_orm_1.generateOrm; } });
@@ -1,35 +0,0 @@
1
- export interface InitOptions {
2
- /** Target directory for the config file */
3
- directory?: string;
4
- /** Force overwrite existing config */
5
- force?: boolean;
6
- /** GraphQL endpoint URL to pre-populate */
7
- endpoint?: string;
8
- /** Output directory to pre-populate */
9
- output?: string;
10
- }
11
- export interface InitResult {
12
- success: boolean;
13
- message: string;
14
- configPath?: string;
15
- }
16
- /**
17
- * Execute the init command
18
- */
19
- export declare function initCommand(options?: InitOptions): Promise<InitResult>;
20
- /**
21
- * Find the nearest config file by walking up directories
22
- */
23
- export declare function findConfigFile(startDir?: string): string | null;
24
- /**
25
- * Load and validate a config file
26
- *
27
- * Uses jiti to support TypeScript config files (.ts) in addition to
28
- * JavaScript (.js, .mjs, .cjs) without requiring the user to have
29
- * tsx or ts-node installed.
30
- */
31
- export declare function loadConfigFile(configPath: string): Promise<{
32
- success: boolean;
33
- config?: any;
34
- error?: string;
35
- }>;
@@ -1,48 +0,0 @@
1
- /**
2
- * Schema Source Module
3
- *
4
- * Provides a unified interface for loading GraphQL schemas from different sources:
5
- * - Live GraphQL endpoints (via introspection)
6
- * - Static .graphql schema files
7
- */
8
- export * from './types';
9
- export * from './endpoint';
10
- export * from './file';
11
- import type { SchemaSource } from './types';
12
- export interface CreateSchemaSourceOptions {
13
- /**
14
- * GraphQL endpoint URL (for live introspection)
15
- */
16
- endpoint?: string;
17
- /**
18
- * Path to GraphQL schema file (.graphql)
19
- */
20
- schema?: string;
21
- /**
22
- * Optional authorization header for endpoint requests
23
- */
24
- authorization?: string;
25
- /**
26
- * Optional additional headers for endpoint requests
27
- */
28
- headers?: Record<string, string>;
29
- /**
30
- * Request timeout in milliseconds (for endpoint requests)
31
- */
32
- timeout?: number;
33
- }
34
- /**
35
- * Create a schema source based on configuration
36
- *
37
- * @param options - Source configuration
38
- * @returns Appropriate SchemaSource implementation
39
- * @throws Error if neither endpoint nor schema is provided
40
- */
41
- export declare function createSchemaSource(options: CreateSchemaSourceOptions): SchemaSource;
42
- /**
43
- * Validate that source options are valid (at least one source specified)
44
- */
45
- export declare function validateSourceOptions(options: CreateSchemaSourceOptions): {
46
- valid: boolean;
47
- error?: string;
48
- };
@@ -1,72 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createSchemaSource = createSchemaSource;
18
- exports.validateSourceOptions = validateSourceOptions;
19
- /**
20
- * Schema Source Module
21
- *
22
- * Provides a unified interface for loading GraphQL schemas from different sources:
23
- * - Live GraphQL endpoints (via introspection)
24
- * - Static .graphql schema files
25
- */
26
- __exportStar(require("./types"), exports);
27
- __exportStar(require("./endpoint"), exports);
28
- __exportStar(require("./file"), exports);
29
- const endpoint_1 = require("./endpoint");
30
- const file_1 = require("./file");
31
- /**
32
- * Create a schema source based on configuration
33
- *
34
- * @param options - Source configuration
35
- * @returns Appropriate SchemaSource implementation
36
- * @throws Error if neither endpoint nor schema is provided
37
- */
38
- function createSchemaSource(options) {
39
- if (options.schema) {
40
- return new file_1.FileSchemaSource({
41
- schemaPath: options.schema,
42
- });
43
- }
44
- if (options.endpoint) {
45
- return new endpoint_1.EndpointSchemaSource({
46
- endpoint: options.endpoint,
47
- authorization: options.authorization,
48
- headers: options.headers,
49
- timeout: options.timeout,
50
- });
51
- }
52
- throw new Error('Either endpoint or schema must be provided. ' +
53
- 'Use --endpoint for live introspection or --schema for a local file.');
54
- }
55
- /**
56
- * Validate that source options are valid (at least one source specified)
57
- */
58
- function validateSourceOptions(options) {
59
- if (!options.endpoint && !options.schema) {
60
- return {
61
- valid: false,
62
- error: 'Either endpoint or schema must be provided',
63
- };
64
- }
65
- if (options.endpoint && options.schema) {
66
- return {
67
- valid: false,
68
- error: 'Cannot use both endpoint and schema. Choose one source.',
69
- };
70
- }
71
- return { valid: true };
72
- }
@@ -1,53 +0,0 @@
1
- /**
2
- * Generate ORM command - generates Prisma-like ORM client from GraphQL schema
3
- *
4
- * This command:
5
- * 1. Fetches schema from endpoint or loads from file
6
- * 2. Infers table metadata from introspection (replaces _meta)
7
- * 3. Generates a Prisma-like ORM client with fluent API
8
- */
9
- export interface GenerateOrmOptions {
10
- /** Path to config file */
11
- config?: string;
12
- /** Named target in a multi-target config */
13
- target?: string;
14
- /** GraphQL endpoint URL (overrides config) */
15
- endpoint?: string;
16
- /** Path to GraphQL schema file (.graphql) */
17
- schema?: string;
18
- /** Output directory (overrides config) */
19
- output?: string;
20
- /** Authorization header */
21
- authorization?: string;
22
- /** Verbose output */
23
- verbose?: boolean;
24
- /** Dry run - don't write files */
25
- dryRun?: boolean;
26
- /** Skip custom operations (only generate table CRUD) */
27
- skipCustomOperations?: boolean;
28
- }
29
- export interface GenerateOrmTargetResult {
30
- name: string;
31
- output: string;
32
- success: boolean;
33
- message: string;
34
- tables?: string[];
35
- customQueries?: string[];
36
- customMutations?: string[];
37
- filesWritten?: string[];
38
- errors?: string[];
39
- }
40
- export interface GenerateOrmResult {
41
- success: boolean;
42
- message: string;
43
- targets?: GenerateOrmTargetResult[];
44
- tables?: string[];
45
- customQueries?: string[];
46
- customMutations?: string[];
47
- filesWritten?: string[];
48
- errors?: string[];
49
- }
50
- /**
51
- * Execute the generate-orm command (generates ORM client)
52
- */
53
- export declare function generateOrm(options?: GenerateOrmOptions): Promise<GenerateOrmResult>;