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