@constructive-io/graphql-codegen 2.31.0 → 3.0.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 (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} +12 -5
  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} +9 -5
  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 +110 -136
  97. package/esm/types/config.js +23 -148
  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 +19 -11
  103. package/types/config.d.ts +110 -136
  104. package/types/config.js +28 -152
  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,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
52
- */
53
- export declare function generateOrmCommand(options?: GenerateOrmOptions): Promise<GenerateOrmResult>;
@@ -1,292 +0,0 @@
1
- "use strict";
2
- /**
3
- * Generate ORM command - generates Prisma-like ORM client from GraphQL schema
4
- *
5
- * This command:
6
- * 1. Fetches schema from endpoint or loads from file
7
- * 2. Infers table metadata from introspection (replaces _meta)
8
- * 3. Generates a Prisma-like ORM client with fluent API
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.generateOrmCommand = generateOrmCommand;
12
- const config_1 = require("../../types/config");
13
- const source_1 = require("../introspect/source");
14
- const shared_1 = require("./shared");
15
- const init_1 = require("./init");
16
- const generate_1 = require("./generate");
17
- const orm_1 = require("../codegen/orm");
18
- /**
19
- * Execute the generate-orm command
20
- */
21
- async function generateOrmCommand(options = {}) {
22
- if (options.verbose) {
23
- console.log('Loading configuration...');
24
- }
25
- const configResult = await loadConfig(options);
26
- if (!configResult.success) {
27
- return {
28
- success: false,
29
- message: configResult.error,
30
- };
31
- }
32
- const targets = configResult.targets ?? [];
33
- if (targets.length === 0) {
34
- return {
35
- success: false,
36
- message: 'No targets resolved from configuration.',
37
- };
38
- }
39
- const isMultiTarget = configResult.isMulti ?? targets.length > 1;
40
- const results = [];
41
- for (const target of targets) {
42
- const result = await generateOrmForTarget(target, options, isMultiTarget);
43
- results.push(result);
44
- }
45
- if (!isMultiTarget) {
46
- const [result] = results;
47
- return {
48
- success: result.success,
49
- message: result.message,
50
- targets: results,
51
- tables: result.tables,
52
- customQueries: result.customQueries,
53
- customMutations: result.customMutations,
54
- filesWritten: result.filesWritten,
55
- errors: result.errors,
56
- };
57
- }
58
- const successCount = results.filter((result) => result.success).length;
59
- const failedCount = results.length - successCount;
60
- const summaryMessage = failedCount === 0
61
- ? `Generated ORM clients for ${results.length} targets.`
62
- : `Generated ORM clients for ${successCount} of ${results.length} targets.`;
63
- return {
64
- success: failedCount === 0,
65
- message: summaryMessage,
66
- targets: results,
67
- errors: failedCount > 0
68
- ? results.flatMap((result) => result.errors ?? [])
69
- : undefined,
70
- };
71
- }
72
- async function generateOrmForTarget(target, options, isMultiTarget) {
73
- const config = target.config;
74
- const outputDir = options.output || config.orm?.output || './generated/orm';
75
- const prefix = isMultiTarget ? `[${target.name}] ` : '';
76
- const log = options.verbose
77
- ? (message) => console.log(`${prefix}${message}`)
78
- : () => { };
79
- const formatMessage = (message) => isMultiTarget ? `Target "${target.name}": ${message}` : message;
80
- if (isMultiTarget) {
81
- console.log(`\nTarget "${target.name}"`);
82
- const sourceLabel = config.schema
83
- ? `schema: ${config.schema}`
84
- : `endpoint: ${config.endpoint}`;
85
- console.log(` Source: ${sourceLabel}`);
86
- console.log(` Output: ${outputDir}`);
87
- }
88
- // 1. Validate source
89
- const sourceValidation = (0, source_1.validateSourceOptions)({
90
- endpoint: config.endpoint || undefined,
91
- schema: config.schema || undefined,
92
- });
93
- if (!sourceValidation.valid) {
94
- return {
95
- name: target.name,
96
- output: outputDir,
97
- success: false,
98
- message: formatMessage(sourceValidation.error),
99
- };
100
- }
101
- const source = (0, source_1.createSchemaSource)({
102
- endpoint: config.endpoint || undefined,
103
- schema: config.schema || undefined,
104
- authorization: options.authorization || config.headers['Authorization'],
105
- headers: config.headers,
106
- });
107
- // 2. Run the codegen pipeline
108
- let pipelineResult;
109
- try {
110
- pipelineResult = await (0, shared_1.runCodegenPipeline)({
111
- source,
112
- config,
113
- verbose: options.verbose,
114
- skipCustomOperations: options.skipCustomOperations,
115
- });
116
- }
117
- catch (err) {
118
- return {
119
- name: target.name,
120
- output: outputDir,
121
- success: false,
122
- message: formatMessage(`Failed to fetch schema: ${err instanceof Error ? err.message : 'Unknown error'}`),
123
- };
124
- }
125
- const { tables, customOperations, stats } = pipelineResult;
126
- // 3. Validate tables found
127
- const tablesValidation = (0, shared_1.validateTablesFound)(tables);
128
- if (!tablesValidation.valid) {
129
- return {
130
- name: target.name,
131
- output: outputDir,
132
- success: false,
133
- message: formatMessage(tablesValidation.error),
134
- };
135
- }
136
- // 4. Generate ORM code
137
- console.log(`${prefix}Generating code...`);
138
- const { files: generatedFiles, stats: genStats } = (0, orm_1.generateOrm)({
139
- tables,
140
- customOperations: {
141
- queries: customOperations.queries,
142
- mutations: customOperations.mutations,
143
- typeRegistry: customOperations.typeRegistry,
144
- },
145
- config,
146
- });
147
- console.log(`${prefix}Generated ${genStats.totalFiles} files`);
148
- log(` ${genStats.tables} table models`);
149
- log(` ${genStats.customQueries} custom query operations`);
150
- log(` ${genStats.customMutations} custom mutation operations`);
151
- const customQueries = customOperations.queries.map((q) => q.name);
152
- const customMutations = customOperations.mutations.map((m) => m.name);
153
- if (options.dryRun) {
154
- return {
155
- name: target.name,
156
- output: outputDir,
157
- success: true,
158
- message: formatMessage(`Dry run complete. Would generate ${generatedFiles.length} files for ${tables.length} tables and ${stats.customQueries + stats.customMutations} custom operations.`),
159
- tables: tables.map((t) => t.name),
160
- customQueries,
161
- customMutations,
162
- filesWritten: generatedFiles.map((f) => f.path),
163
- };
164
- }
165
- // 5. Write files
166
- log('Writing files...');
167
- const writeResult = await (0, generate_1.writeGeneratedFiles)(generatedFiles, outputDir, [
168
- 'models',
169
- 'query',
170
- 'mutation',
171
- ]);
172
- if (!writeResult.success) {
173
- return {
174
- name: target.name,
175
- output: outputDir,
176
- success: false,
177
- message: formatMessage(`Failed to write files: ${writeResult.errors?.join(', ')}`),
178
- errors: writeResult.errors,
179
- };
180
- }
181
- const totalOps = customQueries.length + customMutations.length;
182
- const customOpsMsg = totalOps > 0 ? ` and ${totalOps} custom operations` : '';
183
- return {
184
- name: target.name,
185
- output: outputDir,
186
- success: true,
187
- message: formatMessage(`Generated ORM client for ${tables.length} tables${customOpsMsg}. Files written to ${outputDir}`),
188
- tables: tables.map((t) => t.name),
189
- customQueries,
190
- customMutations,
191
- filesWritten: writeResult.filesWritten,
192
- };
193
- }
194
- function buildTargetOverrides(options) {
195
- const overrides = {};
196
- if (options.endpoint) {
197
- overrides.endpoint = options.endpoint;
198
- overrides.schema = undefined;
199
- }
200
- if (options.schema) {
201
- overrides.schema = options.schema;
202
- overrides.endpoint = undefined;
203
- }
204
- return overrides;
205
- }
206
- async function loadConfig(options) {
207
- if (options.endpoint && options.schema) {
208
- return {
209
- success: false,
210
- error: 'Cannot use both --endpoint and --schema. Choose one source.',
211
- };
212
- }
213
- // Find config file
214
- let configPath = options.config;
215
- if (!configPath) {
216
- configPath = (0, init_1.findConfigFile)() ?? undefined;
217
- }
218
- let baseConfig = {};
219
- if (configPath) {
220
- const loadResult = await (0, init_1.loadConfigFile)(configPath);
221
- if (!loadResult.success) {
222
- return { success: false, error: loadResult.error };
223
- }
224
- baseConfig = loadResult.config;
225
- }
226
- const overrides = buildTargetOverrides(options);
227
- if ((0, config_1.isMultiConfig)(baseConfig)) {
228
- if (Object.keys(baseConfig.targets).length === 0) {
229
- return {
230
- success: false,
231
- error: 'Config file defines no targets.',
232
- };
233
- }
234
- if (!options.target &&
235
- (options.endpoint || options.schema || options.output)) {
236
- return {
237
- success: false,
238
- error: 'Multiple targets configured. Use --target with --endpoint, --schema, or --output.',
239
- };
240
- }
241
- if (options.target && !baseConfig.targets[options.target]) {
242
- return {
243
- success: false,
244
- error: `Target "${options.target}" not found in config file.`,
245
- };
246
- }
247
- const selectedTargets = options.target
248
- ? { [options.target]: baseConfig.targets[options.target] }
249
- : baseConfig.targets;
250
- const defaults = baseConfig.defaults ?? {};
251
- const resolvedTargets = [];
252
- for (const [name, target] of Object.entries(selectedTargets)) {
253
- let mergedTarget = (0, config_1.mergeConfig)(defaults, target);
254
- if (options.target && name === options.target) {
255
- mergedTarget = (0, config_1.mergeConfig)(mergedTarget, overrides);
256
- }
257
- if (!mergedTarget.endpoint && !mergedTarget.schema) {
258
- return {
259
- success: false,
260
- error: `Target "${name}" is missing an endpoint or schema.`,
261
- };
262
- }
263
- resolvedTargets.push({
264
- name,
265
- config: (0, config_1.resolveConfig)(mergedTarget),
266
- });
267
- }
268
- return {
269
- success: true,
270
- targets: resolvedTargets,
271
- isMulti: true,
272
- };
273
- }
274
- if (options.target) {
275
- return {
276
- success: false,
277
- error: 'Config file does not define targets. Remove --target to continue.',
278
- };
279
- }
280
- const mergedConfig = (0, config_1.mergeConfig)(baseConfig, overrides);
281
- if (!mergedConfig.endpoint && !mergedConfig.schema) {
282
- return {
283
- success: false,
284
- error: 'No source specified. Use --endpoint or --schema, or create a config file with "graphql-codegen init".',
285
- };
286
- }
287
- return {
288
- success: true,
289
- targets: [{ name: 'default', config: (0, config_1.resolveConfig)(mergedConfig) }],
290
- isMulti: false,
291
- };
292
- }
@@ -1,66 +0,0 @@
1
- export interface GenerateOptions {
2
- /** Path to config file */
3
- config?: string;
4
- /** Named target in a multi-target config */
5
- target?: string;
6
- /** GraphQL endpoint URL (overrides config) */
7
- endpoint?: string;
8
- /** Path to GraphQL schema file (.graphql) */
9
- schema?: string;
10
- /** Output directory (overrides config) */
11
- output?: string;
12
- /** Authorization header */
13
- authorization?: string;
14
- /** Verbose output */
15
- verbose?: boolean;
16
- /** Dry run - don't write files */
17
- dryRun?: boolean;
18
- /** Skip custom operations (only generate table CRUD) */
19
- skipCustomOperations?: boolean;
20
- }
21
- export interface GenerateTargetResult {
22
- name: string;
23
- output: string;
24
- success: boolean;
25
- message: string;
26
- tables?: string[];
27
- customQueries?: string[];
28
- customMutations?: string[];
29
- filesWritten?: string[];
30
- errors?: string[];
31
- }
32
- export interface GenerateResult {
33
- success: boolean;
34
- message: string;
35
- targets?: GenerateTargetResult[];
36
- tables?: string[];
37
- customQueries?: string[];
38
- customMutations?: string[];
39
- filesWritten?: string[];
40
- errors?: string[];
41
- }
42
- /**
43
- * Execute the generate command
44
- */
45
- export declare function generateCommand(options?: GenerateOptions): Promise<GenerateResult>;
46
- export interface GeneratedFile {
47
- path: string;
48
- content: string;
49
- }
50
- export interface WriteResult {
51
- success: boolean;
52
- filesWritten?: string[];
53
- errors?: string[];
54
- }
55
- export interface WriteOptions {
56
- showProgress?: boolean;
57
- }
58
- export declare function writeGeneratedFiles(files: GeneratedFile[], outputDir: string, subdirs: string[], options?: WriteOptions): Promise<WriteResult>;
59
- /**
60
- * Format generated files using prettier
61
- * Runs prettier on the output directory after all files are written
62
- */
63
- export declare function formatOutput(outputDir: string): {
64
- success: boolean;
65
- error?: string;
66
- };