@constructive-io/graphql-codegen 2.21.0 → 2.22.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.
- package/cli/codegen/barrel.d.ts +4 -1
- package/cli/codegen/barrel.js +18 -12
- package/cli/codegen/client.js +33 -0
- package/cli/codegen/custom-mutations.d.ts +4 -0
- package/cli/codegen/custom-mutations.js +39 -13
- package/cli/codegen/custom-queries.d.ts +4 -0
- package/cli/codegen/custom-queries.js +36 -11
- package/cli/codegen/gql-ast.js +9 -5
- package/cli/codegen/index.js +35 -7
- package/cli/codegen/mutations.d.ts +2 -0
- package/cli/codegen/mutations.js +87 -23
- package/cli/codegen/orm/barrel.js +4 -2
- package/cli/codegen/orm/index.js +17 -0
- package/cli/codegen/orm/input-types-generator.js +83 -29
- package/cli/codegen/orm/model-generator.js +6 -4
- package/cli/codegen/queries.js +36 -27
- package/cli/codegen/scalars.d.ts +6 -4
- package/cli/codegen/scalars.js +17 -9
- package/cli/codegen/schema-types-generator.d.ts +26 -0
- package/cli/codegen/schema-types-generator.js +365 -0
- package/cli/codegen/ts-ast.d.ts +3 -1
- package/cli/codegen/ts-ast.js +2 -2
- package/cli/codegen/type-resolver.d.ts +52 -6
- package/cli/codegen/type-resolver.js +97 -19
- package/cli/codegen/types.d.ts +7 -4
- package/cli/codegen/types.js +94 -41
- package/cli/codegen/utils.d.ts +20 -2
- package/cli/codegen/utils.js +32 -7
- package/cli/commands/generate-orm.js +5 -5
- package/cli/commands/generate.d.ts +4 -1
- package/cli/commands/generate.js +27 -8
- package/cli/introspect/transform-schema.d.ts +33 -21
- package/cli/introspect/transform-schema.js +31 -21
- package/esm/cli/codegen/barrel.d.ts +4 -1
- package/esm/cli/codegen/barrel.js +18 -12
- package/esm/cli/codegen/client.js +33 -0
- package/esm/cli/codegen/custom-mutations.d.ts +4 -0
- package/esm/cli/codegen/custom-mutations.js +40 -14
- package/esm/cli/codegen/custom-queries.d.ts +4 -0
- package/esm/cli/codegen/custom-queries.js +37 -12
- package/esm/cli/codegen/gql-ast.js +10 -6
- package/esm/cli/codegen/index.js +35 -7
- package/esm/cli/codegen/mutations.d.ts +2 -0
- package/esm/cli/codegen/mutations.js +88 -24
- package/esm/cli/codegen/orm/barrel.js +4 -2
- package/esm/cli/codegen/orm/index.js +17 -0
- package/esm/cli/codegen/orm/input-types-generator.js +83 -29
- package/esm/cli/codegen/orm/model-generator.js +7 -5
- package/esm/cli/codegen/queries.js +37 -28
- package/esm/cli/codegen/scalars.d.ts +6 -4
- package/esm/cli/codegen/scalars.js +16 -8
- package/esm/cli/codegen/schema-types-generator.d.ts +26 -0
- package/esm/cli/codegen/schema-types-generator.js +362 -0
- package/esm/cli/codegen/ts-ast.d.ts +3 -1
- package/esm/cli/codegen/ts-ast.js +2 -2
- package/esm/cli/codegen/type-resolver.d.ts +52 -6
- package/esm/cli/codegen/type-resolver.js +97 -20
- package/esm/cli/codegen/types.d.ts +7 -4
- package/esm/cli/codegen/types.js +95 -41
- package/esm/cli/codegen/utils.d.ts +20 -2
- package/esm/cli/codegen/utils.js +31 -7
- package/esm/cli/commands/generate-orm.js +5 -5
- package/esm/cli/commands/generate.d.ts +4 -1
- package/esm/cli/commands/generate.js +27 -8
- package/esm/cli/introspect/transform-schema.d.ts +33 -21
- package/esm/cli/introspect/transform-schema.js +31 -21
- package/esm/types/schema.d.ts +2 -0
- package/package.json +8 -6
- package/types/schema.d.ts +2 -0
- package/__tests__/codegen/input-types-generator.test.d.ts +0 -1
- package/__tests__/codegen/input-types-generator.test.js +0 -635
- package/__tests__/codegen/react-query-optional.test.d.ts +0 -1
- package/__tests__/codegen/react-query-optional.test.js +0 -292
- package/cli/codegen/filters.d.ts +0 -27
- package/cli/codegen/filters.js +0 -357
- package/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
- package/cli/codegen/orm/input-types-generator.test.js +0 -75
- package/cli/codegen/orm/select-types.test.d.ts +0 -11
- package/cli/codegen/orm/select-types.test.js +0 -22
- package/cli/introspect/transform-schema.test.d.ts +0 -1
- package/cli/introspect/transform-schema.test.js +0 -67
- package/esm/__tests__/codegen/input-types-generator.test.d.ts +0 -1
- package/esm/__tests__/codegen/input-types-generator.test.js +0 -633
- package/esm/__tests__/codegen/react-query-optional.test.d.ts +0 -1
- package/esm/__tests__/codegen/react-query-optional.test.js +0 -290
- package/esm/cli/codegen/filters.d.ts +0 -27
- package/esm/cli/codegen/filters.js +0 -351
- package/esm/cli/codegen/orm/input-types-generator.test.d.ts +0 -1
- package/esm/cli/codegen/orm/input-types-generator.test.js +0 -73
- package/esm/cli/codegen/orm/select-types.test.d.ts +0 -11
- package/esm/cli/codegen/orm/select-types.test.js +0 -21
- package/esm/cli/introspect/transform-schema.test.d.ts +0 -1
- 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
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
-
|
|
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
|
|
211
|
-
*
|
|
212
|
-
*
|
|
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
|
|
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
|
-
|
|
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));
|
package/esm/types/schema.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.0",
|
|
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:
|
|
45
|
-
"example:
|
|
46
|
-
"example:
|
|
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.
|
|
53
|
+
"graphql": "15.10.1",
|
|
53
54
|
"inflection": "^3.0.2",
|
|
54
55
|
"jiti": "^2.6.1",
|
|
55
56
|
"prettier": "^3.7.4",
|
|
@@ -76,7 +77,8 @@
|
|
|
76
77
|
"jest": "^29.7.0",
|
|
77
78
|
"react": "^19.2.3",
|
|
78
79
|
"ts-jest": "^29.2.5",
|
|
80
|
+
"tsx": "^4.21.0",
|
|
79
81
|
"typescript": "^5.9.3"
|
|
80
82
|
},
|
|
81
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "fe5e59d3a4497d7ac91a051b74e181851393f56c"
|
|
82
84
|
}
|
package/types/schema.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|