@constructive-io/graphql-codegen 4.5.2 → 4.6.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 (41) hide show
  1. package/core/codegen/hooks-docs-generator.js +16 -16
  2. package/core/codegen/mutations.js +6 -6
  3. package/core/codegen/orm/custom-ops-generator.d.ts +2 -2
  4. package/core/codegen/orm/custom-ops-generator.js +15 -6
  5. package/core/codegen/orm/docs-generator.js +6 -6
  6. package/core/codegen/orm/index.js +4 -3
  7. package/core/codegen/orm/input-types-generator.d.ts +1 -1
  8. package/core/codegen/orm/input-types-generator.js +41 -17
  9. package/core/codegen/queries.js +12 -10
  10. package/core/codegen/schema-types-generator.d.ts +2 -0
  11. package/core/codegen/schema-types-generator.js +41 -12
  12. package/core/codegen/shared/index.js +2 -0
  13. package/core/codegen/utils.d.ts +14 -0
  14. package/core/codegen/utils.js +87 -0
  15. package/core/introspect/infer-tables.d.ts +5 -0
  16. package/core/introspect/infer-tables.js +11 -4
  17. package/core/pipeline/index.js +2 -1
  18. package/esm/core/codegen/hooks-docs-generator.js +16 -16
  19. package/esm/core/codegen/mutations.js +6 -6
  20. package/esm/core/codegen/orm/custom-ops-generator.d.ts +2 -2
  21. package/esm/core/codegen/orm/custom-ops-generator.js +17 -8
  22. package/esm/core/codegen/orm/docs-generator.js +6 -6
  23. package/esm/core/codegen/orm/index.js +4 -3
  24. package/esm/core/codegen/orm/input-types-generator.d.ts +1 -1
  25. package/esm/core/codegen/orm/input-types-generator.js +43 -19
  26. package/esm/core/codegen/queries.js +12 -10
  27. package/esm/core/codegen/schema-types-generator.d.ts +2 -0
  28. package/esm/core/codegen/schema-types-generator.js +43 -14
  29. package/esm/core/codegen/shared/index.js +2 -0
  30. package/esm/core/codegen/utils.d.ts +14 -0
  31. package/esm/core/codegen/utils.js +86 -0
  32. package/esm/core/introspect/infer-tables.d.ts +5 -0
  33. package/esm/core/introspect/infer-tables.js +11 -4
  34. package/esm/core/pipeline/index.js +2 -1
  35. package/esm/types/config.d.ts +6 -0
  36. package/esm/types/config.js +1 -0
  37. package/esm/types/schema.d.ts +4 -0
  38. package/package.json +6 -6
  39. package/types/config.d.ts +6 -0
  40. package/types/config.js +1 -0
  41. package/types/schema.d.ts +4 -0
@@ -13,6 +13,7 @@
13
13
  * - Mutation operations: create{Name}, update{Name}, delete{Name}
14
14
  */
15
15
  import { lcFirst, pluralize, singularize, ucFirst } from 'inflekt';
16
+ import { stripSmartComments } from '../codegen/utils';
16
17
  import { getBaseTypeName, isList, unwrapType } from '../../types/introspection';
17
18
  // ============================================================================
18
19
  // Pattern Matching Constants
@@ -81,6 +82,7 @@ function isInternalType(name) {
81
82
  export function inferTablesFromIntrospection(introspection, options = {}) {
82
83
  const { __schema: schema } = introspection;
83
84
  const { types, queryType, mutationType } = schema;
85
+ const commentsEnabled = options.comments !== false;
84
86
  // Build lookup maps for efficient access
85
87
  const typeMap = buildTypeMap(types);
86
88
  const { entityNames, entityToConnection, connectionToEntity } = buildEntityConnectionMaps(types, typeMap);
@@ -95,7 +97,7 @@ export function inferTablesFromIntrospection(introspection, options = {}) {
95
97
  if (!entityType)
96
98
  continue;
97
99
  // Infer all metadata for this entity
98
- const { table, hasRealOperation } = buildCleanTable(entityName, entityType, typeMap, queryFields, mutationFields, entityToConnection, connectionToEntity);
100
+ const { table, hasRealOperation } = buildCleanTable(entityName, entityType, typeMap, queryFields, mutationFields, entityToConnection, connectionToEntity, commentsEnabled);
99
101
  // Only include tables that have at least one real operation
100
102
  if (hasRealOperation) {
101
103
  tables.push(table);
@@ -169,9 +171,9 @@ function resolveEntityNameFromConnectionType(connectionType, typeMap) {
169
171
  /**
170
172
  * Build a complete CleanTable from an entity type
171
173
  */
172
- function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationFields, entityToConnection, connectionToEntity) {
174
+ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationFields, entityToConnection, connectionToEntity, commentsEnabled) {
173
175
  // Extract scalar fields from entity type
174
- const fields = extractEntityFields(entityType, typeMap, entityToConnection);
176
+ const fields = extractEntityFields(entityType, typeMap, entityToConnection, commentsEnabled);
175
177
  // Infer relations from entity fields
176
178
  const relations = inferRelations(entityType, entityToConnection, connectionToEntity);
177
179
  // Match query and mutation operations
@@ -199,9 +201,12 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
199
201
  delete: mutationOps.delete,
200
202
  patchFieldName,
201
203
  };
204
+ // Extract description from entity type (PostgreSQL COMMENT), strip smart comments
205
+ const description = commentsEnabled ? stripSmartComments(entityType.description) : undefined;
202
206
  return {
203
207
  table: {
204
208
  name: entityName,
209
+ ...(description ? { description } : {}),
205
210
  fields,
206
211
  relations,
207
212
  inflection,
@@ -218,7 +223,7 @@ function buildCleanTable(entityName, entityType, typeMap, queryFields, mutationF
218
223
  * Extract scalar fields from an entity type
219
224
  * Excludes relation fields (those returning other entity types or connections)
220
225
  */
221
- function extractEntityFields(entityType, typeMap, entityToConnection) {
226
+ function extractEntityFields(entityType, typeMap, entityToConnection, commentsEnabled) {
222
227
  const fields = [];
223
228
  if (!entityType.fields)
224
229
  return fields;
@@ -236,8 +241,10 @@ function extractEntityFields(entityType, typeMap, entityToConnection) {
236
241
  }
237
242
  }
238
243
  // Include scalar, enum, and other non-relation fields
244
+ const fieldDescription = commentsEnabled ? stripSmartComments(field.description) : undefined;
239
245
  fields.push({
240
246
  name: field.name,
247
+ ...(fieldDescription ? { description: fieldDescription } : {}),
241
248
  type: convertToCleanFieldType(field.type),
242
249
  });
243
250
  }
@@ -23,7 +23,8 @@ export async function runCodegenPipeline(options) {
23
23
  const { introspection } = await source.fetch();
24
24
  // 2. Infer tables from introspection (replaces _meta)
25
25
  log('Inferring table metadata from schema...');
26
- let tables = inferTablesFromIntrospection(introspection);
26
+ const commentsEnabled = config.codegen?.comments !== false;
27
+ let tables = inferTablesFromIntrospection(introspection, { comments: commentsEnabled });
27
28
  const totalTables = tables.length;
28
29
  log(` Found ${totalTables} tables`);
29
30
  // 3. Filter tables by config (combine exclude and systemExclude)
@@ -279,6 +279,12 @@ export interface GraphQLSDKConfigTarget {
279
279
  codegen?: {
280
280
  /** Skip 'query' field on mutation payloads (default: true) */
281
281
  skipQueryField?: boolean;
282
+ /**
283
+ * Include PostgreSQL COMMENT descriptions as JSDoc comments in generated code.
284
+ * PostGraphile smart comments and boilerplate descriptions are automatically stripped.
285
+ * @default true
286
+ */
287
+ comments?: boolean;
282
288
  };
283
289
  /**
284
290
  * Whether to generate ORM client
@@ -60,6 +60,7 @@ export const DEFAULT_CONFIG = {
60
60
  },
61
61
  codegen: {
62
62
  skipQueryField: true,
63
+ comments: true,
63
64
  },
64
65
  orm: false,
65
66
  reactQuery: false,
@@ -7,6 +7,8 @@
7
7
  */
8
8
  export interface CleanTable {
9
9
  name: string;
10
+ /** Description from PostgreSQL COMMENT (smart comments stripped) */
11
+ description?: string;
10
12
  fields: CleanField[];
11
13
  relations: CleanRelations;
12
14
  /** PostGraphile inflection rules for this table */
@@ -103,6 +105,8 @@ export interface ForeignKeyConstraint extends ConstraintInfo {
103
105
  */
104
106
  export interface CleanField {
105
107
  name: string;
108
+ /** Description from PostgreSQL COMMENT (smart comments stripped) */
109
+ description?: string;
106
110
  type: CleanFieldType;
107
111
  }
108
112
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "4.5.2",
3
+ "version": "4.6.0",
4
4
  "description": "GraphQL SDK generator for Constructive databases with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -58,12 +58,12 @@
58
58
  "@babel/types": "^7.28.6",
59
59
  "@constructive-io/graphql-types": "^3.1.1",
60
60
  "@inquirerer/utils": "^3.2.3",
61
- "@pgpmjs/core": "^6.3.0",
61
+ "@pgpmjs/core": "^6.3.2",
62
62
  "ajv": "^8.17.1",
63
63
  "deepmerge": "^4.3.1",
64
64
  "find-and-require-package-json": "^0.9.0",
65
65
  "gql-ast": "^3.1.0",
66
- "graphile-schema": "^1.2.2",
66
+ "graphile-schema": "^1.2.4",
67
67
  "graphql": "^16.9.0",
68
68
  "inflekt": "^0.3.1",
69
69
  "inquirerer": "^4.4.0",
@@ -72,8 +72,8 @@
72
72
  "oxfmt": "^0.26.0",
73
73
  "pg-cache": "^3.1.0",
74
74
  "pg-env": "^1.5.0",
75
- "pgsql-client": "^3.2.1",
76
- "pgsql-seed": "^2.2.1",
75
+ "pgsql-client": "^3.2.3",
76
+ "pgsql-seed": "^2.2.3",
77
77
  "undici": "^7.19.0"
78
78
  },
79
79
  "peerDependencies": {
@@ -100,5 +100,5 @@
100
100
  "tsx": "^4.21.0",
101
101
  "typescript": "^5.9.3"
102
102
  },
103
- "gitHead": "ce2369cad9ed3abca2887fe4e955afbcc536c17e"
103
+ "gitHead": "1b17d61b375abaa04310abe05c2a3ca5881ac650"
104
104
  }
package/types/config.d.ts CHANGED
@@ -279,6 +279,12 @@ export interface GraphQLSDKConfigTarget {
279
279
  codegen?: {
280
280
  /** Skip 'query' field on mutation payloads (default: true) */
281
281
  skipQueryField?: boolean;
282
+ /**
283
+ * Include PostgreSQL COMMENT descriptions as JSDoc comments in generated code.
284
+ * PostGraphile smart comments and boilerplate descriptions are automatically stripped.
285
+ * @default true
286
+ */
287
+ comments?: boolean;
282
288
  };
283
289
  /**
284
290
  * Whether to generate ORM client
package/types/config.js CHANGED
@@ -69,6 +69,7 @@ exports.DEFAULT_CONFIG = {
69
69
  },
70
70
  codegen: {
71
71
  skipQueryField: true,
72
+ comments: true,
72
73
  },
73
74
  orm: false,
74
75
  reactQuery: false,
package/types/schema.d.ts CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  export interface CleanTable {
9
9
  name: string;
10
+ /** Description from PostgreSQL COMMENT (smart comments stripped) */
11
+ description?: string;
10
12
  fields: CleanField[];
11
13
  relations: CleanRelations;
12
14
  /** PostGraphile inflection rules for this table */
@@ -103,6 +105,8 @@ export interface ForeignKeyConstraint extends ConstraintInfo {
103
105
  */
104
106
  export interface CleanField {
105
107
  name: string;
108
+ /** Description from PostgreSQL COMMENT (smart comments stripped) */
109
+ description?: string;
106
110
  type: CleanFieldType;
107
111
  }
108
112
  /**