@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
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Shared CLI utilities for graphql-codegen
3
+ *
4
+ * These are exported so that packages/cli can use the same questions
5
+ * and types, ensuring consistency between the two CLIs.
6
+ */
7
+ import type { Question } from 'inquirerer';
8
+ import type { GenerateResult } from '../core/generate';
9
+ /**
10
+ * Sanitize function that splits comma-separated strings into arrays
11
+ */
12
+ export declare const splitCommas: (input: string | undefined) => string[] | undefined;
13
+ /**
14
+ * Interface for codegen CLI answers
15
+ */
16
+ export interface CodegenAnswers {
17
+ endpoint?: string;
18
+ schemaFile?: string;
19
+ output?: string;
20
+ schemas?: string[];
21
+ apiNames?: string[];
22
+ reactQuery?: boolean;
23
+ orm?: boolean;
24
+ authorization?: string;
25
+ dryRun?: boolean;
26
+ verbose?: boolean;
27
+ }
28
+ /**
29
+ * Questions for the codegen CLI
30
+ */
31
+ export declare const codegenQuestions: Question[];
32
+ /**
33
+ * Print the result of a generate operation
34
+ */
35
+ export declare function printResult(result: GenerateResult): void;
package/cli/shared.js ADDED
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codegenQuestions = exports.splitCommas = void 0;
4
+ exports.printResult = printResult;
5
+ /**
6
+ * Sanitize function that splits comma-separated strings into arrays
7
+ */
8
+ const splitCommas = (input) => {
9
+ if (!input)
10
+ return undefined;
11
+ return input.split(',').map((s) => s.trim()).filter(Boolean);
12
+ };
13
+ exports.splitCommas = splitCommas;
14
+ /**
15
+ * Questions for the codegen CLI
16
+ */
17
+ exports.codegenQuestions = [
18
+ {
19
+ name: 'endpoint',
20
+ message: 'GraphQL endpoint URL',
21
+ type: 'text',
22
+ required: false,
23
+ },
24
+ {
25
+ name: 'schemaFile',
26
+ message: 'Path to GraphQL schema file',
27
+ type: 'text',
28
+ required: false,
29
+ },
30
+ {
31
+ name: 'output',
32
+ message: 'Output directory',
33
+ type: 'text',
34
+ required: false,
35
+ default: 'codegen',
36
+ useDefault: true,
37
+ },
38
+ {
39
+ name: 'schemas',
40
+ message: 'PostgreSQL schemas (comma-separated)',
41
+ type: 'text',
42
+ required: false,
43
+ sanitize: exports.splitCommas,
44
+ },
45
+ {
46
+ name: 'apiNames',
47
+ message: 'API names (comma-separated)',
48
+ type: 'text',
49
+ required: false,
50
+ sanitize: exports.splitCommas,
51
+ },
52
+ {
53
+ name: 'reactQuery',
54
+ message: 'Generate React Query hooks?',
55
+ type: 'confirm',
56
+ required: false,
57
+ default: false,
58
+ useDefault: true,
59
+ },
60
+ {
61
+ name: 'orm',
62
+ message: 'Generate ORM client?',
63
+ type: 'confirm',
64
+ required: false,
65
+ default: false,
66
+ useDefault: true,
67
+ },
68
+ {
69
+ name: 'authorization',
70
+ message: 'Authorization header value',
71
+ type: 'text',
72
+ required: false,
73
+ },
74
+ {
75
+ name: 'dryRun',
76
+ message: 'Preview without writing files?',
77
+ type: 'confirm',
78
+ required: false,
79
+ default: false,
80
+ useDefault: true,
81
+ },
82
+ {
83
+ name: 'verbose',
84
+ message: 'Verbose output?',
85
+ type: 'confirm',
86
+ required: false,
87
+ default: false,
88
+ useDefault: true,
89
+ },
90
+ ];
91
+ /**
92
+ * Print the result of a generate operation
93
+ */
94
+ function printResult(result) {
95
+ if (result.success) {
96
+ console.log('[ok]', result.message);
97
+ if (result.tables?.length) {
98
+ console.log('Tables:', result.tables.join(', '));
99
+ }
100
+ }
101
+ else {
102
+ console.error('x', result.message);
103
+ result.errors?.forEach((e) => console.error(' -', e));
104
+ process.exit(1);
105
+ }
106
+ }
@@ -28,7 +28,7 @@ export interface MainBarrelOptions {
28
28
  /** Whether invalidation.ts was generated */
29
29
  hasInvalidation?: boolean;
30
30
  }
31
- export declare function generateMainBarrel(tables: CleanTable[], options?: MainBarrelOptions | boolean): string;
31
+ export declare function generateMainBarrel(tables: CleanTable[], options?: MainBarrelOptions): string;
32
32
  /**
33
33
  * Generate queries barrel including custom query operations
34
34
  */
@@ -103,10 +103,7 @@ function generateMutationsBarrel(tables) {
103
103
  return (0, babel_ast_1.generateCode)(statements);
104
104
  }
105
105
  function generateMainBarrel(tables, options = {}) {
106
- // Support legacy signature where second arg was just hasSchemaTypes boolean
107
- const opts = typeof options === 'boolean'
108
- ? { hasSchemaTypes: options, hasMutations: true }
109
- : options;
106
+ const opts = options;
110
107
  const { hasSchemaTypes = false, hasMutations = true, hasQueryKeys = false, hasMutationKeys = false, hasInvalidation = false, } = opts;
111
108
  const tableNames = tables.map((tbl) => tbl.name).join(', ');
112
109
  const statements = [];
@@ -24,7 +24,7 @@
24
24
  * ...
25
25
  */
26
26
  import type { CleanTable, CleanOperation, TypeRegistry } from '../../types/schema';
27
- import type { ResolvedConfig } from '../../types/config';
27
+ import type { GraphQLSDKConfigTarget } from '../../types/config';
28
28
  export interface GeneratedFile {
29
29
  /** Relative path from output directory */
30
30
  path: string;
@@ -51,15 +51,25 @@ export interface GenerateOptions {
51
51
  mutations: CleanOperation[];
52
52
  typeRegistry: TypeRegistry;
53
53
  };
54
- /** Resolved configuration */
55
- config: ResolvedConfig;
54
+ /** Configuration */
55
+ config: GraphQLSDKConfigTarget;
56
+ /**
57
+ * Path to shared types directory (relative import path).
58
+ * When provided, types.ts and schema-types.ts are NOT generated
59
+ * and imports reference the shared types location instead.
60
+ * Example: '..' means types are in parent directory
61
+ */
62
+ sharedTypesPath?: string;
56
63
  }
57
64
  /**
58
- * Generate all SDK files for tables only (legacy function signature)
65
+ * Generate all SDK files for tables only
59
66
  */
60
- export declare function generateAllFiles(tables: CleanTable[], config: ResolvedConfig): GenerateResult;
67
+ export declare function generateAllFiles(tables: CleanTable[], config: GraphQLSDKConfigTarget): GenerateResult;
61
68
  /**
62
69
  * Generate all SDK files with full support for custom operations
70
+ *
71
+ * When sharedTypesPath is provided, types.ts and schema-types.ts are NOT generated
72
+ * (they're expected to exist in the shared types directory).
63
73
  */
64
74
  export declare function generate(options: GenerateOptions): GenerateResult;
65
75
  export { generateClientFile } from './client';
@@ -20,21 +20,24 @@ const utils_1 = require("./utils");
20
20
  // Main orchestrator
21
21
  // ============================================================================
22
22
  /**
23
- * Generate all SDK files for tables only (legacy function signature)
23
+ * Generate all SDK files for tables only
24
24
  */
25
25
  function generateAllFiles(tables, config) {
26
26
  return generate({ tables, config });
27
27
  }
28
28
  /**
29
29
  * Generate all SDK files with full support for custom operations
30
+ *
31
+ * When sharedTypesPath is provided, types.ts and schema-types.ts are NOT generated
32
+ * (they're expected to exist in the shared types directory).
30
33
  */
31
34
  function generate(options) {
32
- const { tables, customOperations, config } = options;
35
+ const { tables, customOperations, config, sharedTypesPath } = options;
33
36
  const files = [];
34
37
  // Extract codegen options
35
38
  const maxDepth = config.codegen.maxFieldDepth;
36
39
  const skipQueryField = config.codegen.skipQueryField;
37
- const reactQueryEnabled = config.reactQuery.enabled;
40
+ const reactQueryEnabled = config.reactQuery;
38
41
  // Query key configuration (use defaults if not provided)
39
42
  const queryKeyConfig = config.queryKeys ?? config_1.DEFAULT_QUERY_KEY_CONFIG;
40
43
  const useCentralizedKeys = queryKeyConfig.generateScopedKeys;
@@ -46,32 +49,49 @@ function generate(options) {
46
49
  });
47
50
  // Collect table type names for import path resolution
48
51
  const tableTypeNames = new Set(tables.map((t) => (0, utils_1.getTableNames)(t).typeName));
49
- // 2. Generate schema-types.ts for custom operations (if any)
50
- // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
52
+ // When using shared types, skip generating types.ts and schema-types.ts
53
+ // They're already generated in the shared directory
51
54
  let hasSchemaTypes = false;
52
55
  let generatedEnumNames = [];
53
- if (customOperations && customOperations.typeRegistry) {
54
- const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
55
- typeRegistry: customOperations.typeRegistry,
56
- tableTypeNames,
57
- });
58
- // Only include if there's meaningful content
59
- if (schemaTypesResult.content.split('\n').length > 10) {
60
- files.push({
61
- path: 'schema-types.ts',
62
- content: schemaTypesResult.content,
56
+ if (sharedTypesPath) {
57
+ // Using shared types - check if schema-types would be generated
58
+ if (customOperations && customOperations.typeRegistry) {
59
+ const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
60
+ typeRegistry: customOperations.typeRegistry,
61
+ tableTypeNames,
63
62
  });
64
- hasSchemaTypes = true;
65
- generatedEnumNames = schemaTypesResult.generatedEnums || [];
63
+ if (schemaTypesResult.content.split('\n').length > 10) {
64
+ hasSchemaTypes = true;
65
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
66
+ }
66
67
  }
67
68
  }
68
- // 3. Generate types.ts (can now import enums from schema-types)
69
- files.push({
70
- path: 'types.ts',
71
- content: (0, types_1.generateTypesFile)(tables, {
72
- enumsFromSchemaTypes: generatedEnumNames,
73
- }),
74
- });
69
+ else {
70
+ // 2. Generate schema-types.ts for custom operations (if any)
71
+ // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
72
+ if (customOperations && customOperations.typeRegistry) {
73
+ const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
74
+ typeRegistry: customOperations.typeRegistry,
75
+ tableTypeNames,
76
+ });
77
+ // Only include if there's meaningful content
78
+ if (schemaTypesResult.content.split('\n').length > 10) {
79
+ files.push({
80
+ path: 'schema-types.ts',
81
+ content: schemaTypesResult.content,
82
+ });
83
+ hasSchemaTypes = true;
84
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
85
+ }
86
+ }
87
+ // 3. Generate types.ts (can now import enums from schema-types)
88
+ files.push({
89
+ path: 'types.ts',
90
+ content: (0, types_1.generateTypesFile)(tables, {
91
+ enumsFromSchemaTypes: generatedEnumNames,
92
+ }),
93
+ });
94
+ }
75
95
  // 3b. Generate centralized query keys (query-keys.ts)
76
96
  let hasQueryKeys = false;
77
97
  if (useCentralizedKeys) {
@@ -5,10 +5,10 @@
5
5
  * for parent-child entity relationships.
6
6
  */
7
7
  import type { CleanTable } from '../../types/schema';
8
- import type { ResolvedQueryKeyConfig } from '../../types/config';
8
+ import type { QueryKeyConfig } from '../../types/config';
9
9
  export interface InvalidationGeneratorOptions {
10
10
  tables: CleanTable[];
11
- config: ResolvedQueryKeyConfig;
11
+ config: QueryKeyConfig;
12
12
  }
13
13
  export interface GeneratedInvalidationFile {
14
14
  fileName: string;
@@ -8,11 +8,11 @@
8
8
  * - Tracking mutation state with useIsMutating
9
9
  */
10
10
  import type { CleanTable, CleanOperation } from '../../types/schema';
11
- import type { ResolvedQueryKeyConfig } from '../../types/config';
11
+ import type { QueryKeyConfig } from '../../types/config';
12
12
  export interface MutationKeyGeneratorOptions {
13
13
  tables: CleanTable[];
14
14
  customMutations: CleanOperation[];
15
- config: ResolvedQueryKeyConfig;
15
+ config: QueryKeyConfig;
16
16
  }
17
17
  export interface GeneratedMutationKeysFile {
18
18
  fileName: string;
@@ -410,10 +410,9 @@ function generateCreateClientFile(tables, hasCustomQueries, hasCustomMutations)
410
410
  ], t.stringLiteral('./query-builder')));
411
411
  // export * from './select-types';
412
412
  statements.push(t.exportAllDeclaration(t.stringLiteral('./select-types')));
413
- // Re-export all models for backwards compatibility
414
- // export * from './models';
413
+ // Re-export all models
415
414
  statements.push(t.exportAllDeclaration(t.stringLiteral('./models')));
416
- // Re-export custom operations for backwards compatibility
415
+ // Re-export custom operations
417
416
  if (hasCustomQueries) {
418
417
  statements.push(t.exportNamedDeclaration(null, [
419
418
  t.exportSpecifier(t.identifier('createQueryOperations'), t.identifier('createQueryOperations')),
@@ -5,7 +5,7 @@
5
5
  * and produces the complete ORM client output.
6
6
  */
7
7
  import type { CleanTable, CleanOperation, TypeRegistry } from '../../../types/schema';
8
- import type { ResolvedConfig } from '../../../types/config';
8
+ import type { GraphQLSDKConfigTarget } from '../../../types/config';
9
9
  export interface GeneratedFile {
10
10
  path: string;
11
11
  content: string;
@@ -17,7 +17,14 @@ export interface GenerateOrmOptions {
17
17
  mutations: CleanOperation[];
18
18
  typeRegistry?: TypeRegistry;
19
19
  };
20
- config: ResolvedConfig;
20
+ config: GraphQLSDKConfigTarget;
21
+ /**
22
+ * Path to shared types directory (relative import path).
23
+ * When provided, entity types are imported from shared types
24
+ * instead of being generated in input-types.ts.
25
+ * Example: '..' means types are in parent directory
26
+ */
27
+ sharedTypesPath?: string;
21
28
  }
22
29
  export interface GenerateOrmResult {
23
30
  files: GeneratedFile[];
@@ -11,9 +11,10 @@ const input_types_generator_1 = require("./input-types-generator");
11
11
  * Generate all ORM client files
12
12
  */
13
13
  function generateOrm(options) {
14
- const { tables, customOperations, config } = options;
14
+ const { tables, customOperations, sharedTypesPath } = options;
15
15
  const files = [];
16
- const useSharedTypes = config.orm.useSharedTypes;
16
+ // Use shared types when a sharedTypesPath is provided (unified output mode)
17
+ const useSharedTypes = !!sharedTypesPath;
17
18
  const hasCustomQueries = (customOperations?.queries.length ?? 0) > 0;
18
19
  const hasCustomMutations = (customOperations?.mutations.length ?? 0) > 0;
19
20
  const typeRegistry = customOperations?.typeRegistry;
@@ -1,9 +1,9 @@
1
1
  import type { CleanTable, CleanOperation } from '../../types/schema';
2
- import type { ResolvedQueryKeyConfig } from '../../types/config';
2
+ import type { QueryKeyConfig } from '../../types/config';
3
3
  export interface QueryKeyGeneratorOptions {
4
4
  tables: CleanTable[];
5
5
  customQueries: CleanOperation[];
6
- config: ResolvedQueryKeyConfig;
6
+ config: QueryKeyConfig;
7
7
  }
8
8
  export interface GeneratedQueryKeysFile {
9
9
  fileName: string;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Shared types generator
3
+ *
4
+ * Generates shared TypeScript types that can be imported by both
5
+ * React Query SDK and ORM client outputs.
6
+ *
7
+ * Output structure:
8
+ * shared/
9
+ * index.ts - Barrel export
10
+ * types.ts - Entity interfaces
11
+ * schema-types.ts - Enums, input types, payload types
12
+ * filters.ts - Filter types (StringFilter, IntFilter, etc.)
13
+ */
14
+ import type { CleanTable, CleanOperation, TypeRegistry } from '../../../types/schema';
15
+ import type { GraphQLSDKConfigTarget } from '../../../types/config';
16
+ export interface GeneratedFile {
17
+ path: string;
18
+ content: string;
19
+ }
20
+ export interface GenerateSharedOptions {
21
+ tables: CleanTable[];
22
+ customOperations?: {
23
+ queries: CleanOperation[];
24
+ mutations: CleanOperation[];
25
+ typeRegistry: TypeRegistry;
26
+ };
27
+ config: GraphQLSDKConfigTarget;
28
+ }
29
+ export interface GenerateSharedResult {
30
+ files: GeneratedFile[];
31
+ generatedEnumNames: string[];
32
+ hasSchemaTypes: boolean;
33
+ }
34
+ /**
35
+ * Generate shared types that can be imported by both React Query SDK and ORM client
36
+ */
37
+ export declare function generateSharedTypes(options: GenerateSharedOptions): GenerateSharedResult;
38
+ export { generateTypesFile } from '../types';
39
+ export { generateSchemaTypesFile } from '../schema-types-generator';
@@ -0,0 +1,118 @@
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.generateSchemaTypesFile = exports.generateTypesFile = void 0;
37
+ exports.generateSharedTypes = generateSharedTypes;
38
+ const t = __importStar(require("@babel/types"));
39
+ const babel_ast_1 = require("../babel-ast");
40
+ const types_1 = require("../types");
41
+ const schema_types_generator_1 = require("../schema-types-generator");
42
+ const utils_1 = require("../utils");
43
+ /**
44
+ * Helper to create export * from './module' statement
45
+ */
46
+ function exportAllFrom(modulePath) {
47
+ return t.exportAllDeclaration(t.stringLiteral(modulePath));
48
+ }
49
+ /**
50
+ * Generate shared types that can be imported by both React Query SDK and ORM client
51
+ */
52
+ function generateSharedTypes(options) {
53
+ const { tables, customOperations } = options;
54
+ const files = [];
55
+ // Collect table type names for import path resolution
56
+ const tableTypeNames = new Set(tables.map((t) => (0, utils_1.getTableNames)(t).typeName));
57
+ // 1. Generate schema-types.ts for custom operations (if any)
58
+ // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
59
+ let hasSchemaTypes = false;
60
+ let generatedEnumNames = [];
61
+ if (customOperations && customOperations.typeRegistry) {
62
+ const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
63
+ typeRegistry: customOperations.typeRegistry,
64
+ tableTypeNames,
65
+ });
66
+ // Only include if there's meaningful content
67
+ if (schemaTypesResult.content.split('\n').length > 10) {
68
+ files.push({
69
+ path: 'schema-types.ts',
70
+ content: schemaTypesResult.content,
71
+ });
72
+ hasSchemaTypes = true;
73
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
74
+ }
75
+ }
76
+ // 2. Generate types.ts (entity interfaces and filter types)
77
+ files.push({
78
+ path: 'types.ts',
79
+ content: (0, types_1.generateTypesFile)(tables, {
80
+ enumsFromSchemaTypes: generatedEnumNames,
81
+ }),
82
+ });
83
+ // 3. Generate barrel export (index.ts)
84
+ const barrelContent = generateSharedBarrel(hasSchemaTypes);
85
+ files.push({
86
+ path: 'index.ts',
87
+ content: barrelContent,
88
+ });
89
+ return {
90
+ files,
91
+ generatedEnumNames,
92
+ hasSchemaTypes,
93
+ };
94
+ }
95
+ /**
96
+ * Generate the barrel export for shared types using Babel AST
97
+ */
98
+ function generateSharedBarrel(hasSchemaTypes) {
99
+ const statements = [];
100
+ // Export types
101
+ statements.push(exportAllFrom('./types'));
102
+ // Export schema types if present
103
+ if (hasSchemaTypes) {
104
+ statements.push(exportAllFrom('./schema-types'));
105
+ }
106
+ // Add file header as leading comment on first statement
107
+ if (statements.length > 0) {
108
+ (0, babel_ast_1.addJSDocComment)(statements[0], [
109
+ 'Shared types - auto-generated, do not edit',
110
+ '@generated by @constructive-io/graphql-codegen',
111
+ ]);
112
+ }
113
+ return (0, babel_ast_1.generateCode)(statements);
114
+ }
115
+ var types_2 = require("../types");
116
+ Object.defineProperty(exports, "generateTypesFile", { enumerable: true, get: function () { return types_2.generateTypesFile; } });
117
+ var schema_types_generator_2 = require("../schema-types-generator");
118
+ Object.defineProperty(exports, "generateSchemaTypesFile", { enumerable: true, get: function () { return schema_types_generator_2.generateSchemaTypesFile; } });
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Configuration module exports
3
+ */
4
+ export { CONFIG_FILENAME, findConfigFile, loadConfigFile, type LoadConfigFileResult, } from './loader';
5
+ export { loadAndResolveConfig, loadWatchConfig, type ConfigOverrideOptions, type LoadConfigResult, } from './resolver';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration module exports
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.loadWatchConfig = exports.loadAndResolveConfig = exports.loadConfigFile = exports.findConfigFile = exports.CONFIG_FILENAME = void 0;
7
+ var loader_1 = require("./loader");
8
+ Object.defineProperty(exports, "CONFIG_FILENAME", { enumerable: true, get: function () { return loader_1.CONFIG_FILENAME; } });
9
+ Object.defineProperty(exports, "findConfigFile", { enumerable: true, get: function () { return loader_1.findConfigFile; } });
10
+ Object.defineProperty(exports, "loadConfigFile", { enumerable: true, get: function () { return loader_1.loadConfigFile; } });
11
+ var resolver_1 = require("./resolver");
12
+ Object.defineProperty(exports, "loadAndResolveConfig", { enumerable: true, get: function () { return resolver_1.loadAndResolveConfig; } });
13
+ Object.defineProperty(exports, "loadWatchConfig", { enumerable: true, get: function () { return resolver_1.loadWatchConfig; } });
@@ -0,0 +1,18 @@
1
+ export declare const CONFIG_FILENAME = "graphql-codegen.config.ts";
2
+ /**
3
+ * Find the nearest config file by walking up directories
4
+ */
5
+ export declare function findConfigFile(startDir?: string): string | null;
6
+ export interface LoadConfigFileResult {
7
+ success: boolean;
8
+ config?: any;
9
+ error?: string;
10
+ }
11
+ /**
12
+ * Load and validate a config file
13
+ *
14
+ * Uses jiti to support TypeScript config files (.ts) in addition to
15
+ * JavaScript (.js, .mjs, .cjs) without requiring the user to have
16
+ * tsx or ts-node installed.
17
+ */
18
+ export declare function loadConfigFile(configPath: string): Promise<LoadConfigFileResult>;