@constructive-io/graphql-codegen 2.19.0 → 2.20.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/README.md +1818 -113
- package/__tests__/codegen/input-types-generator.test.d.ts +1 -0
- package/__tests__/codegen/input-types-generator.test.js +635 -0
- package/cli/codegen/barrel.d.ts +27 -0
- package/cli/codegen/barrel.js +163 -0
- package/cli/codegen/client.d.ts +4 -0
- package/cli/codegen/client.js +170 -0
- package/cli/codegen/custom-mutations.d.ts +38 -0
- package/cli/codegen/custom-mutations.js +149 -0
- package/cli/codegen/custom-queries.d.ts +38 -0
- package/cli/codegen/custom-queries.js +358 -0
- package/cli/codegen/filters.d.ts +27 -0
- package/cli/codegen/filters.js +357 -0
- package/cli/codegen/gql-ast.d.ts +41 -0
- package/cli/codegen/gql-ast.js +329 -0
- package/cli/codegen/index.d.ts +71 -0
- package/cli/codegen/index.js +147 -0
- package/cli/codegen/mutations.d.ts +30 -0
- package/cli/codegen/mutations.js +410 -0
- package/cli/codegen/orm/barrel.d.ts +18 -0
- package/cli/codegen/orm/barrel.js +48 -0
- package/cli/codegen/orm/client-generator.d.ts +45 -0
- package/cli/codegen/orm/client-generator.js +646 -0
- package/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
- package/cli/codegen/orm/custom-ops-generator.js +350 -0
- package/cli/codegen/orm/index.d.ts +38 -0
- package/cli/codegen/orm/index.js +88 -0
- package/cli/codegen/orm/input-types-generator.d.ts +21 -0
- package/cli/codegen/orm/input-types-generator.js +705 -0
- package/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
- package/cli/codegen/orm/input-types-generator.test.js +75 -0
- package/cli/codegen/orm/model-generator.d.ts +32 -0
- package/cli/codegen/orm/model-generator.js +264 -0
- package/cli/codegen/orm/query-builder.d.ts +161 -0
- package/cli/codegen/orm/query-builder.js +366 -0
- package/cli/codegen/orm/select-types.d.ts +169 -0
- package/cli/codegen/orm/select-types.js +16 -0
- package/cli/codegen/orm/select-types.test.d.ts +11 -0
- package/cli/codegen/orm/select-types.test.js +22 -0
- package/cli/codegen/queries.d.ts +25 -0
- package/cli/codegen/queries.js +438 -0
- package/cli/codegen/scalars.d.ts +12 -0
- package/cli/codegen/scalars.js +71 -0
- package/cli/codegen/schema-gql-ast.d.ts +51 -0
- package/cli/codegen/schema-gql-ast.js +385 -0
- package/cli/codegen/ts-ast.d.ts +122 -0
- package/cli/codegen/ts-ast.js +280 -0
- package/cli/codegen/type-resolver.d.ts +96 -0
- package/cli/codegen/type-resolver.js +246 -0
- package/cli/codegen/types.d.ts +12 -0
- package/cli/codegen/types.js +69 -0
- package/cli/codegen/utils.d.ts +163 -0
- package/cli/codegen/utils.js +326 -0
- package/cli/commands/generate-orm.d.ts +37 -0
- package/cli/commands/generate-orm.js +195 -0
- package/cli/commands/generate.d.ts +39 -0
- package/cli/commands/generate.js +299 -0
- package/cli/commands/index.d.ts +7 -0
- package/cli/commands/index.js +12 -0
- package/cli/commands/init.d.ts +35 -0
- package/cli/commands/init.js +176 -0
- package/cli/index.d.ts +4 -0
- package/cli/index.js +291 -0
- package/cli/introspect/fetch-meta.d.ts +31 -0
- package/cli/introspect/fetch-meta.js +108 -0
- package/cli/introspect/fetch-schema.d.ts +21 -0
- package/cli/introspect/fetch-schema.js +86 -0
- package/cli/introspect/index.d.ts +8 -0
- package/cli/introspect/index.js +16 -0
- package/cli/introspect/meta-query.d.ts +111 -0
- package/cli/introspect/meta-query.js +191 -0
- package/cli/introspect/schema-query.d.ts +20 -0
- package/cli/introspect/schema-query.js +123 -0
- package/cli/introspect/transform-schema.d.ts +74 -0
- package/cli/introspect/transform-schema.js +269 -0
- package/cli/introspect/transform-schema.test.d.ts +1 -0
- package/cli/introspect/transform-schema.test.js +67 -0
- package/cli/introspect/transform.d.ts +21 -0
- package/cli/introspect/transform.js +216 -0
- package/cli/watch/cache.d.ts +45 -0
- package/cli/watch/cache.js +111 -0
- package/cli/watch/debounce.d.ts +19 -0
- package/cli/watch/debounce.js +89 -0
- package/cli/watch/hash.d.ts +17 -0
- package/cli/watch/hash.js +48 -0
- package/cli/watch/index.d.ts +10 -0
- package/cli/watch/index.js +22 -0
- package/cli/watch/orchestrator.d.ts +63 -0
- package/cli/watch/orchestrator.js +228 -0
- package/cli/watch/poller.d.ts +65 -0
- package/cli/watch/poller.js +203 -0
- package/cli/watch/types.d.ts +67 -0
- package/cli/watch/types.js +5 -0
- package/client/error.d.ts +95 -0
- package/client/error.js +255 -0
- package/client/execute.d.ts +57 -0
- package/client/execute.js +124 -0
- package/client/index.d.ts +6 -0
- package/client/index.js +18 -0
- package/client/typed-document.d.ts +31 -0
- package/client/typed-document.js +44 -0
- package/core/ast.d.ts +10 -0
- package/core/ast.js +593 -0
- package/core/custom-ast.d.ts +35 -0
- package/core/custom-ast.js +204 -0
- package/core/index.d.ts +8 -0
- package/core/index.js +33 -0
- package/core/meta-object/convert.d.ts +65 -0
- package/core/meta-object/convert.js +63 -0
- package/core/meta-object/format.json +93 -0
- package/core/meta-object/index.d.ts +2 -0
- package/core/meta-object/index.js +18 -0
- package/core/meta-object/validate.d.ts +9 -0
- package/core/meta-object/validate.js +34 -0
- package/core/query-builder.d.ts +46 -0
- package/core/query-builder.js +412 -0
- package/core/types.d.ts +139 -0
- package/core/types.js +28 -0
- package/esm/__tests__/codegen/input-types-generator.test.d.ts +1 -0
- package/esm/__tests__/codegen/input-types-generator.test.js +633 -0
- package/esm/cli/codegen/barrel.d.ts +27 -0
- package/esm/cli/codegen/barrel.js +156 -0
- package/esm/cli/codegen/client.d.ts +4 -0
- package/esm/cli/codegen/client.js +167 -0
- package/esm/cli/codegen/custom-mutations.d.ts +38 -0
- package/esm/cli/codegen/custom-mutations.js +145 -0
- package/esm/cli/codegen/custom-queries.d.ts +38 -0
- package/esm/cli/codegen/custom-queries.js +354 -0
- package/esm/cli/codegen/filters.d.ts +27 -0
- package/esm/cli/codegen/filters.js +351 -0
- package/esm/cli/codegen/gql-ast.d.ts +41 -0
- package/esm/cli/codegen/gql-ast.js +288 -0
- package/esm/cli/codegen/index.d.ts +71 -0
- package/esm/cli/codegen/index.js +124 -0
- package/esm/cli/codegen/mutations.d.ts +30 -0
- package/esm/cli/codegen/mutations.js +404 -0
- package/esm/cli/codegen/orm/barrel.d.ts +18 -0
- package/esm/cli/codegen/orm/barrel.js +44 -0
- package/esm/cli/codegen/orm/client-generator.d.ts +45 -0
- package/esm/cli/codegen/orm/client-generator.js +640 -0
- package/esm/cli/codegen/orm/custom-ops-generator.d.ts +30 -0
- package/esm/cli/codegen/orm/custom-ops-generator.js +346 -0
- package/esm/cli/codegen/orm/index.d.ts +38 -0
- package/esm/cli/codegen/orm/index.js +75 -0
- package/esm/cli/codegen/orm/input-types-generator.d.ts +21 -0
- package/esm/cli/codegen/orm/input-types-generator.js +700 -0
- package/esm/cli/codegen/orm/input-types-generator.test.d.ts +1 -0
- package/esm/cli/codegen/orm/input-types-generator.test.js +73 -0
- package/esm/cli/codegen/orm/model-generator.d.ts +32 -0
- package/esm/cli/codegen/orm/model-generator.js +260 -0
- package/esm/cli/codegen/orm/query-builder.d.ts +161 -0
- package/esm/cli/codegen/orm/query-builder.js +353 -0
- package/esm/cli/codegen/orm/select-types.d.ts +169 -0
- package/esm/cli/codegen/orm/select-types.js +15 -0
- package/esm/cli/codegen/orm/select-types.test.d.ts +11 -0
- package/esm/cli/codegen/orm/select-types.test.js +21 -0
- package/esm/cli/codegen/queries.d.ts +25 -0
- package/esm/cli/codegen/queries.js +433 -0
- package/esm/cli/codegen/scalars.d.ts +12 -0
- package/esm/cli/codegen/scalars.js +66 -0
- package/esm/cli/codegen/schema-gql-ast.d.ts +51 -0
- package/esm/cli/codegen/schema-gql-ast.js +343 -0
- package/esm/cli/codegen/ts-ast.d.ts +122 -0
- package/esm/cli/codegen/ts-ast.js +260 -0
- package/esm/cli/codegen/type-resolver.d.ts +96 -0
- package/esm/cli/codegen/type-resolver.js +224 -0
- package/esm/cli/codegen/types.d.ts +12 -0
- package/esm/cli/codegen/types.js +65 -0
- package/esm/cli/codegen/utils.d.ts +163 -0
- package/esm/cli/codegen/utils.js +288 -0
- package/esm/cli/commands/generate-orm.d.ts +37 -0
- package/esm/cli/commands/generate-orm.js +192 -0
- package/esm/cli/commands/generate.d.ts +39 -0
- package/esm/cli/commands/generate.js +262 -0
- package/esm/cli/commands/index.d.ts +7 -0
- package/esm/cli/commands/index.js +5 -0
- package/esm/cli/commands/init.d.ts +35 -0
- package/esm/cli/commands/init.js +138 -0
- package/esm/cli/index.d.ts +4 -0
- package/esm/cli/index.js +256 -0
- package/esm/cli/introspect/fetch-meta.d.ts +31 -0
- package/esm/cli/introspect/fetch-meta.js +104 -0
- package/esm/cli/introspect/fetch-schema.d.ts +21 -0
- package/esm/cli/introspect/fetch-schema.js +83 -0
- package/esm/cli/introspect/index.d.ts +8 -0
- package/esm/cli/introspect/index.js +6 -0
- package/esm/cli/introspect/meta-query.d.ts +111 -0
- package/esm/cli/introspect/meta-query.js +188 -0
- package/esm/cli/introspect/schema-query.d.ts +20 -0
- package/esm/cli/introspect/schema-query.js +120 -0
- package/esm/cli/introspect/transform-schema.d.ts +74 -0
- package/esm/cli/introspect/transform-schema.js +259 -0
- package/esm/cli/introspect/transform-schema.test.d.ts +1 -0
- package/esm/cli/introspect/transform-schema.test.js +65 -0
- package/esm/cli/introspect/transform.d.ts +21 -0
- package/esm/cli/introspect/transform.js +210 -0
- package/esm/cli/watch/cache.d.ts +45 -0
- package/esm/cli/watch/cache.js +73 -0
- package/esm/cli/watch/debounce.d.ts +19 -0
- package/esm/cli/watch/debounce.js +85 -0
- package/esm/cli/watch/hash.d.ts +17 -0
- package/esm/cli/watch/hash.js +43 -0
- package/esm/cli/watch/index.d.ts +10 -0
- package/esm/cli/watch/index.js +8 -0
- package/esm/cli/watch/orchestrator.d.ts +63 -0
- package/esm/cli/watch/orchestrator.js +223 -0
- package/esm/cli/watch/poller.d.ts +65 -0
- package/esm/cli/watch/poller.js +198 -0
- package/esm/cli/watch/types.d.ts +67 -0
- package/esm/cli/watch/types.js +4 -0
- package/esm/client/error.d.ts +95 -0
- package/esm/client/error.js +249 -0
- package/esm/client/execute.d.ts +57 -0
- package/esm/client/execute.js +120 -0
- package/esm/client/index.d.ts +6 -0
- package/esm/client/index.js +6 -0
- package/esm/client/typed-document.d.ts +31 -0
- package/esm/client/typed-document.js +40 -0
- package/esm/core/ast.d.ts +10 -0
- package/esm/core/ast.js +549 -0
- package/esm/core/custom-ast.d.ts +35 -0
- package/esm/core/custom-ast.js +161 -0
- package/esm/core/index.d.ts +8 -0
- package/esm/core/index.js +12 -0
- package/esm/core/meta-object/convert.d.ts +65 -0
- package/esm/core/meta-object/convert.js +60 -0
- package/esm/core/meta-object/format.json +93 -0
- package/esm/core/meta-object/index.d.ts +2 -0
- package/esm/core/meta-object/index.js +2 -0
- package/esm/core/meta-object/validate.d.ts +9 -0
- package/esm/core/meta-object/validate.js +28 -0
- package/esm/core/query-builder.d.ts +46 -0
- package/esm/core/query-builder.js +375 -0
- package/esm/core/types.d.ts +139 -0
- package/esm/core/types.js +24 -0
- package/esm/generators/field-selector.d.ts +30 -0
- package/esm/generators/field-selector.js +355 -0
- package/esm/generators/index.d.ts +6 -0
- package/esm/generators/index.js +9 -0
- package/esm/generators/mutations.d.ts +31 -0
- package/esm/generators/mutations.js +197 -0
- package/esm/generators/select.d.ts +50 -0
- package/esm/generators/select.js +636 -0
- package/esm/index.d.ts +12 -0
- package/esm/index.js +17 -3
- package/esm/react/index.d.ts +5 -0
- package/esm/react/index.js +6 -0
- package/esm/types/config.d.ts +199 -0
- package/esm/types/config.js +106 -0
- package/esm/types/index.d.ts +9 -0
- package/esm/types/index.js +4 -0
- package/esm/types/introspection.d.ts +121 -0
- package/esm/types/introspection.js +54 -0
- package/esm/types/mutation.d.ts +45 -0
- package/esm/types/mutation.js +4 -0
- package/esm/types/query.d.ts +82 -0
- package/esm/types/query.js +4 -0
- package/esm/types/schema.d.ts +253 -0
- package/esm/types/schema.js +5 -0
- package/esm/types/selection.d.ts +43 -0
- package/esm/types/selection.js +4 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +4 -0
- package/generators/field-selector.d.ts +30 -0
- package/generators/field-selector.js +361 -0
- package/generators/index.d.ts +6 -0
- package/generators/index.js +27 -0
- package/generators/mutations.d.ts +31 -0
- package/generators/mutations.js +235 -0
- package/generators/select.d.ts +50 -0
- package/generators/select.js +679 -0
- package/index.d.ts +12 -3
- package/index.js +19 -3
- package/package.json +59 -38
- package/react/index.d.ts +5 -0
- package/react/index.js +9 -0
- package/types/config.d.ts +199 -0
- package/types/config.js +111 -0
- package/types/index.d.ts +9 -0
- package/types/index.js +10 -0
- package/types/introspection.d.ts +121 -0
- package/types/introspection.js +62 -0
- package/types/mutation.d.ts +45 -0
- package/types/mutation.js +5 -0
- package/types/query.d.ts +82 -0
- package/types/query.js +5 -0
- package/types/schema.d.ts +253 -0
- package/types/schema.js +6 -0
- package/types/selection.d.ts +43 -0
- package/types/selection.js +5 -0
- package/utils/index.d.ts +4 -0
- package/utils/index.js +7 -0
- package/codegen.d.ts +0 -13
- package/codegen.js +0 -293
- package/esm/codegen.js +0 -253
- package/esm/gql.js +0 -939
- package/esm/options.js +0 -27
- package/gql.d.ts +0 -188
- package/gql.js +0 -992
- package/options.d.ts +0 -45
- package/options.js +0 -31
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNonNull = exports.getBaseTypeName = exports.unwrapType = void 0;
|
|
4
|
+
exports.buildTypeRegistry = buildTypeRegistry;
|
|
5
|
+
exports.transformSchemaToOperations = transformSchemaToOperations;
|
|
6
|
+
exports.filterOperations = filterOperations;
|
|
7
|
+
exports.getTableOperationNames = getTableOperationNames;
|
|
8
|
+
exports.isTableOperation = isTableOperation;
|
|
9
|
+
exports.getCustomOperations = getCustomOperations;
|
|
10
|
+
const introspection_1 = require("../../types/introspection");
|
|
11
|
+
Object.defineProperty(exports, "unwrapType", { enumerable: true, get: function () { return introspection_1.unwrapType; } });
|
|
12
|
+
Object.defineProperty(exports, "getBaseTypeName", { enumerable: true, get: function () { return introspection_1.getBaseTypeName; } });
|
|
13
|
+
Object.defineProperty(exports, "isNonNull", { enumerable: true, get: function () { return introspection_1.isNonNull; } });
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Type Registry Builder
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Build a type registry from introspection types
|
|
19
|
+
* Maps type names to their full resolved definitions
|
|
20
|
+
*
|
|
21
|
+
* This is a two-pass process to handle circular references:
|
|
22
|
+
* 1. First pass: Create all type entries with basic info
|
|
23
|
+
* 2. Second pass: Resolve fields with references to other types
|
|
24
|
+
*/
|
|
25
|
+
function buildTypeRegistry(types) {
|
|
26
|
+
const registry = new Map();
|
|
27
|
+
// First pass: Create all type entries
|
|
28
|
+
for (const type of types) {
|
|
29
|
+
// Skip built-in types that start with __
|
|
30
|
+
if (type.name.startsWith('__'))
|
|
31
|
+
continue;
|
|
32
|
+
const resolvedType = {
|
|
33
|
+
kind: type.kind,
|
|
34
|
+
name: type.name,
|
|
35
|
+
description: type.description ?? undefined,
|
|
36
|
+
};
|
|
37
|
+
// Resolve enum values for ENUM types (no circular refs possible)
|
|
38
|
+
if (type.kind === 'ENUM' && type.enumValues) {
|
|
39
|
+
resolvedType.enumValues = type.enumValues.map((ev) => ev.name);
|
|
40
|
+
}
|
|
41
|
+
registry.set(type.name, resolvedType);
|
|
42
|
+
}
|
|
43
|
+
// Second pass: Resolve fields (now that all types exist in registry)
|
|
44
|
+
for (const type of types) {
|
|
45
|
+
if (type.name.startsWith('__'))
|
|
46
|
+
continue;
|
|
47
|
+
const resolvedType = registry.get(type.name);
|
|
48
|
+
if (!resolvedType)
|
|
49
|
+
continue;
|
|
50
|
+
// Resolve fields for OBJECT types
|
|
51
|
+
if (type.kind === 'OBJECT' && type.fields) {
|
|
52
|
+
resolvedType.fields = type.fields.map((field) => transformFieldToCleanObjectFieldShallow(field));
|
|
53
|
+
}
|
|
54
|
+
// Resolve input fields for INPUT_OBJECT types
|
|
55
|
+
if (type.kind === 'INPUT_OBJECT' && type.inputFields) {
|
|
56
|
+
resolvedType.inputFields = type.inputFields.map((field) => transformInputValueToCleanArgumentShallow(field));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return registry;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Transform field to CleanObjectField without resolving nested types
|
|
63
|
+
* (shallow transformation to avoid circular refs)
|
|
64
|
+
*/
|
|
65
|
+
function transformFieldToCleanObjectFieldShallow(field) {
|
|
66
|
+
return {
|
|
67
|
+
name: field.name,
|
|
68
|
+
type: transformTypeRefShallow(field.type),
|
|
69
|
+
description: field.description ?? undefined,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Transform input value to CleanArgument without resolving nested types
|
|
74
|
+
*/
|
|
75
|
+
function transformInputValueToCleanArgumentShallow(inputValue) {
|
|
76
|
+
return {
|
|
77
|
+
name: inputValue.name,
|
|
78
|
+
type: transformTypeRefShallow(inputValue.type),
|
|
79
|
+
defaultValue: inputValue.defaultValue ?? undefined,
|
|
80
|
+
description: inputValue.description ?? undefined,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Transform TypeRef without resolving nested types
|
|
85
|
+
* Only handles wrappers (LIST, NON_NULL) and stores the type name
|
|
86
|
+
*/
|
|
87
|
+
function transformTypeRefShallow(typeRef) {
|
|
88
|
+
const cleanRef = {
|
|
89
|
+
kind: typeRef.kind,
|
|
90
|
+
name: typeRef.name,
|
|
91
|
+
};
|
|
92
|
+
if (typeRef.ofType) {
|
|
93
|
+
cleanRef.ofType = transformTypeRefShallow(typeRef.ofType);
|
|
94
|
+
}
|
|
95
|
+
return cleanRef;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Transform introspection response to clean operations
|
|
99
|
+
*/
|
|
100
|
+
function transformSchemaToOperations(response) {
|
|
101
|
+
const { __schema: schema } = response;
|
|
102
|
+
const { types, queryType, mutationType } = schema;
|
|
103
|
+
// Build type registry first
|
|
104
|
+
const typeRegistry = buildTypeRegistry(types);
|
|
105
|
+
// Find Query and Mutation types
|
|
106
|
+
const queryTypeDef = types.find((t) => t.name === queryType.name);
|
|
107
|
+
const mutationTypeDef = mutationType
|
|
108
|
+
? types.find((t) => t.name === mutationType.name)
|
|
109
|
+
: null;
|
|
110
|
+
// Transform queries
|
|
111
|
+
const queries = queryTypeDef?.fields
|
|
112
|
+
? queryTypeDef.fields.map((field) => transformFieldToCleanOperation(field, 'query', types))
|
|
113
|
+
: [];
|
|
114
|
+
// Transform mutations
|
|
115
|
+
const mutations = mutationTypeDef?.fields
|
|
116
|
+
? mutationTypeDef.fields.map((field) => transformFieldToCleanOperation(field, 'mutation', types))
|
|
117
|
+
: [];
|
|
118
|
+
return { queries, mutations, typeRegistry };
|
|
119
|
+
}
|
|
120
|
+
// ============================================================================
|
|
121
|
+
// Field to Operation Transformation
|
|
122
|
+
// ============================================================================
|
|
123
|
+
/**
|
|
124
|
+
* Transform an introspection field to a CleanOperation
|
|
125
|
+
*/
|
|
126
|
+
function transformFieldToCleanOperation(field, kind, types) {
|
|
127
|
+
return {
|
|
128
|
+
name: field.name,
|
|
129
|
+
kind,
|
|
130
|
+
args: field.args.map((arg) => transformInputValueToCleanArgument(arg, types)),
|
|
131
|
+
returnType: transformTypeRefToCleanTypeRef(field.type, types),
|
|
132
|
+
description: field.description ?? undefined,
|
|
133
|
+
isDeprecated: field.isDeprecated,
|
|
134
|
+
deprecationReason: field.deprecationReason ?? undefined,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Transform an input value to CleanArgument
|
|
139
|
+
*/
|
|
140
|
+
function transformInputValueToCleanArgument(inputValue, types) {
|
|
141
|
+
return {
|
|
142
|
+
name: inputValue.name,
|
|
143
|
+
type: transformTypeRefToCleanTypeRef(inputValue.type, types),
|
|
144
|
+
defaultValue: inputValue.defaultValue ?? undefined,
|
|
145
|
+
description: inputValue.description ?? undefined,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// ============================================================================
|
|
149
|
+
// Type Reference Transformation
|
|
150
|
+
// ============================================================================
|
|
151
|
+
/**
|
|
152
|
+
* Transform an introspection TypeRef to CleanTypeRef
|
|
153
|
+
* Recursively handles wrapper types (LIST, NON_NULL)
|
|
154
|
+
*
|
|
155
|
+
* NOTE: We intentionally do NOT resolve nested fields here to avoid
|
|
156
|
+
* infinite recursion from circular type references. Fields are resolved
|
|
157
|
+
* lazily via the TypeRegistry when needed for code generation.
|
|
158
|
+
*/
|
|
159
|
+
function transformTypeRefToCleanTypeRef(typeRef, types) {
|
|
160
|
+
const cleanRef = {
|
|
161
|
+
kind: typeRef.kind,
|
|
162
|
+
name: typeRef.name,
|
|
163
|
+
};
|
|
164
|
+
// Recursively transform ofType for wrappers (LIST, NON_NULL)
|
|
165
|
+
if (typeRef.ofType) {
|
|
166
|
+
cleanRef.ofType = transformTypeRefToCleanTypeRef(typeRef.ofType, types);
|
|
167
|
+
}
|
|
168
|
+
// For named types, only resolve enum values (they don't have circular refs)
|
|
169
|
+
// Fields are NOT resolved here - they're resolved via TypeRegistry during codegen
|
|
170
|
+
if (typeRef.name && !typeRef.ofType) {
|
|
171
|
+
const typeDef = types.find((t) => t.name === typeRef.name);
|
|
172
|
+
if (typeDef) {
|
|
173
|
+
// Add enum values for ENUM types (safe, no recursion)
|
|
174
|
+
if (typeDef.kind === 'ENUM' && typeDef.enumValues) {
|
|
175
|
+
cleanRef.enumValues = typeDef.enumValues.map((ev) => ev.name);
|
|
176
|
+
}
|
|
177
|
+
// NOTE: OBJECT and INPUT_OBJECT fields are resolved via TypeRegistry
|
|
178
|
+
// to avoid circular reference issues
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return cleanRef;
|
|
182
|
+
}
|
|
183
|
+
// ============================================================================
|
|
184
|
+
// Operation Filtering
|
|
185
|
+
// ============================================================================
|
|
186
|
+
/**
|
|
187
|
+
* Filter operations by include/exclude patterns
|
|
188
|
+
* Uses glob-like patterns (supports * wildcard)
|
|
189
|
+
*/
|
|
190
|
+
function filterOperations(operations, include, exclude) {
|
|
191
|
+
let result = operations;
|
|
192
|
+
if (include && include.length > 0) {
|
|
193
|
+
result = result.filter((op) => matchesPatterns(op.name, include));
|
|
194
|
+
}
|
|
195
|
+
if (exclude && exclude.length > 0) {
|
|
196
|
+
result = result.filter((op) => !matchesPatterns(op.name, exclude));
|
|
197
|
+
}
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Check if a name matches any of the patterns
|
|
202
|
+
* Supports simple glob patterns with * wildcard
|
|
203
|
+
*/
|
|
204
|
+
function matchesPatterns(name, patterns) {
|
|
205
|
+
return patterns.some((pattern) => {
|
|
206
|
+
if (pattern === '*')
|
|
207
|
+
return true;
|
|
208
|
+
if (pattern.includes('*')) {
|
|
209
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
|
|
210
|
+
return regex.test(name);
|
|
211
|
+
}
|
|
212
|
+
return name === pattern;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
// ============================================================================
|
|
216
|
+
// Utility Functions
|
|
217
|
+
// ============================================================================
|
|
218
|
+
/**
|
|
219
|
+
* Get the set of table-related operation names from tables
|
|
220
|
+
* Used to identify which operations are already covered by table generators
|
|
221
|
+
*
|
|
222
|
+
* This includes:
|
|
223
|
+
* - Basic CRUD: all, one, create, update, delete
|
|
224
|
+
* - PostGraphile alternate mutations: updateXByY, deleteXByY (for unique constraints)
|
|
225
|
+
*/
|
|
226
|
+
function getTableOperationNames(tables) {
|
|
227
|
+
const queries = new Set();
|
|
228
|
+
const mutations = new Set();
|
|
229
|
+
const tableTypePatterns = [];
|
|
230
|
+
for (const table of tables) {
|
|
231
|
+
if (table.query) {
|
|
232
|
+
queries.add(table.query.all);
|
|
233
|
+
queries.add(table.query.one);
|
|
234
|
+
mutations.add(table.query.create);
|
|
235
|
+
if (table.query.update)
|
|
236
|
+
mutations.add(table.query.update);
|
|
237
|
+
if (table.query.delete)
|
|
238
|
+
mutations.add(table.query.delete);
|
|
239
|
+
}
|
|
240
|
+
// Create patterns to match alternate CRUD mutations (updateXByY, deleteXByY)
|
|
241
|
+
if (table.inflection?.tableType) {
|
|
242
|
+
const typeName = table.inflection.tableType;
|
|
243
|
+
// Match: update{TypeName}By*, delete{TypeName}By*
|
|
244
|
+
tableTypePatterns.push(new RegExp(`^update${typeName}By`, 'i'));
|
|
245
|
+
tableTypePatterns.push(new RegExp(`^delete${typeName}By`, 'i'));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return { queries, mutations, tableTypePatterns };
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Check if an operation is a table operation (already handled by table generators)
|
|
252
|
+
*/
|
|
253
|
+
function isTableOperation(operation, tableOperationNames) {
|
|
254
|
+
if (operation.kind === 'query') {
|
|
255
|
+
return tableOperationNames.queries.has(operation.name);
|
|
256
|
+
}
|
|
257
|
+
// Check exact match first
|
|
258
|
+
if (tableOperationNames.mutations.has(operation.name)) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
// Check pattern match for alternate CRUD mutations (updateXByY, deleteXByY)
|
|
262
|
+
return tableOperationNames.tableTypePatterns.some((pattern) => pattern.test(operation.name));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Get only custom operations (not covered by table generators)
|
|
266
|
+
*/
|
|
267
|
+
function getCustomOperations(operations, tableOperationNames) {
|
|
268
|
+
return operations.filter((op) => !isTableOperation(op, tableOperationNames));
|
|
269
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Jest globals - no import needed
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const transform_schema_1 = require("./transform-schema");
|
|
5
|
+
describe('transform-schema table operation filtering', () => {
|
|
6
|
+
const dummyReturnType = { kind: 'SCALAR', name: 'String' };
|
|
7
|
+
it('detects table operations and update/delete patterns', () => {
|
|
8
|
+
const tableOps = (0, transform_schema_1.getTableOperationNames)([
|
|
9
|
+
{
|
|
10
|
+
name: 'User',
|
|
11
|
+
query: {
|
|
12
|
+
all: 'users',
|
|
13
|
+
one: 'user',
|
|
14
|
+
create: 'createUser',
|
|
15
|
+
update: 'updateUser',
|
|
16
|
+
delete: 'deleteUser',
|
|
17
|
+
},
|
|
18
|
+
inflection: { tableType: 'User' },
|
|
19
|
+
},
|
|
20
|
+
]);
|
|
21
|
+
const updateByEmail = {
|
|
22
|
+
name: 'updateUserByEmail',
|
|
23
|
+
kind: 'mutation',
|
|
24
|
+
args: [],
|
|
25
|
+
returnType: dummyReturnType,
|
|
26
|
+
};
|
|
27
|
+
const login = {
|
|
28
|
+
name: 'login',
|
|
29
|
+
kind: 'mutation',
|
|
30
|
+
args: [],
|
|
31
|
+
returnType: dummyReturnType,
|
|
32
|
+
};
|
|
33
|
+
expect((0, transform_schema_1.isTableOperation)(updateByEmail, tableOps)).toBe(true);
|
|
34
|
+
expect((0, transform_schema_1.isTableOperation)(login, tableOps)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
it('filters out table operations from custom list', () => {
|
|
37
|
+
const tableOps = (0, transform_schema_1.getTableOperationNames)([
|
|
38
|
+
{
|
|
39
|
+
name: 'User',
|
|
40
|
+
query: {
|
|
41
|
+
all: 'users',
|
|
42
|
+
one: 'user',
|
|
43
|
+
create: 'createUser',
|
|
44
|
+
update: 'updateUser',
|
|
45
|
+
delete: 'deleteUser',
|
|
46
|
+
},
|
|
47
|
+
inflection: { tableType: 'User' },
|
|
48
|
+
},
|
|
49
|
+
]);
|
|
50
|
+
const operations = [
|
|
51
|
+
{
|
|
52
|
+
name: 'users',
|
|
53
|
+
kind: 'query',
|
|
54
|
+
args: [],
|
|
55
|
+
returnType: dummyReturnType,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'login',
|
|
59
|
+
kind: 'mutation',
|
|
60
|
+
args: [],
|
|
61
|
+
returnType: dummyReturnType,
|
|
62
|
+
},
|
|
63
|
+
];
|
|
64
|
+
const customOps = (0, transform_schema_1.getCustomOperations)(operations, tableOps);
|
|
65
|
+
expect(customOps.map((op) => op.name)).toEqual(['login']);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform _meta query response to CleanTable[] format
|
|
3
|
+
*/
|
|
4
|
+
import type { CleanTable } from '../../types/schema';
|
|
5
|
+
import type { MetaQueryResponse } from './meta-query';
|
|
6
|
+
/**
|
|
7
|
+
* Transform _meta response to CleanTable array
|
|
8
|
+
*/
|
|
9
|
+
export declare function transformMetaToCleanTables(metaResponse: MetaQueryResponse): CleanTable[];
|
|
10
|
+
/**
|
|
11
|
+
* Get table names from CleanTable array
|
|
12
|
+
*/
|
|
13
|
+
export declare function getTableNames(tables: CleanTable[]): string[];
|
|
14
|
+
/**
|
|
15
|
+
* Find a table by name
|
|
16
|
+
*/
|
|
17
|
+
export declare function findTable(tables: CleanTable[], name: string): CleanTable | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Filter tables by name pattern (glob-like)
|
|
20
|
+
*/
|
|
21
|
+
export declare function filterTables(tables: CleanTable[], include?: string[], exclude?: string[]): CleanTable[];
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformMetaToCleanTables = transformMetaToCleanTables;
|
|
4
|
+
exports.getTableNames = getTableNames;
|
|
5
|
+
exports.findTable = findTable;
|
|
6
|
+
exports.filterTables = filterTables;
|
|
7
|
+
/**
|
|
8
|
+
* Transform _meta response to CleanTable array
|
|
9
|
+
*/
|
|
10
|
+
function transformMetaToCleanTables(metaResponse) {
|
|
11
|
+
const { tables } = metaResponse._meta;
|
|
12
|
+
return tables.map((table) => transformTable(table));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Transform a single MetaTable to CleanTable
|
|
16
|
+
*/
|
|
17
|
+
function transformTable(table) {
|
|
18
|
+
return {
|
|
19
|
+
name: table.name,
|
|
20
|
+
fields: transformFields(table.fields),
|
|
21
|
+
relations: transformRelations(table.relations),
|
|
22
|
+
inflection: transformInflection(table.inflection),
|
|
23
|
+
query: transformQuery(table.query),
|
|
24
|
+
constraints: transformConstraints(table),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Transform MetaField[] to CleanField[]
|
|
29
|
+
*/
|
|
30
|
+
function transformFields(fields) {
|
|
31
|
+
return fields.map((field) => ({
|
|
32
|
+
name: field.name,
|
|
33
|
+
type: transformFieldType(field.type),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Transform MetaFieldType to CleanFieldType
|
|
38
|
+
*/
|
|
39
|
+
function transformFieldType(type) {
|
|
40
|
+
return {
|
|
41
|
+
gqlType: type.gqlType,
|
|
42
|
+
isArray: type.isArray,
|
|
43
|
+
modifier: type.modifier,
|
|
44
|
+
pgAlias: type.pgAlias,
|
|
45
|
+
pgType: type.pgType,
|
|
46
|
+
subtype: type.subtype,
|
|
47
|
+
typmod: type.typmod,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Transform table relations
|
|
52
|
+
*/
|
|
53
|
+
function transformRelations(relations) {
|
|
54
|
+
return {
|
|
55
|
+
belongsTo: relations.belongsTo.map(transformBelongsTo),
|
|
56
|
+
hasOne: relations.hasOne.map(transformHasOne),
|
|
57
|
+
hasMany: relations.hasMany.map(transformHasMany),
|
|
58
|
+
manyToMany: relations.manyToMany.map(transformManyToMany),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Transform belongsTo relation
|
|
63
|
+
*/
|
|
64
|
+
function transformBelongsTo(rel) {
|
|
65
|
+
return {
|
|
66
|
+
fieldName: rel.fieldName,
|
|
67
|
+
isUnique: rel.isUnique,
|
|
68
|
+
referencesTable: rel.references.name,
|
|
69
|
+
type: rel.type,
|
|
70
|
+
keys: transformFields(rel.keys),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Transform hasOne relation
|
|
75
|
+
*/
|
|
76
|
+
function transformHasOne(rel) {
|
|
77
|
+
return {
|
|
78
|
+
fieldName: rel.fieldName,
|
|
79
|
+
isUnique: rel.isUnique,
|
|
80
|
+
referencedByTable: rel.referencedBy.name,
|
|
81
|
+
type: rel.type,
|
|
82
|
+
keys: transformFields(rel.keys),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Transform hasMany relation
|
|
87
|
+
*/
|
|
88
|
+
function transformHasMany(rel) {
|
|
89
|
+
return {
|
|
90
|
+
fieldName: rel.fieldName,
|
|
91
|
+
isUnique: rel.isUnique,
|
|
92
|
+
referencedByTable: rel.referencedBy.name,
|
|
93
|
+
type: rel.type,
|
|
94
|
+
keys: transformFields(rel.keys),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Transform manyToMany relation
|
|
99
|
+
*/
|
|
100
|
+
function transformManyToMany(rel) {
|
|
101
|
+
return {
|
|
102
|
+
fieldName: rel.fieldName,
|
|
103
|
+
rightTable: rel.rightTable.name,
|
|
104
|
+
junctionTable: rel.junctionTable.name,
|
|
105
|
+
type: rel.type,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Transform inflection data
|
|
110
|
+
*/
|
|
111
|
+
function transformInflection(inflection) {
|
|
112
|
+
return {
|
|
113
|
+
allRows: inflection.allRows,
|
|
114
|
+
allRowsSimple: inflection.allRowsSimple,
|
|
115
|
+
conditionType: inflection.conditionType,
|
|
116
|
+
connection: inflection.connection,
|
|
117
|
+
createField: inflection.createField,
|
|
118
|
+
createInputType: inflection.createInputType,
|
|
119
|
+
createPayloadType: inflection.createPayloadType,
|
|
120
|
+
deleteByPrimaryKey: inflection.deleteByPrimaryKey,
|
|
121
|
+
deletePayloadType: inflection.deletePayloadType,
|
|
122
|
+
edge: inflection.edge,
|
|
123
|
+
edgeField: inflection.edgeField,
|
|
124
|
+
enumType: inflection.enumType,
|
|
125
|
+
filterType: inflection.filterType,
|
|
126
|
+
inputType: inflection.inputType,
|
|
127
|
+
orderByType: inflection.orderByType,
|
|
128
|
+
patchField: inflection.patchField,
|
|
129
|
+
patchType: inflection.patchType,
|
|
130
|
+
tableFieldName: inflection.tableFieldName,
|
|
131
|
+
tableType: inflection.tableType,
|
|
132
|
+
typeName: inflection.typeName,
|
|
133
|
+
updateByPrimaryKey: inflection.updateByPrimaryKey,
|
|
134
|
+
updatePayloadType: inflection.updatePayloadType,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Transform query names
|
|
139
|
+
*/
|
|
140
|
+
function transformQuery(query) {
|
|
141
|
+
return {
|
|
142
|
+
all: query.all,
|
|
143
|
+
one: query.one,
|
|
144
|
+
create: query.create,
|
|
145
|
+
update: query.update,
|
|
146
|
+
delete: query.delete,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Transform constraints
|
|
151
|
+
*/
|
|
152
|
+
function transformConstraints(table) {
|
|
153
|
+
return {
|
|
154
|
+
primaryKey: table.primaryKeyConstraints.map(transformConstraint),
|
|
155
|
+
foreignKey: table.foreignKeyConstraints.map(transformForeignKeyConstraint),
|
|
156
|
+
unique: table.uniqueConstraints.map(transformConstraint),
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Transform a basic constraint
|
|
161
|
+
*/
|
|
162
|
+
function transformConstraint(constraint) {
|
|
163
|
+
return {
|
|
164
|
+
name: constraint.name,
|
|
165
|
+
fields: transformFields(constraint.fields),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Transform a foreign key constraint
|
|
170
|
+
*/
|
|
171
|
+
function transformForeignKeyConstraint(constraint) {
|
|
172
|
+
return {
|
|
173
|
+
name: constraint.name,
|
|
174
|
+
fields: transformFields(constraint.fields),
|
|
175
|
+
refTable: constraint.refTable.name,
|
|
176
|
+
refFields: transformFields(constraint.refFields),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get table names from CleanTable array
|
|
181
|
+
*/
|
|
182
|
+
function getTableNames(tables) {
|
|
183
|
+
return tables.map((t) => t.name);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Find a table by name
|
|
187
|
+
*/
|
|
188
|
+
function findTable(tables, name) {
|
|
189
|
+
return tables.find((t) => t.name === name);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Filter tables by name pattern (glob-like)
|
|
193
|
+
*/
|
|
194
|
+
function filterTables(tables, include, exclude) {
|
|
195
|
+
let result = tables;
|
|
196
|
+
if (include && include.length > 0) {
|
|
197
|
+
result = result.filter((t) => matchesPatterns(t.name, include));
|
|
198
|
+
}
|
|
199
|
+
if (exclude && exclude.length > 0) {
|
|
200
|
+
result = result.filter((t) => !matchesPatterns(t.name, exclude));
|
|
201
|
+
}
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Check if a name matches any of the patterns
|
|
206
|
+
* Supports simple glob patterns with * wildcard
|
|
207
|
+
*/
|
|
208
|
+
function matchesPatterns(name, patterns) {
|
|
209
|
+
return patterns.some((pattern) => {
|
|
210
|
+
if (pattern.includes('*')) {
|
|
211
|
+
const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
|
|
212
|
+
return regex.test(name);
|
|
213
|
+
}
|
|
214
|
+
return name === pattern;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory schema cache for watch mode
|
|
3
|
+
*
|
|
4
|
+
* Only stores the hash in memory - no file I/O during normal operation.
|
|
5
|
+
* Touch file feature is optional and only writes when explicitly configured.
|
|
6
|
+
*/
|
|
7
|
+
import type { MetaQueryResponse } from '../introspect/meta-query';
|
|
8
|
+
import type { IntrospectionQueryResponse } from '../../types/introspection';
|
|
9
|
+
/**
|
|
10
|
+
* Lightweight in-memory schema cache
|
|
11
|
+
* Only stores the combined hash string to detect changes
|
|
12
|
+
*/
|
|
13
|
+
export declare class SchemaCache {
|
|
14
|
+
/** Current schema hash (in-memory only) */
|
|
15
|
+
private currentHash;
|
|
16
|
+
/**
|
|
17
|
+
* Check if schema has changed by comparing hashes
|
|
18
|
+
* This is the hot path - must be efficient
|
|
19
|
+
*/
|
|
20
|
+
hasChanged(meta: MetaQueryResponse, schema: IntrospectionQueryResponse): Promise<{
|
|
21
|
+
changed: boolean;
|
|
22
|
+
newHash: string;
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Update the cached hash (call after successful regeneration)
|
|
26
|
+
*/
|
|
27
|
+
updateHash(hash: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current cached hash
|
|
30
|
+
*/
|
|
31
|
+
getHash(): string | null;
|
|
32
|
+
/**
|
|
33
|
+
* Clear the cached hash
|
|
34
|
+
*/
|
|
35
|
+
clear(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Compute hash from meta and schema responses
|
|
38
|
+
*/
|
|
39
|
+
private computeHash;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Touch a file to signal schema change (for external tools like tsc/webpack)
|
|
43
|
+
* This is the only file I/O in watch mode, and it's optional.
|
|
44
|
+
*/
|
|
45
|
+
export declare function touchFile(filePath: string): void;
|