@constructive-io/graphql-codegen 4.8.1 → 4.12.2

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 (33) hide show
  1. package/core/codegen/cli/arg-mapper.d.ts +1 -1
  2. package/core/codegen/cli/arg-mapper.js +15 -11
  3. package/core/codegen/cli/custom-command-generator.js +4 -3
  4. package/core/codegen/cli/docs-generator.d.ts +6 -5
  5. package/core/codegen/cli/docs-generator.js +167 -64
  6. package/core/codegen/cli/table-command-generator.d.ts +15 -0
  7. package/core/codegen/cli/table-command-generator.js +29 -3
  8. package/core/codegen/docs-utils.d.ts +26 -1
  9. package/core/codegen/docs-utils.js +105 -0
  10. package/core/codegen/orm/input-types-generator.js +112 -14
  11. package/core/codegen/orm/model-generator.js +8 -0
  12. package/core/codegen/orm/select-types.d.ts +4 -2
  13. package/core/codegen/scalars.js +8 -0
  14. package/core/codegen/templates/cli-entry.ts +2 -2
  15. package/core/codegen/templates/cli-utils.ts +28 -0
  16. package/core/codegen/templates/query-builder.ts +28 -5
  17. package/core/codegen/templates/select-types.ts +4 -2
  18. package/core/generate.js +14 -4
  19. package/esm/core/codegen/cli/arg-mapper.d.ts +1 -1
  20. package/esm/core/codegen/cli/arg-mapper.js +15 -11
  21. package/esm/core/codegen/cli/custom-command-generator.js +4 -3
  22. package/esm/core/codegen/cli/docs-generator.d.ts +6 -5
  23. package/esm/core/codegen/cli/docs-generator.js +168 -65
  24. package/esm/core/codegen/cli/table-command-generator.d.ts +15 -0
  25. package/esm/core/codegen/cli/table-command-generator.js +29 -5
  26. package/esm/core/codegen/docs-utils.d.ts +26 -1
  27. package/esm/core/codegen/docs-utils.js +102 -0
  28. package/esm/core/codegen/orm/input-types-generator.js +112 -14
  29. package/esm/core/codegen/orm/model-generator.js +8 -0
  30. package/esm/core/codegen/orm/select-types.d.ts +4 -2
  31. package/esm/core/codegen/scalars.js +8 -0
  32. package/esm/core/generate.js +14 -4
  33. package/package.json +11 -11
@@ -1,4 +1,4 @@
1
1
  import * as t from '@babel/types';
2
2
  import type { CleanArgument } from '../../../types/schema';
3
- export declare function buildQuestionObject(arg: CleanArgument): t.ObjectExpression;
3
+ export declare function buildQuestionObject(arg: CleanArgument, namePrefix?: string): t.ObjectExpression;
4
4
  export declare function buildQuestionsArray(args: CleanArgument[]): t.ArrayExpression;
@@ -48,35 +48,37 @@ function resolveBaseType(typeRef) {
48
48
  }
49
49
  return typeRef;
50
50
  }
51
- function buildQuestionObject(arg) {
51
+ function buildQuestionObject(arg, namePrefix) {
52
52
  const { inner, required } = unwrapNonNull(arg.type);
53
53
  const base = resolveBaseType(arg.type);
54
54
  const props = [];
55
+ const questionName = namePrefix ? `${namePrefix}.${arg.name}` : arg.name;
55
56
  if (base.kind === 'ENUM' && base.enumValues && base.enumValues.length > 0) {
56
57
  props.push(t.objectProperty(t.identifier('type'), t.stringLiteral('autocomplete')));
57
- props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(arg.name)));
58
- props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || arg.name)));
58
+ props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(questionName)));
59
+ props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || questionName)));
59
60
  props.push(t.objectProperty(t.identifier('options'), t.arrayExpression(base.enumValues.map((v) => t.stringLiteral(v)))));
60
61
  }
61
62
  else if (base.kind === 'SCALAR' && base.name === 'Boolean') {
62
63
  props.push(t.objectProperty(t.identifier('type'), t.stringLiteral('confirm')));
63
- props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(arg.name)));
64
- props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || arg.name)));
64
+ props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(questionName)));
65
+ props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || questionName)));
65
66
  props.push(t.objectProperty(t.identifier('default'), t.booleanLiteral(false)));
66
67
  }
67
68
  else if (base.kind === 'SCALAR' &&
68
69
  (base.name === 'Int' || base.name === 'Float')) {
69
70
  props.push(t.objectProperty(t.identifier('type'), t.stringLiteral('text')));
70
- props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(arg.name)));
71
- props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || `${arg.name} (number)`)));
71
+ props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(questionName)));
72
+ props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || `${questionName} (number)`)));
72
73
  }
73
74
  else if (inner.kind === 'INPUT_OBJECT' && inner.inputFields) {
75
+ // INPUT_OBJECT fields are flattened in buildQuestionsArray with dot-notation
74
76
  return buildInputObjectQuestion(arg.name, inner, required);
75
77
  }
76
78
  else {
77
79
  props.push(t.objectProperty(t.identifier('type'), t.stringLiteral('text')));
78
- props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(arg.name)));
79
- props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || arg.name)));
80
+ props.push(t.objectProperty(t.identifier('name'), t.stringLiteral(questionName)));
81
+ props.push(t.objectProperty(t.identifier('message'), t.stringLiteral(arg.description || questionName)));
80
82
  }
81
83
  if (required) {
82
84
  props.push(t.objectProperty(t.identifier('required'), t.booleanLiteral(true)));
@@ -100,13 +102,15 @@ function buildQuestionsArray(args) {
100
102
  const base = resolveBaseType(arg.type);
101
103
  const { inner } = unwrapNonNull(arg.type);
102
104
  if (inner.kind === 'INPUT_OBJECT' && inner.inputFields) {
105
+ // Flatten INPUT_OBJECT fields with dot-notation: e.g. input.email, input.password
103
106
  for (const field of inner.inputFields) {
104
- questions.push(buildQuestionObject(field));
107
+ questions.push(buildQuestionObject(field, arg.name));
105
108
  }
106
109
  }
107
110
  else if (base.kind === 'INPUT_OBJECT' && base.inputFields) {
111
+ // Same for NON_NULL-wrapped INPUT_OBJECT
108
112
  for (const field of base.inputFields) {
109
- questions.push(buildQuestionObject(field));
113
+ questions.push(buildQuestionObject(field, arg.name));
110
114
  }
111
115
  }
112
116
  else {
@@ -155,7 +155,7 @@ function generateCustomCommand(op, options) {
155
155
  // Build the list of utils imports needed
156
156
  const utilsImports = [];
157
157
  if (hasInputObjectArg) {
158
- utilsImports.push('parseMutationInput');
158
+ utilsImports.push('unflattenDotNotation');
159
159
  }
160
160
  if (isObjectReturn) {
161
161
  utilsImports.push('buildSelectFromPaths');
@@ -204,10 +204,11 @@ function generateCustomCommand(op, options) {
204
204
  t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('getClient'), getClientArgs)),
205
205
  ]));
206
206
  // For mutations with INPUT_OBJECT args (like `input: SignUpInput`),
207
- // parse JSON strings from CLI into proper objects
207
+ // reconstruct nested objects from dot-notation CLI answers.
208
+ // e.g. { 'input.email': 'foo', 'input.password': 'bar' } → { input: { email: 'foo', password: 'bar' } }
208
209
  if (hasInputObjectArg && op.args.length > 0) {
209
210
  bodyStatements.push(t.variableDeclaration('const', [
210
- t.variableDeclarator(t.identifier('parsedAnswers'), t.callExpression(t.identifier('parseMutationInput'), [
211
+ t.variableDeclarator(t.identifier('parsedAnswers'), t.callExpression(t.identifier('unflattenDotNotation'), [
211
212
  t.identifier('answers'),
212
213
  ])),
213
214
  ]));
@@ -1,17 +1,18 @@
1
- import type { CleanTable, CleanOperation } from '../../../types/schema';
1
+ import type { CleanTable, CleanOperation, TypeRegistry } from '../../../types/schema';
2
2
  import type { GeneratedDocFile, McpTool } from '../docs-utils';
3
3
  export { resolveDocsConfig } from '../docs-utils';
4
4
  export type { GeneratedDocFile, McpTool } from '../docs-utils';
5
- export declare function generateReadme(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): GeneratedDocFile;
6
- export declare function generateAgentsDocs(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): GeneratedDocFile;
7
- export declare function getCliMcpTools(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): McpTool[];
8
- export declare function generateSkills(tables: CleanTable[], customOperations: CleanOperation[], toolName: string, targetName: string): GeneratedDocFile[];
5
+ export declare function generateReadme(tables: CleanTable[], customOperations: CleanOperation[], toolName: string, registry?: TypeRegistry): GeneratedDocFile;
6
+ export declare function generateAgentsDocs(tables: CleanTable[], customOperations: CleanOperation[], toolName: string, registry?: TypeRegistry): GeneratedDocFile;
7
+ export declare function getCliMcpTools(tables: CleanTable[], customOperations: CleanOperation[], toolName: string, registry?: TypeRegistry): McpTool[];
8
+ export declare function generateSkills(tables: CleanTable[], customOperations: CleanOperation[], toolName: string, targetName: string, registry?: TypeRegistry): GeneratedDocFile[];
9
9
  export interface MultiTargetDocsInput {
10
10
  toolName: string;
11
11
  builtinNames: {
12
12
  auth: string;
13
13
  context: string;
14
14
  };
15
+ registry?: TypeRegistry;
15
16
  targets: Array<{
16
17
  name: string;
17
18
  endpoint: string;