@constructive-io/graphql-codegen 2.32.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} +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;
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Sanitize function that splits comma-separated strings into arrays
3
+ */
4
+ export const splitCommas = (input) => {
5
+ if (!input)
6
+ return undefined;
7
+ return input.split(',').map((s) => s.trim()).filter(Boolean);
8
+ };
9
+ /**
10
+ * Questions for the codegen CLI
11
+ */
12
+ export const codegenQuestions = [
13
+ {
14
+ name: 'endpoint',
15
+ message: 'GraphQL endpoint URL',
16
+ type: 'text',
17
+ required: false,
18
+ },
19
+ {
20
+ name: 'schemaFile',
21
+ message: 'Path to GraphQL schema file',
22
+ type: 'text',
23
+ required: false,
24
+ },
25
+ {
26
+ name: 'output',
27
+ message: 'Output directory',
28
+ type: 'text',
29
+ required: false,
30
+ default: 'codegen',
31
+ useDefault: true,
32
+ },
33
+ {
34
+ name: 'schemas',
35
+ message: 'PostgreSQL schemas (comma-separated)',
36
+ type: 'text',
37
+ required: false,
38
+ sanitize: splitCommas,
39
+ },
40
+ {
41
+ name: 'apiNames',
42
+ message: 'API names (comma-separated)',
43
+ type: 'text',
44
+ required: false,
45
+ sanitize: splitCommas,
46
+ },
47
+ {
48
+ name: 'reactQuery',
49
+ message: 'Generate React Query hooks?',
50
+ type: 'confirm',
51
+ required: false,
52
+ default: false,
53
+ useDefault: true,
54
+ },
55
+ {
56
+ name: 'orm',
57
+ message: 'Generate ORM client?',
58
+ type: 'confirm',
59
+ required: false,
60
+ default: false,
61
+ useDefault: true,
62
+ },
63
+ {
64
+ name: 'authorization',
65
+ message: 'Authorization header value',
66
+ type: 'text',
67
+ required: false,
68
+ },
69
+ {
70
+ name: 'dryRun',
71
+ message: 'Preview without writing files?',
72
+ type: 'confirm',
73
+ required: false,
74
+ default: false,
75
+ useDefault: true,
76
+ },
77
+ {
78
+ name: 'verbose',
79
+ message: 'Verbose output?',
80
+ type: 'confirm',
81
+ required: false,
82
+ default: false,
83
+ useDefault: true,
84
+ },
85
+ ];
86
+ /**
87
+ * Print the result of a generate operation
88
+ */
89
+ export function printResult(result) {
90
+ if (result.success) {
91
+ console.log('[ok]', result.message);
92
+ if (result.tables?.length) {
93
+ console.log('Tables:', result.tables.join(', '));
94
+ }
95
+ }
96
+ else {
97
+ console.error('x', result.message);
98
+ result.errors?.forEach((e) => console.error(' -', e));
99
+ process.exit(1);
100
+ }
101
+ }
@@ -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
  */
@@ -63,10 +63,7 @@ export function generateMutationsBarrel(tables) {
63
63
  return generateCode(statements);
64
64
  }
65
65
  export function generateMainBarrel(tables, options = {}) {
66
- // Support legacy signature where second arg was just hasSchemaTypes boolean
67
- const opts = typeof options === 'boolean'
68
- ? { hasSchemaTypes: options, hasMutations: true }
69
- : options;
66
+ const opts = options;
70
67
  const { hasSchemaTypes = false, hasMutations = true, hasQueryKeys = false, hasMutationKeys = false, hasInvalidation = false, } = opts;
71
68
  const tableNames = tables.map((tbl) => tbl.name).join(', ');
72
69
  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';
@@ -15,21 +15,24 @@ import { getTableNames } from './utils';
15
15
  // Main orchestrator
16
16
  // ============================================================================
17
17
  /**
18
- * Generate all SDK files for tables only (legacy function signature)
18
+ * Generate all SDK files for tables only
19
19
  */
20
20
  export function generateAllFiles(tables, config) {
21
21
  return generate({ tables, config });
22
22
  }
23
23
  /**
24
24
  * Generate all SDK files with full support for custom operations
25
+ *
26
+ * When sharedTypesPath is provided, types.ts and schema-types.ts are NOT generated
27
+ * (they're expected to exist in the shared types directory).
25
28
  */
26
29
  export function generate(options) {
27
- const { tables, customOperations, config } = options;
30
+ const { tables, customOperations, config, sharedTypesPath } = options;
28
31
  const files = [];
29
32
  // Extract codegen options
30
33
  const maxDepth = config.codegen.maxFieldDepth;
31
34
  const skipQueryField = config.codegen.skipQueryField;
32
- const reactQueryEnabled = config.reactQuery.enabled;
35
+ const reactQueryEnabled = config.reactQuery;
33
36
  // Query key configuration (use defaults if not provided)
34
37
  const queryKeyConfig = config.queryKeys ?? DEFAULT_QUERY_KEY_CONFIG;
35
38
  const useCentralizedKeys = queryKeyConfig.generateScopedKeys;
@@ -41,32 +44,49 @@ export function generate(options) {
41
44
  });
42
45
  // Collect table type names for import path resolution
43
46
  const tableTypeNames = new Set(tables.map((t) => getTableNames(t).typeName));
44
- // 2. Generate schema-types.ts for custom operations (if any)
45
- // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
47
+ // When using shared types, skip generating types.ts and schema-types.ts
48
+ // They're already generated in the shared directory
46
49
  let hasSchemaTypes = false;
47
50
  let generatedEnumNames = [];
48
- if (customOperations && customOperations.typeRegistry) {
49
- const schemaTypesResult = generateSchemaTypesFile({
50
- typeRegistry: customOperations.typeRegistry,
51
- tableTypeNames,
52
- });
53
- // Only include if there's meaningful content
54
- if (schemaTypesResult.content.split('\n').length > 10) {
55
- files.push({
56
- path: 'schema-types.ts',
57
- content: schemaTypesResult.content,
51
+ if (sharedTypesPath) {
52
+ // Using shared types - check if schema-types would be generated
53
+ if (customOperations && customOperations.typeRegistry) {
54
+ const schemaTypesResult = generateSchemaTypesFile({
55
+ typeRegistry: customOperations.typeRegistry,
56
+ tableTypeNames,
58
57
  });
59
- hasSchemaTypes = true;
60
- generatedEnumNames = schemaTypesResult.generatedEnums || [];
58
+ if (schemaTypesResult.content.split('\n').length > 10) {
59
+ hasSchemaTypes = true;
60
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
61
+ }
61
62
  }
62
63
  }
63
- // 3. Generate types.ts (can now import enums from schema-types)
64
- files.push({
65
- path: 'types.ts',
66
- content: generateTypesFile(tables, {
67
- enumsFromSchemaTypes: generatedEnumNames,
68
- }),
69
- });
64
+ else {
65
+ // 2. Generate schema-types.ts for custom operations (if any)
66
+ // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
67
+ if (customOperations && customOperations.typeRegistry) {
68
+ const schemaTypesResult = generateSchemaTypesFile({
69
+ typeRegistry: customOperations.typeRegistry,
70
+ tableTypeNames,
71
+ });
72
+ // Only include if there's meaningful content
73
+ if (schemaTypesResult.content.split('\n').length > 10) {
74
+ files.push({
75
+ path: 'schema-types.ts',
76
+ content: schemaTypesResult.content,
77
+ });
78
+ hasSchemaTypes = true;
79
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
80
+ }
81
+ }
82
+ // 3. Generate types.ts (can now import enums from schema-types)
83
+ files.push({
84
+ path: 'types.ts',
85
+ content: generateTypesFile(tables, {
86
+ enumsFromSchemaTypes: generatedEnumNames,
87
+ }),
88
+ });
89
+ }
70
90
  // 3b. Generate centralized query keys (query-keys.ts)
71
91
  let hasQueryKeys = false;
72
92
  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;
@@ -371,10 +371,9 @@ export function generateCreateClientFile(tables, hasCustomQueries, hasCustomMuta
371
371
  ], t.stringLiteral('./query-builder')));
372
372
  // export * from './select-types';
373
373
  statements.push(t.exportAllDeclaration(t.stringLiteral('./select-types')));
374
- // Re-export all models for backwards compatibility
375
- // export * from './models';
374
+ // Re-export all models
376
375
  statements.push(t.exportAllDeclaration(t.stringLiteral('./models')));
377
- // Re-export custom operations for backwards compatibility
376
+ // Re-export custom operations
378
377
  if (hasCustomQueries) {
379
378
  statements.push(t.exportNamedDeclaration(null, [
380
379
  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[];
@@ -7,9 +7,10 @@ import { generateInputTypesFile, collectInputTypeNames, collectPayloadTypeNames
7
7
  * Generate all ORM client files
8
8
  */
9
9
  export function generateOrm(options) {
10
- const { tables, customOperations, config } = options;
10
+ const { tables, customOperations, sharedTypesPath } = options;
11
11
  const files = [];
12
- const useSharedTypes = config.orm.useSharedTypes;
12
+ // Use shared types when a sharedTypesPath is provided (unified output mode)
13
+ const useSharedTypes = !!sharedTypesPath;
13
14
  const hasCustomQueries = (customOperations?.queries.length ?? 0) > 0;
14
15
  const hasCustomMutations = (customOperations?.mutations.length ?? 0) > 0;
15
16
  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,79 @@
1
+ import * as t from '@babel/types';
2
+ import { generateCode, addJSDocComment } from '../babel-ast';
3
+ import { generateTypesFile } from '../types';
4
+ import { generateSchemaTypesFile } from '../schema-types-generator';
5
+ import { getTableNames } from '../utils';
6
+ /**
7
+ * Helper to create export * from './module' statement
8
+ */
9
+ function exportAllFrom(modulePath) {
10
+ return t.exportAllDeclaration(t.stringLiteral(modulePath));
11
+ }
12
+ /**
13
+ * Generate shared types that can be imported by both React Query SDK and ORM client
14
+ */
15
+ export function generateSharedTypes(options) {
16
+ const { tables, customOperations } = options;
17
+ const files = [];
18
+ // Collect table type names for import path resolution
19
+ const tableTypeNames = new Set(tables.map((t) => getTableNames(t).typeName));
20
+ // 1. Generate schema-types.ts for custom operations (if any)
21
+ // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
22
+ let hasSchemaTypes = false;
23
+ let generatedEnumNames = [];
24
+ if (customOperations && customOperations.typeRegistry) {
25
+ const schemaTypesResult = generateSchemaTypesFile({
26
+ typeRegistry: customOperations.typeRegistry,
27
+ tableTypeNames,
28
+ });
29
+ // Only include if there's meaningful content
30
+ if (schemaTypesResult.content.split('\n').length > 10) {
31
+ files.push({
32
+ path: 'schema-types.ts',
33
+ content: schemaTypesResult.content,
34
+ });
35
+ hasSchemaTypes = true;
36
+ generatedEnumNames = schemaTypesResult.generatedEnums || [];
37
+ }
38
+ }
39
+ // 2. Generate types.ts (entity interfaces and filter types)
40
+ files.push({
41
+ path: 'types.ts',
42
+ content: generateTypesFile(tables, {
43
+ enumsFromSchemaTypes: generatedEnumNames,
44
+ }),
45
+ });
46
+ // 3. Generate barrel export (index.ts)
47
+ const barrelContent = generateSharedBarrel(hasSchemaTypes);
48
+ files.push({
49
+ path: 'index.ts',
50
+ content: barrelContent,
51
+ });
52
+ return {
53
+ files,
54
+ generatedEnumNames,
55
+ hasSchemaTypes,
56
+ };
57
+ }
58
+ /**
59
+ * Generate the barrel export for shared types using Babel AST
60
+ */
61
+ function generateSharedBarrel(hasSchemaTypes) {
62
+ const statements = [];
63
+ // Export types
64
+ statements.push(exportAllFrom('./types'));
65
+ // Export schema types if present
66
+ if (hasSchemaTypes) {
67
+ statements.push(exportAllFrom('./schema-types'));
68
+ }
69
+ // Add file header as leading comment on first statement
70
+ if (statements.length > 0) {
71
+ addJSDocComment(statements[0], [
72
+ 'Shared types - auto-generated, do not edit',
73
+ '@generated by @constructive-io/graphql-codegen',
74
+ ]);
75
+ }
76
+ return generateCode(statements);
77
+ }
78
+ export { generateTypesFile } from '../types';
79
+ export { generateSchemaTypesFile } from '../schema-types-generator';
@@ -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,5 @@
1
+ /**
2
+ * Configuration module exports
3
+ */
4
+ export { CONFIG_FILENAME, findConfigFile, loadConfigFile, } from './loader';
5
+ export { loadAndResolveConfig, loadWatchConfig, } from './resolver';
@@ -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>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Configuration file loading utilities
3
+ *
4
+ * Pure functions for finding and loading graphql-codegen configuration files.
5
+ * These are core utilities that can be used programmatically or by the CLI.
6
+ */
7
+ import * as fs from 'node:fs';
8
+ import * as path from 'node:path';
9
+ import { createJiti } from 'jiti';
10
+ export const CONFIG_FILENAME = 'graphql-codegen.config.ts';
11
+ /**
12
+ * Find the nearest config file by walking up directories
13
+ */
14
+ export function findConfigFile(startDir = process.cwd()) {
15
+ let currentDir = startDir;
16
+ while (true) {
17
+ const configPath = path.join(currentDir, CONFIG_FILENAME);
18
+ if (fs.existsSync(configPath)) {
19
+ return configPath;
20
+ }
21
+ const parentDir = path.dirname(currentDir);
22
+ if (parentDir === currentDir) {
23
+ // Reached root
24
+ return null;
25
+ }
26
+ currentDir = parentDir;
27
+ }
28
+ }
29
+ /**
30
+ * Load and validate a config file
31
+ *
32
+ * Uses jiti to support TypeScript config files (.ts) in addition to
33
+ * JavaScript (.js, .mjs, .cjs) without requiring the user to have
34
+ * tsx or ts-node installed.
35
+ */
36
+ export async function loadConfigFile(configPath) {
37
+ const resolvedPath = path.resolve(configPath);
38
+ if (!fs.existsSync(resolvedPath)) {
39
+ return {
40
+ success: false,
41
+ error: `Config file not found: ${resolvedPath}`,
42
+ };
43
+ }
44
+ try {
45
+ // Use jiti to load TypeScript/ESM config files seamlessly
46
+ // jiti handles .ts, .js, .mjs, .cjs and ESM/CJS interop
47
+ const jiti = createJiti(__filename, {
48
+ interopDefault: true,
49
+ debug: process.env.JITI_DEBUG === '1',
50
+ });
51
+ // jiti.import() with { default: true } returns mod?.default ?? mod
52
+ const config = await jiti.import(resolvedPath, { default: true });
53
+ if (!config || typeof config !== 'object') {
54
+ return {
55
+ success: false,
56
+ error: 'Config file must export a configuration object',
57
+ };
58
+ }
59
+ return {
60
+ success: true,
61
+ config,
62
+ };
63
+ }
64
+ catch (err) {
65
+ const message = err instanceof Error ? err.message : 'Unknown error';
66
+ return {
67
+ success: false,
68
+ error: `Failed to load config file: ${message}`,
69
+ };
70
+ }
71
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Configuration resolution utilities
3
+ *
4
+ * Functions for resolving and merging configuration from various sources
5
+ * (config file, CLI options, defaults) into a final resolved configuration.
6
+ */
7
+ import type { GraphQLSDKConfigTarget } from '../../types/config';
8
+ /**
9
+ * Options that can override config file settings.
10
+ * Extends GraphQLSDKConfigTarget with CLI-specific fields.
11
+ */
12
+ export interface ConfigOverrideOptions extends GraphQLSDKConfigTarget {
13
+ /** Path to config file (CLI-only) */
14
+ config?: string;
15
+ }
16
+ /**
17
+ * Result of loading and resolving configuration
18
+ */
19
+ export interface LoadConfigResult {
20
+ success: boolean;
21
+ config?: GraphQLSDKConfigTarget;
22
+ error?: string;
23
+ }
24
+ /**
25
+ * Load and resolve configuration from file and/or options
26
+ *
27
+ * This is the main entry point for configuration loading. It:
28
+ * 1. Finds and loads the config file (if any)
29
+ * 2. Applies CLI option overrides
30
+ * 3. Returns fully resolved configuration ready for use
31
+ */
32
+ export declare function loadAndResolveConfig(options: ConfigOverrideOptions): Promise<LoadConfigResult>;
33
+ /**
34
+ * Build watch configuration from options
35
+ *
36
+ * Used by watch mode to resolve configuration with watch-specific overrides.
37
+ */
38
+ export declare function loadWatchConfig(options: {
39
+ config?: string;
40
+ endpoint?: string;
41
+ output?: string;
42
+ pollInterval?: number;
43
+ debounce?: number;
44
+ touch?: string;
45
+ clear?: boolean;
46
+ }): Promise<GraphQLSDKConfigTarget | null>;