@constructive-io/graphql-codegen 2.21.0 → 2.22.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 (93) hide show
  1. package/cli/codegen/barrel.d.ts +4 -1
  2. package/cli/codegen/barrel.js +18 -12
  3. package/cli/codegen/client.js +33 -0
  4. package/cli/codegen/custom-mutations.d.ts +4 -0
  5. package/cli/codegen/custom-mutations.js +39 -13
  6. package/cli/codegen/custom-queries.d.ts +4 -0
  7. package/cli/codegen/custom-queries.js +36 -11
  8. package/cli/codegen/gql-ast.js +9 -5
  9. package/cli/codegen/index.js +35 -7
  10. package/cli/codegen/mutations.d.ts +2 -0
  11. package/cli/codegen/mutations.js +87 -23
  12. package/cli/codegen/orm/barrel.js +4 -2
  13. package/cli/codegen/orm/index.js +17 -0
  14. package/cli/codegen/orm/input-types-generator.js +83 -29
  15. package/cli/codegen/orm/model-generator.js +6 -4
  16. package/cli/codegen/queries.js +36 -27
  17. package/cli/codegen/scalars.d.ts +6 -4
  18. package/cli/codegen/scalars.js +17 -9
  19. package/cli/codegen/schema-types-generator.d.ts +26 -0
  20. package/cli/codegen/schema-types-generator.js +365 -0
  21. package/cli/codegen/ts-ast.d.ts +3 -1
  22. package/cli/codegen/ts-ast.js +2 -2
  23. package/cli/codegen/type-resolver.d.ts +52 -6
  24. package/cli/codegen/type-resolver.js +97 -19
  25. package/cli/codegen/types.d.ts +7 -4
  26. package/cli/codegen/types.js +94 -41
  27. package/cli/codegen/utils.d.ts +20 -2
  28. package/cli/codegen/utils.js +32 -7
  29. package/cli/commands/generate-orm.js +5 -5
  30. package/cli/commands/generate.d.ts +4 -1
  31. package/cli/commands/generate.js +27 -8
  32. package/cli/introspect/transform-schema.d.ts +33 -21
  33. package/cli/introspect/transform-schema.js +31 -21
  34. package/esm/cli/codegen/barrel.d.ts +4 -1
  35. package/esm/cli/codegen/barrel.js +18 -12
  36. package/esm/cli/codegen/client.js +33 -0
  37. package/esm/cli/codegen/custom-mutations.d.ts +4 -0
  38. package/esm/cli/codegen/custom-mutations.js +40 -14
  39. package/esm/cli/codegen/custom-queries.d.ts +4 -0
  40. package/esm/cli/codegen/custom-queries.js +37 -12
  41. package/esm/cli/codegen/gql-ast.js +10 -6
  42. package/esm/cli/codegen/index.js +35 -7
  43. package/esm/cli/codegen/mutations.d.ts +2 -0
  44. package/esm/cli/codegen/mutations.js +88 -24
  45. package/esm/cli/codegen/orm/barrel.js +4 -2
  46. package/esm/cli/codegen/orm/index.js +17 -0
  47. package/esm/cli/codegen/orm/input-types-generator.js +83 -29
  48. package/esm/cli/codegen/orm/model-generator.js +7 -5
  49. package/esm/cli/codegen/queries.js +37 -28
  50. package/esm/cli/codegen/scalars.d.ts +6 -4
  51. package/esm/cli/codegen/scalars.js +16 -8
  52. package/esm/cli/codegen/schema-types-generator.d.ts +26 -0
  53. package/esm/cli/codegen/schema-types-generator.js +362 -0
  54. package/esm/cli/codegen/ts-ast.d.ts +3 -1
  55. package/esm/cli/codegen/ts-ast.js +2 -2
  56. package/esm/cli/codegen/type-resolver.d.ts +52 -6
  57. package/esm/cli/codegen/type-resolver.js +97 -20
  58. package/esm/cli/codegen/types.d.ts +7 -4
  59. package/esm/cli/codegen/types.js +95 -41
  60. package/esm/cli/codegen/utils.d.ts +20 -2
  61. package/esm/cli/codegen/utils.js +31 -7
  62. package/esm/cli/commands/generate-orm.js +5 -5
  63. package/esm/cli/commands/generate.d.ts +4 -1
  64. package/esm/cli/commands/generate.js +27 -8
  65. package/esm/cli/introspect/transform-schema.d.ts +33 -21
  66. package/esm/cli/introspect/transform-schema.js +31 -21
  67. package/esm/types/schema.d.ts +2 -0
  68. package/package.json +8 -7
  69. package/types/schema.d.ts +2 -0
  70. package/__tests__/codegen/input-types-generator.test.d.ts +0 -1
  71. package/__tests__/codegen/input-types-generator.test.js +0 -635
  72. package/__tests__/codegen/react-query-optional.test.d.ts +0 -1
  73. package/__tests__/codegen/react-query-optional.test.js +0 -292
  74. package/cli/codegen/filters.d.ts +0 -27
  75. package/cli/codegen/filters.js +0 -357
  76. package/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
  77. package/cli/codegen/orm/input-types-generator.test.js +0 -75
  78. package/cli/codegen/orm/select-types.test.d.ts +0 -11
  79. package/cli/codegen/orm/select-types.test.js +0 -22
  80. package/cli/introspect/transform-schema.test.d.ts +0 -1
  81. package/cli/introspect/transform-schema.test.js +0 -67
  82. package/esm/__tests__/codegen/input-types-generator.test.d.ts +0 -1
  83. package/esm/__tests__/codegen/input-types-generator.test.js +0 -633
  84. package/esm/__tests__/codegen/react-query-optional.test.d.ts +0 -1
  85. package/esm/__tests__/codegen/react-query-optional.test.js +0 -290
  86. package/esm/cli/codegen/filters.d.ts +0 -27
  87. package/esm/cli/codegen/filters.js +0 -351
  88. package/esm/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
  89. package/esm/cli/codegen/orm/input-types-generator.test.js +0 -73
  90. package/esm/cli/codegen/orm/select-types.test.d.ts +0 -11
  91. package/esm/cli/codegen/orm/select-types.test.js +0 -21
  92. package/esm/cli/introspect/transform-schema.test.d.ts +0 -1
  93. package/esm/cli/introspect/transform-schema.test.js +0 -65
@@ -30,13 +30,29 @@ export declare function transformSchemaToOperations(response: IntrospectionQuery
30
30
  * Uses glob-like patterns (supports * wildcard)
31
31
  */
32
32
  export declare function filterOperations(operations: CleanOperation[], include?: string[], exclude?: string[]): CleanOperation[];
33
+ /**
34
+ * Result type for table operation names lookup
35
+ */
36
+ export interface TableOperationNames {
37
+ queries: Set<string>;
38
+ mutations: Set<string>;
39
+ }
33
40
  /**
34
41
  * Get the set of table-related operation names from tables
35
42
  * Used to identify which operations are already covered by table generators
36
43
  *
37
- * This includes:
38
- * - Basic CRUD: all, one, create, update, delete
39
- * - PostGraphile alternate mutations: updateXByY, deleteXByY (for unique constraints)
44
+ * IMPORTANT: This uses EXACT matches only from _meta.query fields.
45
+ * Any operation not explicitly listed in _meta will flow through as a
46
+ * custom operation, ensuring 100% coverage of the schema.
47
+ *
48
+ * Table operations (generated by table generators):
49
+ * - Queries: all (list), one (single by PK)
50
+ * - Mutations: create, update (by PK), delete (by PK)
51
+ *
52
+ * Custom operations (generated by custom operation generators):
53
+ * - Unique constraint lookups: *ByUsername, *ByEmail, etc.
54
+ * - Unique constraint mutations: update*By*, delete*By*
55
+ * - True custom operations: login, register, bootstrapUser, etc.
40
56
  */
41
57
  export declare function getTableOperationNames(tables: Array<{
42
58
  name: string;
@@ -47,28 +63,24 @@ export declare function getTableOperationNames(tables: Array<{
47
63
  update: string | null;
48
64
  delete: string | null;
49
65
  };
50
- inflection?: {
51
- tableType: string;
52
- };
53
- }>): {
54
- queries: Set<string>;
55
- mutations: Set<string>;
56
- tableTypePatterns: RegExp[];
57
- };
66
+ }>): TableOperationNames;
58
67
  /**
59
68
  * Check if an operation is a table operation (already handled by table generators)
69
+ *
70
+ * Uses EXACT match only - no pattern matching. This ensures:
71
+ * 1. Only operations explicitly in _meta.query are treated as table operations
72
+ * 2. All other operations (including update*By*, delete*By*) become custom operations
73
+ * 3. 100% schema coverage is guaranteed
60
74
  */
61
- export declare function isTableOperation(operation: CleanOperation, tableOperationNames: {
62
- queries: Set<string>;
63
- mutations: Set<string>;
64
- tableTypePatterns: RegExp[];
65
- }): boolean;
75
+ export declare function isTableOperation(operation: CleanOperation, tableOperationNames: TableOperationNames): boolean;
66
76
  /**
67
77
  * Get only custom operations (not covered by table generators)
78
+ *
79
+ * This returns ALL operations that are not exact matches for table CRUD operations.
80
+ * Includes:
81
+ * - Unique constraint queries (*ByUsername, *ByEmail, etc.)
82
+ * - Unique constraint mutations (update*By*, delete*By*)
83
+ * - True custom operations (login, register, bootstrapUser, etc.)
68
84
  */
69
- export declare function getCustomOperations(operations: CleanOperation[], tableOperationNames: {
70
- queries: Set<string>;
71
- mutations: Set<string>;
72
- tableTypePatterns: RegExp[];
73
- }): CleanOperation[];
85
+ export declare function getCustomOperations(operations: CleanOperation[], tableOperationNames: TableOperationNames): CleanOperation[];
74
86
  export { unwrapType, getBaseTypeName, isNonNull };
@@ -26,6 +26,10 @@ export function buildTypeRegistry(types) {
26
26
  if (type.kind === 'ENUM' && type.enumValues) {
27
27
  resolvedType.enumValues = type.enumValues.map((ev) => ev.name);
28
28
  }
29
+ // Resolve possible types for UNION types (no circular refs for names)
30
+ if (type.kind === 'UNION' && type.possibleTypes) {
31
+ resolvedType.possibleTypes = type.possibleTypes.map((pt) => pt.name);
32
+ }
29
33
  registry.set(type.name, resolvedType);
30
34
  }
31
35
  // Second pass: Resolve fields (now that all types exist in registry)
@@ -200,57 +204,63 @@ function matchesPatterns(name, patterns) {
200
204
  return name === pattern;
201
205
  });
202
206
  }
203
- // ============================================================================
204
- // Utility Functions
205
- // ============================================================================
206
207
  /**
207
208
  * Get the set of table-related operation names from tables
208
209
  * Used to identify which operations are already covered by table generators
209
210
  *
210
- * This includes:
211
- * - Basic CRUD: all, one, create, update, delete
212
- * - PostGraphile alternate mutations: updateXByY, deleteXByY (for unique constraints)
211
+ * IMPORTANT: This uses EXACT matches only from _meta.query fields.
212
+ * Any operation not explicitly listed in _meta will flow through as a
213
+ * custom operation, ensuring 100% coverage of the schema.
214
+ *
215
+ * Table operations (generated by table generators):
216
+ * - Queries: all (list), one (single by PK)
217
+ * - Mutations: create, update (by PK), delete (by PK)
218
+ *
219
+ * Custom operations (generated by custom operation generators):
220
+ * - Unique constraint lookups: *ByUsername, *ByEmail, etc.
221
+ * - Unique constraint mutations: update*By*, delete*By*
222
+ * - True custom operations: login, register, bootstrapUser, etc.
213
223
  */
214
224
  export function getTableOperationNames(tables) {
215
225
  const queries = new Set();
216
226
  const mutations = new Set();
217
- const tableTypePatterns = [];
218
227
  for (const table of tables) {
219
228
  if (table.query) {
229
+ // Add exact query names from _meta
220
230
  queries.add(table.query.all);
221
231
  queries.add(table.query.one);
232
+ // Add exact mutation names from _meta
222
233
  mutations.add(table.query.create);
223
234
  if (table.query.update)
224
235
  mutations.add(table.query.update);
225
236
  if (table.query.delete)
226
237
  mutations.add(table.query.delete);
227
238
  }
228
- // Create patterns to match alternate CRUD mutations (updateXByY, deleteXByY)
229
- if (table.inflection?.tableType) {
230
- const typeName = table.inflection.tableType;
231
- // Match: update{TypeName}By*, delete{TypeName}By*
232
- tableTypePatterns.push(new RegExp(`^update${typeName}By`, 'i'));
233
- tableTypePatterns.push(new RegExp(`^delete${typeName}By`, 'i'));
234
- }
235
239
  }
236
- return { queries, mutations, tableTypePatterns };
240
+ return { queries, mutations };
237
241
  }
238
242
  /**
239
243
  * Check if an operation is a table operation (already handled by table generators)
244
+ *
245
+ * Uses EXACT match only - no pattern matching. This ensures:
246
+ * 1. Only operations explicitly in _meta.query are treated as table operations
247
+ * 2. All other operations (including update*By*, delete*By*) become custom operations
248
+ * 3. 100% schema coverage is guaranteed
240
249
  */
241
250
  export function isTableOperation(operation, tableOperationNames) {
242
251
  if (operation.kind === 'query') {
243
252
  return tableOperationNames.queries.has(operation.name);
244
253
  }
245
- // Check exact match first
246
- if (tableOperationNames.mutations.has(operation.name)) {
247
- return true;
248
- }
249
- // Check pattern match for alternate CRUD mutations (updateXByY, deleteXByY)
250
- return tableOperationNames.tableTypePatterns.some((pattern) => pattern.test(operation.name));
254
+ return tableOperationNames.mutations.has(operation.name);
251
255
  }
252
256
  /**
253
257
  * Get only custom operations (not covered by table generators)
258
+ *
259
+ * This returns ALL operations that are not exact matches for table CRUD operations.
260
+ * Includes:
261
+ * - Unique constraint queries (*ByUsername, *ByEmail, etc.)
262
+ * - Unique constraint mutations (update*By*, delete*By*)
263
+ * - True custom operations (login, register, bootstrapUser, etc.)
254
264
  */
255
265
  export function getCustomOperations(operations, tableOperationNames) {
256
266
  return operations.filter((op) => !isTableOperation(op, tableOperationNames));
@@ -250,4 +250,6 @@ export interface ResolvedType {
250
250
  inputFields?: CleanArgument[];
251
251
  /** Values for ENUM types */
252
252
  enumValues?: string[];
253
+ /** Possible types for UNION types */
254
+ possibleTypes?: string[];
253
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-codegen",
3
- "version": "2.21.0",
3
+ "version": "2.22.1",
4
4
  "description": "CLI-based GraphQL SDK generator for PostGraphile endpoints with React Query hooks",
5
5
  "keywords": [
6
6
  "graphql",
@@ -41,15 +41,16 @@
41
41
  "lint": "eslint . --fix",
42
42
  "test": "jest --passWithNoTests",
43
43
  "test:watch": "jest --watch",
44
- "example:orm": "tsx examples/test-orm.ts",
45
- "example:rq": "tsx examples/test-rq.ts",
46
- "example:schema": "tsx examples/download-schema.ts"
44
+ "example:codegen:sdk": "node dist/cli/index.js generate --endpoint http://api.localhost:3000/graphql --output examples/output/generated-sdk",
45
+ "example:codegen:orm": "node dist/cli/index.js generate-orm --endpoint http://api.localhost:3000/graphql --output examples/output/generated-orm",
46
+ "example:sdk": "tsx examples/react-query-sdk.ts",
47
+ "example:orm": "tsx examples/orm-sdk.ts"
47
48
  },
48
49
  "dependencies": {
49
50
  "ajv": "^8.17.1",
50
51
  "commander": "^12.1.0",
51
52
  "gql-ast": "^2.4.6",
52
- "graphql": "15.8.0",
53
+ "graphql": "15.10.1",
53
54
  "inflection": "^3.0.2",
54
55
  "jiti": "^2.6.1",
55
56
  "prettier": "^3.7.4",
@@ -69,14 +70,14 @@
69
70
  },
70
71
  "devDependencies": {
71
72
  "@tanstack/react-query": "^5.90.16",
72
- "@types/inflection": "^1.13.2",
73
73
  "@types/jest": "^29.5.14",
74
74
  "@types/node": "^20.19.27",
75
75
  "@types/react": "^19.2.7",
76
76
  "jest": "^29.7.0",
77
77
  "react": "^19.2.3",
78
78
  "ts-jest": "^29.2.5",
79
+ "tsx": "^4.21.0",
79
80
  "typescript": "^5.9.3"
80
81
  },
81
- "gitHead": "a8a6f2cf22eb610f385bfba63d5e6e40e0a47e50"
82
+ "gitHead": "cb086f098f3d82ee9e4eced65383fc3f45253064"
82
83
  }
package/types/schema.d.ts CHANGED
@@ -250,4 +250,6 @@ export interface ResolvedType {
250
250
  inputFields?: CleanArgument[];
251
251
  /** Values for ENUM types */
252
252
  enumValues?: string[];
253
+ /** Possible types for UNION types */
254
+ possibleTypes?: string[];
253
255
  }
@@ -1 +0,0 @@
1
- export {};