@constructive-io/graphql-codegen 3.2.1 → 3.3.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 (215) hide show
  1. package/cli/index.js +36 -43
  2. package/cli/shared.d.ts +15 -19
  3. package/cli/shared.js +104 -25
  4. package/client/error.js +31 -9
  5. package/client/execute.js +2 -2
  6. package/client/index.d.ts +3 -3
  7. package/client/index.js +6 -6
  8. package/core/ast.d.ts +1 -1
  9. package/core/ast.js +1 -1
  10. package/core/codegen/babel-ast.d.ts +1 -1
  11. package/core/codegen/babel-ast.js +2 -2
  12. package/core/codegen/barrel.d.ts +0 -6
  13. package/core/codegen/barrel.js +22 -19
  14. package/core/codegen/client.d.ts +2 -12
  15. package/core/codegen/client.js +7 -21
  16. package/core/codegen/custom-mutations.d.ts +0 -14
  17. package/core/codegen/custom-mutations.js +139 -88
  18. package/core/codegen/custom-queries.d.ts +0 -14
  19. package/core/codegen/custom-queries.js +483 -193
  20. package/core/codegen/hooks-ast.d.ts +75 -0
  21. package/core/codegen/hooks-ast.js +522 -0
  22. package/core/codegen/index.d.ts +16 -18
  23. package/core/codegen/index.js +42 -88
  24. package/core/codegen/invalidation.d.ts +1 -7
  25. package/core/codegen/invalidation.js +50 -16
  26. package/core/codegen/mutation-keys.d.ts +1 -10
  27. package/core/codegen/mutation-keys.js +22 -8
  28. package/core/codegen/mutations.d.ts +0 -13
  29. package/core/codegen/mutations.js +301 -366
  30. package/core/codegen/orm/barrel.d.ts +0 -5
  31. package/core/codegen/orm/barrel.js +5 -0
  32. package/core/codegen/orm/client-generator.d.ts +0 -5
  33. package/core/codegen/orm/client-generator.js +7 -2
  34. package/core/codegen/orm/client.js +3 -1
  35. package/core/codegen/orm/custom-ops-generator.d.ts +0 -6
  36. package/core/codegen/orm/custom-ops-generator.js +104 -51
  37. package/core/codegen/orm/index.d.ts +4 -4
  38. package/core/codegen/orm/index.js +28 -15
  39. package/core/codegen/orm/input-types-generator.d.ts +1 -13
  40. package/core/codegen/orm/input-types-generator.js +85 -23
  41. package/core/codegen/orm/model-generator.d.ts +0 -5
  42. package/core/codegen/orm/model-generator.js +309 -131
  43. package/core/codegen/orm/select-types.d.ts +19 -14
  44. package/core/codegen/queries.d.ts +0 -8
  45. package/core/codegen/queries.js +360 -559
  46. package/core/codegen/query-keys.d.ts +1 -1
  47. package/core/codegen/query-keys.js +37 -23
  48. package/core/codegen/scalars.js +3 -1
  49. package/core/codegen/schema-types-generator.d.ts +1 -1
  50. package/core/codegen/schema-types-generator.js +17 -2
  51. package/core/codegen/select-helpers.d.ts +19 -0
  52. package/core/codegen/select-helpers.js +40 -0
  53. package/core/codegen/selection.d.ts +4 -0
  54. package/core/codegen/selection.js +65 -0
  55. package/core/codegen/shared/index.d.ts +2 -15
  56. package/core/codegen/shared/index.js +17 -4
  57. package/core/codegen/templates/hooks-client.ts +49 -0
  58. package/core/codegen/templates/hooks-selection.ts +58 -0
  59. package/core/codegen/templates/orm-client.ts +8 -6
  60. package/core/codegen/templates/query-builder.ts +250 -46
  61. package/core/codegen/templates/select-types.ts +31 -14
  62. package/core/codegen/type-resolver.d.ts +1 -5
  63. package/core/codegen/type-resolver.js +0 -22
  64. package/core/codegen/types.d.ts +0 -3
  65. package/core/codegen/types.js +71 -14
  66. package/core/codegen/utils.d.ts +1 -4
  67. package/core/codegen/utils.js +4 -1
  68. package/core/config/index.d.ts +1 -1
  69. package/core/config/resolver.js +1 -3
  70. package/core/generate.js +38 -50
  71. package/core/index.d.ts +3 -3
  72. package/core/index.js +3 -4
  73. package/core/introspect/index.d.ts +6 -6
  74. package/core/introspect/index.js +5 -8
  75. package/core/introspect/infer-tables.d.ts +0 -14
  76. package/core/introspect/infer-tables.js +15 -1
  77. package/core/introspect/source/database.js +1 -1
  78. package/core/introspect/source/endpoint.d.ts +0 -6
  79. package/core/introspect/source/endpoint.js +7 -1
  80. package/core/introspect/source/index.d.ts +4 -4
  81. package/core/introspect/source/index.js +5 -9
  82. package/core/introspect/source/pgpm-module.js +3 -3
  83. package/core/introspect/transform-schema.d.ts +2 -2
  84. package/core/introspect/transform-schema.js +2 -2
  85. package/core/output/index.d.ts +1 -1
  86. package/core/output/index.js +2 -2
  87. package/core/output/writer.d.ts +3 -0
  88. package/core/output/writer.js +20 -1
  89. package/core/pipeline/index.d.ts +2 -2
  90. package/core/query-builder.d.ts +2 -2
  91. package/core/query-builder.js +1 -1
  92. package/core/watch/index.d.ts +4 -4
  93. package/core/watch/index.js +9 -9
  94. package/core/watch/orchestrator.js +5 -3
  95. package/esm/cli/index.js +37 -44
  96. package/esm/cli/shared.d.ts +15 -19
  97. package/esm/cli/shared.js +94 -23
  98. package/esm/client/error.js +31 -9
  99. package/esm/client/execute.js +2 -2
  100. package/esm/client/index.d.ts +3 -3
  101. package/esm/client/index.js +3 -3
  102. package/esm/core/ast.d.ts +1 -1
  103. package/esm/core/ast.js +1 -1
  104. package/esm/core/codegen/babel-ast.d.ts +1 -1
  105. package/esm/core/codegen/babel-ast.js +2 -2
  106. package/esm/core/codegen/barrel.d.ts +0 -6
  107. package/esm/core/codegen/barrel.js +23 -20
  108. package/esm/core/codegen/client.d.ts +2 -12
  109. package/esm/core/codegen/client.js +7 -21
  110. package/esm/core/codegen/custom-mutations.d.ts +0 -14
  111. package/esm/core/codegen/custom-mutations.js +141 -90
  112. package/esm/core/codegen/custom-queries.d.ts +0 -14
  113. package/esm/core/codegen/custom-queries.js +486 -196
  114. package/esm/core/codegen/hooks-ast.d.ts +75 -0
  115. package/esm/core/codegen/hooks-ast.js +424 -0
  116. package/esm/core/codegen/index.d.ts +16 -18
  117. package/esm/core/codegen/index.js +26 -71
  118. package/esm/core/codegen/invalidation.d.ts +1 -7
  119. package/esm/core/codegen/invalidation.js +51 -17
  120. package/esm/core/codegen/mutation-keys.d.ts +1 -10
  121. package/esm/core/codegen/mutation-keys.js +23 -9
  122. package/esm/core/codegen/mutations.d.ts +0 -13
  123. package/esm/core/codegen/mutations.js +302 -367
  124. package/esm/core/codegen/orm/barrel.d.ts +0 -5
  125. package/esm/core/codegen/orm/barrel.js +6 -1
  126. package/esm/core/codegen/orm/client-generator.d.ts +0 -5
  127. package/esm/core/codegen/orm/client-generator.js +7 -2
  128. package/esm/core/codegen/orm/client.js +3 -1
  129. package/esm/core/codegen/orm/custom-ops-generator.d.ts +0 -6
  130. package/esm/core/codegen/orm/custom-ops-generator.js +103 -50
  131. package/esm/core/codegen/orm/index.d.ts +4 -4
  132. package/esm/core/codegen/orm/index.js +25 -12
  133. package/esm/core/codegen/orm/input-types-generator.d.ts +1 -13
  134. package/esm/core/codegen/orm/input-types-generator.js +85 -23
  135. package/esm/core/codegen/orm/model-generator.d.ts +0 -5
  136. package/esm/core/codegen/orm/model-generator.js +310 -132
  137. package/esm/core/codegen/orm/select-types.d.ts +19 -14
  138. package/esm/core/codegen/queries.d.ts +0 -8
  139. package/esm/core/codegen/queries.js +362 -561
  140. package/esm/core/codegen/query-keys.d.ts +1 -1
  141. package/esm/core/codegen/query-keys.js +38 -24
  142. package/esm/core/codegen/scalars.js +3 -1
  143. package/esm/core/codegen/schema-types-generator.d.ts +1 -1
  144. package/esm/core/codegen/schema-types-generator.js +17 -2
  145. package/esm/core/codegen/select-helpers.d.ts +19 -0
  146. package/esm/core/codegen/select-helpers.js +35 -0
  147. package/esm/core/codegen/selection.d.ts +4 -0
  148. package/esm/core/codegen/selection.js +29 -0
  149. package/esm/core/codegen/shared/index.d.ts +2 -15
  150. package/esm/core/codegen/shared/index.js +16 -3
  151. package/esm/core/codegen/type-resolver.d.ts +1 -5
  152. package/esm/core/codegen/type-resolver.js +1 -22
  153. package/esm/core/codegen/types.d.ts +0 -3
  154. package/esm/core/codegen/types.js +72 -15
  155. package/esm/core/codegen/utils.d.ts +1 -4
  156. package/esm/core/codegen/utils.js +4 -1
  157. package/esm/core/config/index.d.ts +1 -1
  158. package/esm/core/config/resolver.js +2 -4
  159. package/esm/core/generate.js +38 -50
  160. package/esm/core/index.d.ts +3 -3
  161. package/esm/core/index.js +2 -3
  162. package/esm/core/introspect/index.d.ts +6 -6
  163. package/esm/core/introspect/index.js +3 -6
  164. package/esm/core/introspect/infer-tables.d.ts +0 -14
  165. package/esm/core/introspect/infer-tables.js +16 -2
  166. package/esm/core/introspect/source/database.js +2 -2
  167. package/esm/core/introspect/source/endpoint.d.ts +0 -6
  168. package/esm/core/introspect/source/endpoint.js +7 -1
  169. package/esm/core/introspect/source/index.d.ts +4 -4
  170. package/esm/core/introspect/source/index.js +6 -10
  171. package/esm/core/introspect/source/pgpm-module.js +3 -3
  172. package/esm/core/introspect/transform-schema.d.ts +2 -2
  173. package/esm/core/introspect/transform-schema.js +2 -2
  174. package/esm/core/output/index.d.ts +1 -1
  175. package/esm/core/output/index.js +1 -1
  176. package/esm/core/output/writer.d.ts +3 -0
  177. package/esm/core/output/writer.js +20 -1
  178. package/esm/core/pipeline/index.d.ts +2 -2
  179. package/esm/core/pipeline/index.js +2 -2
  180. package/esm/core/query-builder.d.ts +2 -2
  181. package/esm/core/query-builder.js +2 -2
  182. package/esm/core/watch/index.d.ts +4 -4
  183. package/esm/core/watch/index.js +3 -3
  184. package/esm/core/watch/orchestrator.js +5 -3
  185. package/esm/generators/index.d.ts +3 -3
  186. package/esm/generators/index.js +3 -3
  187. package/esm/generators/mutations.d.ts +1 -1
  188. package/esm/generators/select.d.ts +1 -1
  189. package/esm/index.d.ts +3 -3
  190. package/esm/index.js +1 -4
  191. package/esm/types/config.d.ts +0 -10
  192. package/esm/types/config.js +0 -2
  193. package/esm/types/index.d.ts +6 -6
  194. package/esm/types/index.js +1 -1
  195. package/generators/index.d.ts +3 -3
  196. package/generators/index.js +8 -8
  197. package/generators/mutations.d.ts +1 -1
  198. package/generators/select.d.ts +1 -1
  199. package/index.d.ts +3 -3
  200. package/index.js +11 -6
  201. package/package.json +10 -10
  202. package/types/config.d.ts +0 -10
  203. package/types/config.js +0 -2
  204. package/types/index.d.ts +6 -6
  205. package/types/index.js +2 -2
  206. package/core/codegen/gql-ast.d.ts +0 -41
  207. package/core/codegen/gql-ast.js +0 -353
  208. package/core/codegen/schema-gql-ast.d.ts +0 -51
  209. package/core/codegen/schema-gql-ast.js +0 -385
  210. package/core/codegen/templates/client.browser.ts +0 -271
  211. package/core/codegen/templates/client.node.ts +0 -337
  212. package/esm/core/codegen/gql-ast.d.ts +0 -41
  213. package/esm/core/codegen/gql-ast.js +0 -312
  214. package/esm/core/codegen/schema-gql-ast.d.ts +0 -51
  215. package/esm/core/codegen/schema-gql-ast.js +0 -343
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Shared Babel AST helpers for React Query hook generators
3
+ *
4
+ * Provides reusable AST-building functions for the common patterns
5
+ * used across queries.ts, mutations.ts, custom-queries.ts, and custom-mutations.ts.
6
+ */
7
+ import * as t from '@babel/types';
8
+ import type { CleanArgument } from '../../types/schema';
9
+ export declare function createImportDeclaration(moduleSpecifier: string, namedImports: string[], typeOnly?: boolean): t.ImportDeclaration;
10
+ export declare function createTypeReExport(names: string[], moduleSpecifier: string): t.ExportNamedDeclaration;
11
+ export declare function typeRef(name: string, params?: t.TSType[]): t.TSTypeReference;
12
+ export declare function sRef(): t.TSTypeReference;
13
+ export declare function typeofRef(name: string): t.TSTypeQuery;
14
+ export declare function stringLiteralType(value: string): t.TSLiteralType;
15
+ export declare function inferSelectResultType(entityTypeName: string, selectType: t.TSType): t.TSTypeReference;
16
+ export declare function connectionResultType(entityTypeName: string, selectType: t.TSType): t.TSTypeReference;
17
+ export declare function typeLiteralWithProps(props: Array<{
18
+ name: string;
19
+ type: t.TSType;
20
+ optional?: boolean;
21
+ }>): t.TSTypeLiteral;
22
+ export declare function queryResultType(queryName: string, innerType: t.TSType): t.TSTypeLiteral;
23
+ export declare function listQueryResultType(queryName: string, entityTypeName: string, selectType: t.TSType): t.TSTypeLiteral;
24
+ export declare function singleQueryResultType(queryName: string, entityTypeName: string, selectType: t.TSType, nullable?: boolean): t.TSTypeLiteral;
25
+ export declare function mutationResultType(mutationName: string, entityField: string, entityTypeName: string, selectType: t.TSType): t.TSTypeLiteral;
26
+ export declare function omitType(baseType: t.TSType, keys: string[]): t.TSTypeReference;
27
+ export declare function listSelectionConfigType(selectType: t.TSType, filterTypeName: string, orderByTypeName: string): t.TSTypeReference;
28
+ export declare function selectionConfigType(selectType: t.TSType): t.TSTypeReference;
29
+ export declare function strictSelectType(selectType: t.TSType, shapeTypeName: string): t.TSTypeReference;
30
+ export declare function withFieldsSelectionType(selectType: t.TSType, selectTypeName: string): t.TSIntersectionType;
31
+ export declare function withFieldsListSelectionType(selectType: t.TSType, selectTypeName: string, filterTypeName: string, orderByTypeName: string): t.TSIntersectionType;
32
+ export declare function useQueryOptionsType(queryDataType: t.TSType, dataType: t.TSType, extraProps?: t.TSType): t.TSType;
33
+ export declare function useQueryOptionsImplType(extraProps?: t.TSType): t.TSType;
34
+ export declare function useMutationOptionsType(resultType: t.TSType, varType: t.TSType): t.TSTypeReference;
35
+ export declare function useMutationResultType(resultType: t.TSType, varType: t.TSType): t.TSTypeReference;
36
+ export declare function createSTypeParam(constraintName: string): t.TSTypeParameterDeclaration;
37
+ export declare function createSAndTDataTypeParams(constraintName: string, defaultDataType: t.TSType): t.TSTypeParameterDeclaration;
38
+ export declare function createTDataTypeParam(defaultType: t.TSType): t.TSTypeParameterDeclaration;
39
+ export declare function createFunctionParam(name: string, typeAnnotation: t.TSType, optional?: boolean): t.Identifier;
40
+ export declare function exportDeclareFunction(name: string, typeParameters: t.TSTypeParameterDeclaration | null, params: t.Identifier[], returnType: t.TSType): t.ExportNamedDeclaration;
41
+ export declare function exportFunction(name: string, typeParameters: t.TSTypeParameterDeclaration | null, params: t.Identifier[], body: t.Statement[], returnType?: t.TSType): t.ExportNamedDeclaration;
42
+ export declare function exportAsyncFunction(name: string, typeParameters: t.TSTypeParameterDeclaration | null, params: t.Identifier[], body: t.Statement[], returnType?: t.TSType): t.ExportNamedDeclaration;
43
+ export declare function exportAsyncDeclareFunction(name: string, typeParameters: t.TSTypeParameterDeclaration | null, params: t.Identifier[], returnType: t.TSType): t.ExportNamedDeclaration;
44
+ export declare function callExpr(callee: string | t.Expression, args: (t.Expression | t.SpreadElement)[]): t.CallExpression;
45
+ export declare function memberExpr(obj: string, prop: string): t.MemberExpression;
46
+ export declare function optionalMemberExpr(obj: string, prop: string): t.OptionalMemberExpression;
47
+ export declare function arrowFn(params: t.Identifier[], body: t.Expression | t.BlockStatement): t.ArrowFunctionExpression;
48
+ export declare function awaitExpr(expr: t.Expression): t.AwaitExpression;
49
+ export declare function spreadObj(expr: t.Expression): t.SpreadElement;
50
+ export declare function objectProp(key: string, value: t.Expression, shorthand?: boolean): t.ObjectProperty;
51
+ export declare function shorthandProp(name: string): t.ObjectProperty;
52
+ export declare function constDecl(name: string, init: t.Expression): t.VariableDeclaration;
53
+ export declare function asConstExpr(expr: t.Expression): t.TSAsExpression;
54
+ export declare function asTypeExpr(expr: t.Expression, typeName: string): t.TSAsExpression;
55
+ export declare function voidStatement(name: string): t.ExpressionStatement;
56
+ export declare function returnUseQuery(queryKeyExpr: t.Expression, queryFnExpr: t.Expression, extraProps?: Array<t.ObjectProperty | t.SpreadElement>, enabledExpr?: t.Expression): t.ReturnStatement;
57
+ export declare function returnUseMutation(mutationFnExpr: t.Expression, extraProps: Array<t.ObjectProperty | t.SpreadElement>, mutationKeyExpr?: t.Expression): t.ReturnStatement;
58
+ export declare function destructureWithRest(source: t.Expression, keys: string[], restName: string): t.VariableDeclaration;
59
+ export declare function destructureParamsWithSelection(restName: string, extraKeys?: string[]): t.VariableDeclaration;
60
+ export declare function destructureParamsWithSelectionAndScope(restName: string): t.VariableDeclaration;
61
+ export declare function addJSDocComment<T extends t.Node>(node: T, lines: string[]): T;
62
+ export declare function addLineComment<T extends t.Node>(node: T, text: string): T;
63
+ export declare function getClientCall(modelName: string, method: string, args: t.Expression): t.CallExpression;
64
+ export declare function getClientCallUnwrap(modelName: string, method: string, args: t.Expression): t.CallExpression;
65
+ export declare function getClientCustomCall(operationType: 'query' | 'mutation', operationName: string, args: t.Expression[], optionsArg?: t.Expression): t.CallExpression;
66
+ export declare function getClientCustomCallUnwrap(operationType: 'query' | 'mutation', operationName: string, args: t.Expression[], optionsArg?: t.Expression): t.CallExpression;
67
+ export declare function buildFindManyCallExpr(singularName: string, argsIdent: string): t.CallExpression;
68
+ export declare function buildFindOneCallExpr(singularName: string, pkFieldName: string, argsIdent: string, paramsIdent?: string): t.CallExpression;
69
+ export declare function generateHookFileCode(headerDescription: string, statements: t.Statement[]): string;
70
+ export declare function scopeTypeLiteral(scopeTypeName: string): t.TSTypeLiteral;
71
+ export declare function wrapInferSelectResultType(typeRefNode: CleanArgument['type'], payloadTypeName: string, selectType: t.TSType): t.TSType;
72
+ export declare function typeRefToTsTypeAST(typeRefNode: CleanArgument['type']): t.TSType;
73
+ export declare function buildSelectionArgsCall(selectTypeName: string): t.VariableDeclaration;
74
+ export declare function buildListSelectionArgsCall(selectTypeName: string, filterTypeName: string, orderByTypeName: string): t.VariableDeclaration;
75
+ export declare function customSelectResultTypeLiteral(opName: string, returnType: CleanArgument['type'], payloadTypeName: string, selectType: t.TSType): t.TSTypeLiteral;
@@ -0,0 +1,424 @@
1
+ /**
2
+ * Shared Babel AST helpers for React Query hook generators
3
+ *
4
+ * Provides reusable AST-building functions for the common patterns
5
+ * used across queries.ts, mutations.ts, custom-queries.ts, and custom-mutations.ts.
6
+ */
7
+ import * as t from '@babel/types';
8
+ import { commentBlock, generateCode } from './babel-ast';
9
+ import { scalarToTsType } from './type-resolver';
10
+ import { getGeneratedFileHeader } from './utils';
11
+ // ============================================================================
12
+ // Import helpers
13
+ // ============================================================================
14
+ export function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
15
+ const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
16
+ const decl = t.importDeclaration(specifiers, t.stringLiteral(moduleSpecifier));
17
+ decl.importKind = typeOnly ? 'type' : 'value';
18
+ return decl;
19
+ }
20
+ export function createTypeReExport(names, moduleSpecifier) {
21
+ const specifiers = names.map((name) => t.exportSpecifier(t.identifier(name), t.identifier(name)));
22
+ const decl = t.exportNamedDeclaration(null, specifiers, t.stringLiteral(moduleSpecifier));
23
+ decl.exportKind = 'type';
24
+ return decl;
25
+ }
26
+ // ============================================================================
27
+ // Type reference helpers
28
+ // ============================================================================
29
+ export function typeRef(name, params) {
30
+ return t.tsTypeReference(t.identifier(name), params ? t.tsTypeParameterInstantiation(params) : undefined);
31
+ }
32
+ export function sRef() {
33
+ return typeRef('S');
34
+ }
35
+ export function typeofRef(name) {
36
+ return t.tsTypeQuery(t.identifier(name));
37
+ }
38
+ export function stringLiteralType(value) {
39
+ return t.tsLiteralType(t.stringLiteral(value));
40
+ }
41
+ // ============================================================================
42
+ // Complex type builders
43
+ // ============================================================================
44
+ export function inferSelectResultType(entityTypeName, selectType) {
45
+ return typeRef('InferSelectResult', [typeRef(entityTypeName), selectType]);
46
+ }
47
+ export function connectionResultType(entityTypeName, selectType) {
48
+ return typeRef('ConnectionResult', [
49
+ inferSelectResultType(entityTypeName, selectType),
50
+ ]);
51
+ }
52
+ export function typeLiteralWithProps(props) {
53
+ return t.tsTypeLiteral(props.map((p) => {
54
+ const prop = t.tsPropertySignature(t.identifier(p.name), t.tsTypeAnnotation(p.type));
55
+ if (p.optional) {
56
+ prop.optional = true;
57
+ }
58
+ return prop;
59
+ }));
60
+ }
61
+ export function queryResultType(queryName, innerType) {
62
+ return typeLiteralWithProps([{ name: queryName, type: innerType }]);
63
+ }
64
+ export function listQueryResultType(queryName, entityTypeName, selectType) {
65
+ return queryResultType(queryName, connectionResultType(entityTypeName, selectType));
66
+ }
67
+ export function singleQueryResultType(queryName, entityTypeName, selectType, nullable = true) {
68
+ const resultType = inferSelectResultType(entityTypeName, selectType);
69
+ const innerType = nullable
70
+ ? t.tsUnionType([resultType, t.tsNullKeyword()])
71
+ : resultType;
72
+ return queryResultType(queryName, innerType);
73
+ }
74
+ export function mutationResultType(mutationName, entityField, entityTypeName, selectType) {
75
+ return queryResultType(mutationName, typeLiteralWithProps([
76
+ {
77
+ name: entityField,
78
+ type: inferSelectResultType(entityTypeName, selectType),
79
+ },
80
+ ]));
81
+ }
82
+ export function omitType(baseType, keys) {
83
+ const keyType = keys.length === 1
84
+ ? stringLiteralType(keys[0])
85
+ : t.tsUnionType(keys.map(stringLiteralType));
86
+ return typeRef('Omit', [baseType, keyType]);
87
+ }
88
+ export function listSelectionConfigType(selectType, filterTypeName, orderByTypeName) {
89
+ return typeRef('ListSelectionConfig', [
90
+ selectType,
91
+ typeRef(filterTypeName),
92
+ typeRef(orderByTypeName),
93
+ ]);
94
+ }
95
+ export function selectionConfigType(selectType) {
96
+ return typeRef('SelectionConfig', [selectType]);
97
+ }
98
+ export function strictSelectType(selectType, shapeTypeName) {
99
+ return typeRef('StrictSelect', [selectType, typeRef(shapeTypeName)]);
100
+ }
101
+ export function withFieldsSelectionType(selectType, selectTypeName) {
102
+ return t.tsIntersectionType([
103
+ typeLiteralWithProps([{ name: 'fields', type: selectType }]),
104
+ strictSelectType(selectType, selectTypeName),
105
+ ]);
106
+ }
107
+ export function withFieldsListSelectionType(selectType, selectTypeName, filterTypeName, orderByTypeName) {
108
+ return t.tsIntersectionType([
109
+ typeLiteralWithProps([{ name: 'fields', type: selectType }]),
110
+ omitType(listSelectionConfigType(selectType, filterTypeName, orderByTypeName), ['fields']),
111
+ strictSelectType(selectType, selectTypeName),
112
+ ]);
113
+ }
114
+ export function useQueryOptionsType(queryDataType, dataType, extraProps) {
115
+ const base = omitType(typeRef('UseQueryOptions', [queryDataType, typeRef('Error'), dataType]), ['queryKey', 'queryFn']);
116
+ if (extraProps) {
117
+ return t.tsIntersectionType([base, extraProps]);
118
+ }
119
+ return base;
120
+ }
121
+ export function useQueryOptionsImplType(extraProps) {
122
+ const base = omitType(typeRef('UseQueryOptions', [
123
+ t.tsAnyKeyword(),
124
+ typeRef('Error'),
125
+ t.tsAnyKeyword(),
126
+ t.tsAnyKeyword(),
127
+ ]), ['queryKey', 'queryFn']);
128
+ if (extraProps) {
129
+ return t.tsIntersectionType([base, extraProps]);
130
+ }
131
+ return base;
132
+ }
133
+ export function useMutationOptionsType(resultType, varType) {
134
+ return omitType(typeRef('UseMutationOptions', [resultType, typeRef('Error'), varType]), ['mutationFn']);
135
+ }
136
+ export function useMutationResultType(resultType, varType) {
137
+ return typeRef('UseMutationResult', [resultType, typeRef('Error'), varType]);
138
+ }
139
+ // ============================================================================
140
+ // Type parameter helpers
141
+ // ============================================================================
142
+ export function createSTypeParam(constraintName) {
143
+ const param = t.tsTypeParameter(typeRef(constraintName), null, 'S');
144
+ return t.tsTypeParameterDeclaration([param]);
145
+ }
146
+ export function createSAndTDataTypeParams(constraintName, defaultDataType) {
147
+ const sParam = t.tsTypeParameter(typeRef(constraintName), null, 'S');
148
+ const tDataParam = t.tsTypeParameter(null, defaultDataType, 'TData');
149
+ return t.tsTypeParameterDeclaration([sParam, tDataParam]);
150
+ }
151
+ export function createTDataTypeParam(defaultType) {
152
+ const param = t.tsTypeParameter(null, defaultType, 'TData');
153
+ return t.tsTypeParameterDeclaration([param]);
154
+ }
155
+ // ============================================================================
156
+ // Function declaration helpers
157
+ // ============================================================================
158
+ export function createFunctionParam(name, typeAnnotation, optional = false) {
159
+ const param = t.identifier(name);
160
+ param.typeAnnotation = t.tsTypeAnnotation(typeAnnotation);
161
+ param.optional = optional;
162
+ return param;
163
+ }
164
+ export function exportDeclareFunction(name, typeParameters, params, returnType) {
165
+ const func = t.tsDeclareFunction(t.identifier(name), typeParameters, params, t.tsTypeAnnotation(returnType));
166
+ return t.exportNamedDeclaration(func);
167
+ }
168
+ export function exportFunction(name, typeParameters, params, body, returnType) {
169
+ const func = t.functionDeclaration(t.identifier(name), params, t.blockStatement(body));
170
+ func.typeParameters = typeParameters;
171
+ if (returnType) {
172
+ func.returnType = t.tsTypeAnnotation(returnType);
173
+ }
174
+ return t.exportNamedDeclaration(func);
175
+ }
176
+ export function exportAsyncFunction(name, typeParameters, params, body, returnType) {
177
+ const func = t.functionDeclaration(t.identifier(name), params, t.blockStatement(body));
178
+ func.async = true;
179
+ func.typeParameters = typeParameters;
180
+ if (returnType) {
181
+ func.returnType = t.tsTypeAnnotation(returnType);
182
+ }
183
+ return t.exportNamedDeclaration(func);
184
+ }
185
+ export function exportAsyncDeclareFunction(name, typeParameters, params, returnType) {
186
+ const func = t.tsDeclareFunction(t.identifier(name), typeParameters, params, t.tsTypeAnnotation(returnType));
187
+ func.async = true;
188
+ return t.exportNamedDeclaration(func);
189
+ }
190
+ // ============================================================================
191
+ // Expression helpers
192
+ // ============================================================================
193
+ export function callExpr(callee, args) {
194
+ const calleeExpr = typeof callee === 'string' ? t.identifier(callee) : callee;
195
+ return t.callExpression(calleeExpr, args);
196
+ }
197
+ export function memberExpr(obj, prop) {
198
+ return t.memberExpression(t.identifier(obj), t.identifier(prop));
199
+ }
200
+ export function optionalMemberExpr(obj, prop) {
201
+ return t.optionalMemberExpression(t.identifier(obj), t.identifier(prop), false, true);
202
+ }
203
+ export function arrowFn(params, body) {
204
+ return t.arrowFunctionExpression(params, body);
205
+ }
206
+ export function awaitExpr(expr) {
207
+ return t.awaitExpression(expr);
208
+ }
209
+ export function spreadObj(expr) {
210
+ return t.spreadElement(expr);
211
+ }
212
+ export function objectProp(key, value, shorthand = false) {
213
+ return t.objectProperty(t.identifier(key), value, false, shorthand);
214
+ }
215
+ export function shorthandProp(name) {
216
+ return t.objectProperty(t.identifier(name), t.identifier(name), false, true);
217
+ }
218
+ export function constDecl(name, init) {
219
+ return t.variableDeclaration('const', [
220
+ t.variableDeclarator(t.identifier(name), init),
221
+ ]);
222
+ }
223
+ export function asConstExpr(expr) {
224
+ return t.tsAsExpression(expr, t.tsTypeReference(t.identifier('const')));
225
+ }
226
+ export function asTypeExpr(expr, typeName) {
227
+ return t.tsAsExpression(expr, typeRef(typeName));
228
+ }
229
+ // ============================================================================
230
+ // Statement helpers
231
+ // ============================================================================
232
+ export function voidStatement(name) {
233
+ return t.expressionStatement(t.unaryExpression('void', t.identifier(name)));
234
+ }
235
+ export function returnUseQuery(queryKeyExpr, queryFnExpr, extraProps, enabledExpr) {
236
+ const props = [
237
+ objectProp('queryKey', queryKeyExpr),
238
+ objectProp('queryFn', queryFnExpr),
239
+ ];
240
+ if (enabledExpr) {
241
+ props.push(objectProp('enabled', enabledExpr));
242
+ }
243
+ if (extraProps) {
244
+ props.push(...extraProps);
245
+ }
246
+ return t.returnStatement(callExpr('useQuery', [t.objectExpression(props)]));
247
+ }
248
+ export function returnUseMutation(mutationFnExpr, extraProps, mutationKeyExpr) {
249
+ const props = [];
250
+ if (mutationKeyExpr) {
251
+ props.push(objectProp('mutationKey', mutationKeyExpr));
252
+ }
253
+ props.push(objectProp('mutationFn', mutationFnExpr));
254
+ props.push(...extraProps);
255
+ return t.returnStatement(callExpr('useMutation', [t.objectExpression(props)]));
256
+ }
257
+ // ============================================================================
258
+ // Destructuring helpers
259
+ // ============================================================================
260
+ export function destructureWithRest(source, keys, restName) {
261
+ const properties = keys.map((key) => t.objectProperty(t.identifier(key), t.identifier(`_${key}`), false, false));
262
+ const pattern = t.objectPattern([
263
+ ...properties,
264
+ t.restElement(t.identifier(restName)),
265
+ ]);
266
+ return constDecl(restName, t.identifier('__placeholder__'));
267
+ }
268
+ export function destructureParamsWithSelection(restName, extraKeys = []) {
269
+ const properties = [];
270
+ for (const key of extraKeys) {
271
+ properties.push(t.objectProperty(t.identifier(key), t.identifier(key), false, true));
272
+ }
273
+ properties.push(t.objectProperty(t.identifier('selection'), t.identifier('_selection'), false, false));
274
+ properties.push(t.restElement(t.identifier(restName)));
275
+ const pattern = t.objectPattern(properties);
276
+ return t.variableDeclaration('const', [
277
+ t.variableDeclarator(pattern, t.logicalExpression('??', t.identifier('params'), t.objectExpression([]))),
278
+ ]);
279
+ }
280
+ export function destructureParamsWithSelectionAndScope(restName) {
281
+ const pattern = t.objectPattern([
282
+ t.objectProperty(t.identifier('scope'), t.identifier('scope'), false, true),
283
+ t.objectProperty(t.identifier('selection'), t.identifier('_selection'), false, false),
284
+ t.restElement(t.identifier(restName)),
285
+ ]);
286
+ return t.variableDeclaration('const', [
287
+ t.variableDeclarator(pattern, t.logicalExpression('??', t.identifier('params'), t.objectExpression([]))),
288
+ ]);
289
+ }
290
+ // ============================================================================
291
+ // JSDoc comment helpers
292
+ // ============================================================================
293
+ export function addJSDocComment(node, lines) {
294
+ const text = lines.length === 1
295
+ ? `* ${lines[0]} `
296
+ : `*\n${lines.map((line) => ` * ${line}`).join('\n')}\n `;
297
+ if (!node.leadingComments) {
298
+ node.leadingComments = [];
299
+ }
300
+ node.leadingComments.push(commentBlock(text));
301
+ return node;
302
+ }
303
+ export function addLineComment(node, text) {
304
+ if (!node.leadingComments) {
305
+ node.leadingComments = [];
306
+ }
307
+ node.leadingComments.push({
308
+ type: 'CommentLine',
309
+ value: ` ${text}`,
310
+ start: null,
311
+ end: null,
312
+ loc: null,
313
+ });
314
+ return node;
315
+ }
316
+ // ============================================================================
317
+ // ORM client call builders
318
+ // ============================================================================
319
+ export function getClientCall(modelName, method, args) {
320
+ return t.callExpression(t.memberExpression(t.memberExpression(callExpr('getClient', []), t.identifier(modelName)), t.identifier(method)), [args]);
321
+ }
322
+ export function getClientCallUnwrap(modelName, method, args) {
323
+ return t.callExpression(t.memberExpression(getClientCall(modelName, method, args), t.identifier('unwrap')), []);
324
+ }
325
+ export function getClientCustomCall(operationType, operationName, args, optionsArg) {
326
+ const callArgs = optionsArg ? [...args, optionsArg] : args;
327
+ return t.callExpression(t.memberExpression(t.memberExpression(callExpr('getClient', []), t.identifier(operationType)), t.identifier(operationName)), callArgs);
328
+ }
329
+ export function getClientCustomCallUnwrap(operationType, operationName, args, optionsArg) {
330
+ return t.callExpression(t.memberExpression(getClientCustomCall(operationType, operationName, args, optionsArg), t.identifier('unwrap')), []);
331
+ }
332
+ // ============================================================================
333
+ // Select/args expression builders
334
+ // ============================================================================
335
+ export function buildFindManyCallExpr(singularName, argsIdent) {
336
+ return getClientCallUnwrap(singularName, 'findMany', t.identifier(argsIdent));
337
+ }
338
+ export function buildFindOneCallExpr(singularName, pkFieldName, argsIdent, paramsIdent = 'params') {
339
+ return getClientCallUnwrap(singularName, 'findOne', t.objectExpression([
340
+ objectProp(pkFieldName, t.memberExpression(t.identifier(paramsIdent), t.identifier(pkFieldName))),
341
+ objectProp('select', t.memberExpression(t.identifier(argsIdent), t.identifier('select'))),
342
+ ]));
343
+ }
344
+ // ============================================================================
345
+ // Code generation
346
+ // ============================================================================
347
+ export function generateHookFileCode(headerDescription, statements) {
348
+ const header = getGeneratedFileHeader(headerDescription);
349
+ const code = generateCode(statements);
350
+ return header + '\n\n' + code + '\n';
351
+ }
352
+ // ============================================================================
353
+ // Scope type helper
354
+ // ============================================================================
355
+ export function scopeTypeLiteral(scopeTypeName) {
356
+ return typeLiteralWithProps([
357
+ {
358
+ name: 'scope',
359
+ type: typeRef(scopeTypeName),
360
+ optional: true,
361
+ },
362
+ ]);
363
+ }
364
+ // ============================================================================
365
+ // Type conversion helpers (GraphQL -> AST)
366
+ // ============================================================================
367
+ export function wrapInferSelectResultType(typeRefNode, payloadTypeName, selectType) {
368
+ if (typeRefNode.kind === 'NON_NULL' && typeRefNode.ofType) {
369
+ return wrapInferSelectResultType(typeRefNode.ofType, payloadTypeName, selectType);
370
+ }
371
+ if (typeRefNode.kind === 'LIST' && typeRefNode.ofType) {
372
+ return t.tsArrayType(wrapInferSelectResultType(typeRefNode.ofType, payloadTypeName, selectType));
373
+ }
374
+ return inferSelectResultType(payloadTypeName, selectType);
375
+ }
376
+ export function typeRefToTsTypeAST(typeRefNode) {
377
+ if (typeRefNode.kind === 'NON_NULL' && typeRefNode.ofType) {
378
+ return typeRefToTsTypeAST(typeRefNode.ofType);
379
+ }
380
+ if (typeRefNode.kind === 'LIST' && typeRefNode.ofType) {
381
+ return t.tsArrayType(typeRefToTsTypeAST(typeRefNode.ofType));
382
+ }
383
+ if (typeRefNode.kind === 'SCALAR') {
384
+ const tsType = scalarToTsType(typeRefNode.name ?? 'unknown');
385
+ if (tsType === 'string')
386
+ return t.tsStringKeyword();
387
+ if (tsType === 'number')
388
+ return t.tsNumberKeyword();
389
+ if (tsType === 'boolean')
390
+ return t.tsBooleanKeyword();
391
+ return t.tsUnknownKeyword();
392
+ }
393
+ return typeRef(typeRefNode.name ?? 'unknown');
394
+ }
395
+ export function buildSelectionArgsCall(selectTypeName) {
396
+ const call = t.callExpression(t.identifier('buildSelectionArgs'), [
397
+ t.memberExpression(t.identifier('params'), t.identifier('selection')),
398
+ ]);
399
+ // @ts-ignore - Babel types support typeParameters on CallExpression for TS
400
+ call.typeParameters = t.tsTypeParameterInstantiation([
401
+ typeRef(selectTypeName),
402
+ ]);
403
+ return constDecl('args', call);
404
+ }
405
+ export function buildListSelectionArgsCall(selectTypeName, filterTypeName, orderByTypeName) {
406
+ const call = t.callExpression(t.identifier('buildListSelectionArgs'), [
407
+ t.memberExpression(t.identifier('params'), t.identifier('selection')),
408
+ ]);
409
+ // @ts-ignore - Babel types support typeParameters on CallExpression for TS
410
+ call.typeParameters = t.tsTypeParameterInstantiation([
411
+ typeRef(selectTypeName),
412
+ typeRef(filterTypeName),
413
+ typeRef(orderByTypeName),
414
+ ]);
415
+ return constDecl('args', call);
416
+ }
417
+ export function customSelectResultTypeLiteral(opName, returnType, payloadTypeName, selectType) {
418
+ return typeLiteralWithProps([
419
+ {
420
+ name: opName,
421
+ type: wrapInferSelectResultType(returnType, payloadTypeName, selectType),
422
+ },
423
+ ]);
424
+ }
@@ -2,29 +2,28 @@
2
2
  * Code generation orchestrator
3
3
  *
4
4
  * Coordinates all code generators to produce the complete SDK output.
5
+ * Hooks delegate to ORM model methods - types are imported from ORM's input-types.ts.
5
6
  *
6
7
  * Output structure:
7
8
  * generated/
8
9
  * index.ts - Main barrel export
9
- * client.ts - GraphQL client with configure() and execute()
10
- * types.ts - Entity interfaces and filter types
10
+ * client.ts - ORM client wrapper (configure/getClient)
11
11
  * queries/
12
12
  * index.ts - Query hooks barrel
13
- * useCarsQuery.ts - List query hook (table-based)
14
- * useCarQuery.ts - Single item query hook (table-based)
15
- * useCurrentUserQuery.ts - Custom query hook
13
+ * useCarsQuery.ts - List query hook -> ORM findMany
14
+ * useCarQuery.ts - Single item query hook -> ORM findOne
15
+ * useCurrentUserQuery.ts - Custom query hook -> ORM query.xxx
16
16
  * ...
17
17
  * mutations/
18
18
  * index.ts - Mutation hooks barrel
19
- * useCreateCarMutation.ts - Table-based CRUD
20
- * useUpdateCarMutation.ts
21
- * useDeleteCarMutation.ts
22
- * useLoginMutation.ts - Custom mutation
23
- * useRegisterMutation.ts
19
+ * useCreateCarMutation.ts - -> ORM create
20
+ * useUpdateCarMutation.ts - -> ORM update
21
+ * useDeleteCarMutation.ts - -> ORM delete
22
+ * useLoginMutation.ts - Custom mutation -> ORM mutation.xxx
24
23
  * ...
25
24
  */
26
- import type { CleanTable, CleanOperation, TypeRegistry } from '../../types/schema';
27
25
  import type { GraphQLSDKConfigTarget } from '../../types/config';
26
+ import type { CleanOperation, CleanTable, TypeRegistry } from '../../types/schema';
28
27
  export interface GeneratedFile {
29
28
  /** Relative path from output directory */
30
29
  path: string;
@@ -72,13 +71,12 @@ export declare function generateAllFiles(tables: CleanTable[], config: GraphQLSD
72
71
  * (they're expected to exist in the shared types directory).
73
72
  */
74
73
  export declare function generate(options: GenerateOptions): GenerateResult;
74
+ export { generateCustomMutationsBarrel, generateCustomQueriesBarrel, generateMainBarrel, generateMutationsBarrel, generateQueriesBarrel, } from './barrel';
75
75
  export { generateClientFile } from './client';
76
- export { generateTypesFile } from './types';
77
- export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook, } from './queries';
78
- export { generateAllMutationHooks, generateCreateMutationHook, generateUpdateMutationHook, generateDeleteMutationHook, } from './mutations';
79
- export { generateAllCustomQueryHooks, generateCustomQueryHook, } from './custom-queries';
80
76
  export { generateAllCustomMutationHooks, generateCustomMutationHook, } from './custom-mutations';
81
- export { generateQueriesBarrel, generateMutationsBarrel, generateMainBarrel, generateCustomQueriesBarrel, generateCustomMutationsBarrel, } from './barrel';
82
- export { generateQueryKeysFile } from './query-keys';
83
- export { generateMutationKeysFile } from './mutation-keys';
77
+ export { generateAllCustomQueryHooks, generateCustomQueryHook, } from './custom-queries';
84
78
  export { generateInvalidationFile } from './invalidation';
79
+ export { generateMutationKeysFile } from './mutation-keys';
80
+ export { generateAllMutationHooks, generateCreateMutationHook, generateDeleteMutationHook, generateUpdateMutationHook, } from './mutations';
81
+ export { generateAllQueryHooks, generateListQueryHook, generateSingleQueryHook, } from './queries';
82
+ export { generateQueryKeysFile } from './query-keys';