@constructive-io/graphql-query 3.2.4 → 3.3.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 (88) hide show
  1. package/README.md +411 -65
  2. package/ast.d.ts +4 -4
  3. package/ast.js +24 -9
  4. package/client/error.d.ts +95 -0
  5. package/client/error.js +277 -0
  6. package/client/execute.d.ts +57 -0
  7. package/client/execute.js +124 -0
  8. package/client/index.d.ts +8 -0
  9. package/client/index.js +20 -0
  10. package/client/typed-document.d.ts +31 -0
  11. package/client/typed-document.js +44 -0
  12. package/custom-ast.d.ts +22 -8
  13. package/custom-ast.js +16 -1
  14. package/esm/ast.js +22 -7
  15. package/esm/client/error.js +271 -0
  16. package/esm/client/execute.js +120 -0
  17. package/esm/client/index.js +8 -0
  18. package/esm/client/typed-document.js +40 -0
  19. package/esm/custom-ast.js +16 -1
  20. package/esm/generators/field-selector.js +381 -0
  21. package/esm/generators/index.js +13 -0
  22. package/esm/generators/mutations.js +200 -0
  23. package/esm/generators/naming-helpers.js +154 -0
  24. package/esm/generators/select.js +661 -0
  25. package/esm/index.js +30 -0
  26. package/esm/introspect/index.js +9 -0
  27. package/esm/introspect/infer-tables.js +697 -0
  28. package/esm/introspect/schema-query.js +120 -0
  29. package/esm/introspect/transform-schema.js +271 -0
  30. package/esm/introspect/transform.js +38 -0
  31. package/esm/meta-object/convert.js +3 -0
  32. package/esm/meta-object/format.json +11 -41
  33. package/esm/meta-object/validate.js +20 -4
  34. package/esm/query-builder.js +14 -18
  35. package/esm/types/index.js +18 -0
  36. package/esm/types/introspection.js +54 -0
  37. package/esm/types/mutation.js +4 -0
  38. package/esm/types/query.js +4 -0
  39. package/esm/types/schema.js +5 -0
  40. package/esm/types/selection.js +4 -0
  41. package/esm/utils.js +69 -0
  42. package/generators/field-selector.d.ts +30 -0
  43. package/generators/field-selector.js +387 -0
  44. package/generators/index.d.ts +9 -0
  45. package/generators/index.js +42 -0
  46. package/generators/mutations.d.ts +30 -0
  47. package/generators/mutations.js +238 -0
  48. package/generators/naming-helpers.d.ts +48 -0
  49. package/generators/naming-helpers.js +169 -0
  50. package/generators/select.d.ts +39 -0
  51. package/generators/select.js +705 -0
  52. package/index.d.ts +19 -0
  53. package/index.js +34 -1
  54. package/introspect/index.d.ts +9 -0
  55. package/introspect/index.js +25 -0
  56. package/introspect/infer-tables.d.ts +42 -0
  57. package/introspect/infer-tables.js +700 -0
  58. package/introspect/schema-query.d.ts +20 -0
  59. package/introspect/schema-query.js +123 -0
  60. package/introspect/transform-schema.d.ts +86 -0
  61. package/introspect/transform-schema.js +281 -0
  62. package/introspect/transform.d.ts +20 -0
  63. package/introspect/transform.js +43 -0
  64. package/meta-object/convert.d.ts +3 -0
  65. package/meta-object/convert.js +3 -0
  66. package/meta-object/format.json +11 -41
  67. package/meta-object/validate.d.ts +8 -3
  68. package/meta-object/validate.js +20 -4
  69. package/package.json +4 -3
  70. package/query-builder.d.ts +11 -12
  71. package/query-builder.js +25 -29
  72. package/{types.d.ts → types/core.d.ts} +25 -18
  73. package/types/index.d.ts +12 -0
  74. package/types/index.js +34 -0
  75. package/types/introspection.d.ts +121 -0
  76. package/types/introspection.js +62 -0
  77. package/types/mutation.d.ts +45 -0
  78. package/types/mutation.js +5 -0
  79. package/types/query.d.ts +91 -0
  80. package/types/query.js +5 -0
  81. package/types/schema.d.ts +265 -0
  82. package/types/schema.js +6 -0
  83. package/types/selection.d.ts +43 -0
  84. package/types/selection.js +5 -0
  85. package/utils.d.ts +17 -0
  86. package/utils.js +72 -0
  87. /package/esm/{types.js → types/core.js} +0 -0
  88. /package/{types.js → types/core.js} +0 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * GraphQL Schema Introspection Query
3
+ *
4
+ * Full introspection query that captures all queries, mutations, and types
5
+ * from a GraphQL endpoint via the standard __schema query.
6
+ */
7
+ /**
8
+ * Full schema introspection query
9
+ *
10
+ * Captures:
11
+ * - All Query fields with args and return types
12
+ * - All Mutation fields with args and return types
13
+ * - All types (OBJECT, INPUT_OBJECT, ENUM, SCALAR) for resolution
14
+ *
15
+ * Uses a recursive TypeRef fragment to handle deeply nested type wrappers
16
+ * (e.g., [String!]! = NON_NULL(LIST(NON_NULL(SCALAR))))
17
+ */
18
+ export const SCHEMA_INTROSPECTION_QUERY = `
19
+ query IntrospectSchema {
20
+ __schema {
21
+ queryType {
22
+ name
23
+ }
24
+ mutationType {
25
+ name
26
+ }
27
+ subscriptionType {
28
+ name
29
+ }
30
+ types {
31
+ kind
32
+ name
33
+ description
34
+ fields(includeDeprecated: true) {
35
+ name
36
+ description
37
+ args {
38
+ name
39
+ description
40
+ type {
41
+ ...TypeRef
42
+ }
43
+ defaultValue
44
+ }
45
+ type {
46
+ ...TypeRef
47
+ }
48
+ isDeprecated
49
+ deprecationReason
50
+ }
51
+ inputFields {
52
+ name
53
+ description
54
+ type {
55
+ ...TypeRef
56
+ }
57
+ defaultValue
58
+ }
59
+ interfaces {
60
+ name
61
+ }
62
+ enumValues(includeDeprecated: true) {
63
+ name
64
+ description
65
+ isDeprecated
66
+ deprecationReason
67
+ }
68
+ possibleTypes {
69
+ name
70
+ }
71
+ }
72
+ directives {
73
+ name
74
+ description
75
+ locations
76
+ args {
77
+ name
78
+ description
79
+ type {
80
+ ...TypeRef
81
+ }
82
+ defaultValue
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+ fragment TypeRef on __Type {
89
+ kind
90
+ name
91
+ ofType {
92
+ kind
93
+ name
94
+ ofType {
95
+ kind
96
+ name
97
+ ofType {
98
+ kind
99
+ name
100
+ ofType {
101
+ kind
102
+ name
103
+ ofType {
104
+ kind
105
+ name
106
+ ofType {
107
+ kind
108
+ name
109
+ ofType {
110
+ kind
111
+ name
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ `;
@@ -0,0 +1,271 @@
1
+ import { getBaseTypeName, isNonNull, unwrapType, } from '../types/introspection';
2
+ // ============================================================================
3
+ // Type Registry Builder
4
+ // ============================================================================
5
+ /**
6
+ * Build a type registry from introspection types
7
+ * Maps type names to their full resolved definitions
8
+ *
9
+ * This is a two-pass process to handle circular references:
10
+ * 1. First pass: Create all type entries with basic info
11
+ * 2. Second pass: Resolve fields with references to other types
12
+ */
13
+ export function buildTypeRegistry(types) {
14
+ const registry = new Map();
15
+ // First pass: Create all type entries
16
+ for (const type of types) {
17
+ // Skip built-in types that start with __
18
+ if (type.name.startsWith('__'))
19
+ continue;
20
+ const resolvedType = {
21
+ kind: type.kind,
22
+ name: type.name,
23
+ description: type.description ?? undefined,
24
+ };
25
+ // Resolve enum values for ENUM types (no circular refs possible)
26
+ if (type.kind === 'ENUM' && type.enumValues) {
27
+ resolvedType.enumValues = type.enumValues.map((ev) => ev.name);
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
+ }
33
+ registry.set(type.name, resolvedType);
34
+ }
35
+ // Second pass: Resolve fields (now that all types exist in registry)
36
+ for (const type of types) {
37
+ if (type.name.startsWith('__'))
38
+ continue;
39
+ const resolvedType = registry.get(type.name);
40
+ if (!resolvedType)
41
+ continue;
42
+ // Resolve fields for OBJECT types
43
+ if (type.kind === 'OBJECT' && type.fields) {
44
+ resolvedType.fields = type.fields.map((field) => transformFieldToCleanObjectFieldShallow(field));
45
+ }
46
+ // Resolve input fields for INPUT_OBJECT types
47
+ if (type.kind === 'INPUT_OBJECT' && type.inputFields) {
48
+ resolvedType.inputFields = type.inputFields.map((field) => transformInputValueToCleanArgumentShallow(field));
49
+ }
50
+ }
51
+ return registry;
52
+ }
53
+ /**
54
+ * Transform field to CleanObjectField without resolving nested types
55
+ * (shallow transformation to avoid circular refs)
56
+ */
57
+ function transformFieldToCleanObjectFieldShallow(field) {
58
+ return {
59
+ name: field.name,
60
+ type: transformTypeRefShallow(field.type),
61
+ description: field.description ?? undefined,
62
+ };
63
+ }
64
+ /**
65
+ * Transform input value to CleanArgument without resolving nested types
66
+ */
67
+ function transformInputValueToCleanArgumentShallow(inputValue) {
68
+ return {
69
+ name: inputValue.name,
70
+ type: transformTypeRefShallow(inputValue.type),
71
+ defaultValue: inputValue.defaultValue ?? undefined,
72
+ description: inputValue.description ?? undefined,
73
+ };
74
+ }
75
+ /**
76
+ * Transform TypeRef without resolving nested types
77
+ * Only handles wrappers (LIST, NON_NULL) and stores the type name
78
+ */
79
+ function transformTypeRefShallow(typeRef) {
80
+ const cleanRef = {
81
+ kind: typeRef.kind,
82
+ name: typeRef.name,
83
+ };
84
+ if (typeRef.ofType) {
85
+ cleanRef.ofType = transformTypeRefShallow(typeRef.ofType);
86
+ }
87
+ return cleanRef;
88
+ }
89
+ /**
90
+ * Transform introspection response to clean operations
91
+ */
92
+ export function transformSchemaToOperations(response) {
93
+ const { __schema: schema } = response;
94
+ const { types, queryType, mutationType } = schema;
95
+ // Build type registry first
96
+ const typeRegistry = buildTypeRegistry(types);
97
+ // Find Query and Mutation types
98
+ const queryTypeDef = types.find((t) => t.name === queryType.name);
99
+ const mutationTypeDef = mutationType
100
+ ? types.find((t) => t.name === mutationType.name)
101
+ : null;
102
+ // Transform queries
103
+ const queries = queryTypeDef?.fields
104
+ ? queryTypeDef.fields.map((field) => transformFieldToCleanOperation(field, 'query', types))
105
+ : [];
106
+ // Transform mutations
107
+ const mutations = mutationTypeDef?.fields
108
+ ? mutationTypeDef.fields.map((field) => transformFieldToCleanOperation(field, 'mutation', types))
109
+ : [];
110
+ return { queries, mutations, typeRegistry };
111
+ }
112
+ // ============================================================================
113
+ // Field to Operation Transformation
114
+ // ============================================================================
115
+ /**
116
+ * Transform an introspection field to a CleanOperation
117
+ */
118
+ function transformFieldToCleanOperation(field, kind, types) {
119
+ return {
120
+ name: field.name,
121
+ kind,
122
+ args: field.args.map((arg) => transformInputValueToCleanArgument(arg, types)),
123
+ returnType: transformTypeRefToCleanTypeRef(field.type, types),
124
+ description: field.description ?? undefined,
125
+ isDeprecated: field.isDeprecated,
126
+ deprecationReason: field.deprecationReason ?? undefined,
127
+ };
128
+ }
129
+ /**
130
+ * Transform an input value to CleanArgument
131
+ */
132
+ function transformInputValueToCleanArgument(inputValue, types) {
133
+ return {
134
+ name: inputValue.name,
135
+ type: transformTypeRefToCleanTypeRef(inputValue.type, types),
136
+ defaultValue: inputValue.defaultValue ?? undefined,
137
+ description: inputValue.description ?? undefined,
138
+ };
139
+ }
140
+ // ============================================================================
141
+ // Type Reference Transformation
142
+ // ============================================================================
143
+ /**
144
+ * Transform an introspection TypeRef to CleanTypeRef
145
+ * Recursively handles wrapper types (LIST, NON_NULL)
146
+ *
147
+ * NOTE: We intentionally do NOT resolve nested fields here to avoid
148
+ * infinite recursion from circular type references. Fields are resolved
149
+ * lazily via the TypeRegistry when needed for code generation.
150
+ */
151
+ function transformTypeRefToCleanTypeRef(typeRef, types) {
152
+ const cleanRef = {
153
+ kind: typeRef.kind,
154
+ name: typeRef.name,
155
+ };
156
+ // Recursively transform ofType for wrappers (LIST, NON_NULL)
157
+ if (typeRef.ofType) {
158
+ cleanRef.ofType = transformTypeRefToCleanTypeRef(typeRef.ofType, types);
159
+ }
160
+ // For named types, only resolve enum values (they don't have circular refs)
161
+ // Fields are NOT resolved here - they're resolved via TypeRegistry during codegen
162
+ if (typeRef.name && !typeRef.ofType) {
163
+ const typeDef = types.find((t) => t.name === typeRef.name);
164
+ if (typeDef) {
165
+ // Add enum values for ENUM types (safe, no recursion)
166
+ if (typeDef.kind === 'ENUM' && typeDef.enumValues) {
167
+ cleanRef.enumValues = typeDef.enumValues.map((ev) => ev.name);
168
+ }
169
+ // NOTE: OBJECT and INPUT_OBJECT fields are resolved via TypeRegistry
170
+ // to avoid circular reference issues
171
+ }
172
+ }
173
+ return cleanRef;
174
+ }
175
+ // ============================================================================
176
+ // Operation Filtering
177
+ // ============================================================================
178
+ /**
179
+ * Filter operations by include/exclude patterns
180
+ * Uses glob-like patterns (supports * wildcard)
181
+ */
182
+ export function filterOperations(operations, include, exclude) {
183
+ let result = operations;
184
+ if (include && include.length > 0) {
185
+ result = result.filter((op) => matchesPatterns(op.name, include));
186
+ }
187
+ if (exclude && exclude.length > 0) {
188
+ result = result.filter((op) => !matchesPatterns(op.name, exclude));
189
+ }
190
+ return result;
191
+ }
192
+ /**
193
+ * Check if a name matches any of the patterns
194
+ * Supports simple glob patterns with * wildcard
195
+ */
196
+ function matchesPatterns(name, patterns) {
197
+ return patterns.some((pattern) => {
198
+ if (pattern === '*')
199
+ return true;
200
+ if (pattern.includes('*')) {
201
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
202
+ return regex.test(name);
203
+ }
204
+ return name === pattern;
205
+ });
206
+ }
207
+ /**
208
+ * Get the set of table-related operation names from tables
209
+ * Used to identify which operations are already covered by table generators
210
+ *
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.
223
+ */
224
+ export function getTableOperationNames(tables) {
225
+ const queries = new Set();
226
+ const mutations = new Set();
227
+ for (const table of tables) {
228
+ if (table.query) {
229
+ // Add exact query names from _meta
230
+ queries.add(table.query.all);
231
+ if (table.query.one) {
232
+ queries.add(table.query.one);
233
+ }
234
+ // Add exact mutation names from _meta
235
+ mutations.add(table.query.create);
236
+ if (table.query.update)
237
+ mutations.add(table.query.update);
238
+ if (table.query.delete)
239
+ mutations.add(table.query.delete);
240
+ }
241
+ }
242
+ return { queries, mutations };
243
+ }
244
+ /**
245
+ * Check if an operation is a table operation (already handled by table generators)
246
+ *
247
+ * Uses EXACT match only - no pattern matching. This ensures:
248
+ * 1. Only operations explicitly in _meta.query are treated as table operations
249
+ * 2. All other operations (including update*By*, delete*By*) become custom operations
250
+ * 3. 100% schema coverage is guaranteed
251
+ */
252
+ export function isTableOperation(operation, tableOperationNames) {
253
+ if (operation.kind === 'query') {
254
+ return tableOperationNames.queries.has(operation.name);
255
+ }
256
+ return tableOperationNames.mutations.has(operation.name);
257
+ }
258
+ /**
259
+ * Get only custom operations (not covered by table generators)
260
+ *
261
+ * This returns ALL operations that are not exact matches for table CRUD operations.
262
+ * Includes:
263
+ * - Unique constraint queries (*ByUsername, *ByEmail, etc.)
264
+ * - Unique constraint mutations (update*By*, delete*By*)
265
+ * - True custom operations (login, register, bootstrapUser, etc.)
266
+ */
267
+ export function getCustomOperations(operations, tableOperationNames) {
268
+ return operations.filter((op) => !isTableOperation(op, tableOperationNames));
269
+ }
270
+ // Re-export utility functions from introspection types
271
+ export { getBaseTypeName, isNonNull, unwrapType };
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Get table names from CleanTable array
3
+ */
4
+ export function getTableNames(tables) {
5
+ return tables.map((t) => t.name);
6
+ }
7
+ /**
8
+ * Find a table by name
9
+ */
10
+ export function findTable(tables, name) {
11
+ return tables.find((t) => t.name === name);
12
+ }
13
+ /**
14
+ * Filter tables by name pattern (glob-like)
15
+ */
16
+ export function filterTables(tables, include, exclude) {
17
+ let result = tables;
18
+ if (include && include.length > 0) {
19
+ result = result.filter((t) => matchesPatterns(t.name, include));
20
+ }
21
+ if (exclude && exclude.length > 0) {
22
+ result = result.filter((t) => !matchesPatterns(t.name, exclude));
23
+ }
24
+ return result;
25
+ }
26
+ /**
27
+ * Check if a name matches any of the patterns
28
+ * Supports simple glob patterns with * wildcard
29
+ */
30
+ function matchesPatterns(name, patterns) {
31
+ return patterns.some((pattern) => {
32
+ if (pattern.includes('*')) {
33
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*').replace(/\?/g, '.') + '$');
34
+ return regex.test(name);
35
+ }
36
+ return name === pattern;
37
+ });
38
+ }
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Convert from raw _meta schema response to internal MetaObject format
3
+ */
1
4
  export function convertFromMetaSchema(metaSchema) {
2
5
  const { _meta: { tables }, } = metaSchema;
3
6
  const result = {
@@ -5,44 +5,27 @@
5
5
  "definitions": {
6
6
  "field": {
7
7
  "type": "object",
8
- "required": [
9
- "name",
10
- "type"
11
- ],
8
+ "required": ["name", "type"],
12
9
  "additionalProperties": true,
13
10
  "properties": {
14
11
  "name": {
15
12
  "type": "string",
16
13
  "default": "id",
17
- "examples": [
18
- "id"
19
- ]
14
+ "examples": ["id"]
20
15
  },
21
16
  "type": {
22
17
  "type": "object",
23
- "required": [
24
- "pgType",
25
- "gqlType"
26
- ],
18
+ "required": ["pgType", "gqlType"],
27
19
  "additionalProperties": true,
28
20
  "properties": {
29
21
  "gqlType": {
30
- "type": [
31
- "string",
32
- "null"
33
- ]
22
+ "type": ["string", "null"]
34
23
  },
35
24
  "pgType": {
36
- "type": [
37
- "string",
38
- "null"
39
- ]
25
+ "type": ["string", "null"]
40
26
  },
41
27
  "subtype": {
42
- "type": [
43
- "string",
44
- "null"
45
- ]
28
+ "type": ["string", "null"]
46
29
  }
47
30
  }
48
31
  }
@@ -58,9 +41,7 @@
58
41
  "name": {
59
42
  "type": "string",
60
43
  "default": "User",
61
- "examples": [
62
- "User"
63
- ]
44
+ "examples": ["User"]
64
45
  },
65
46
  "fields": {
66
47
  "type": "array",
@@ -88,9 +69,7 @@
88
69
  "refTable": {
89
70
  "type": "string",
90
71
  "default": "User",
91
- "examples": [
92
- "User"
93
- ]
72
+ "examples": ["User"]
94
73
  },
95
74
  "fromKey": {
96
75
  "$ref": "#/definitions/field"
@@ -99,25 +78,16 @@
99
78
  "$ref": "#/definitions/field"
100
79
  }
101
80
  },
102
- "required": [
103
- "refTable",
104
- "fromKey",
105
- "toKey"
106
- ],
81
+ "required": ["refTable", "fromKey", "toKey"],
107
82
  "additionalProperties": false
108
83
  }
109
84
  }
110
85
  },
111
- "required": [
112
- "name",
113
- "fields"
114
- ],
86
+ "required": ["name", "fields"],
115
87
  "additionalProperties": false
116
88
  }
117
89
  }
118
90
  },
119
- "required": [
120
- "tables"
121
- ],
91
+ "required": ["tables"],
122
92
  "additionalProperties": false
123
93
  }
@@ -1,12 +1,28 @@
1
1
  import Ajv from 'ajv';
2
2
  import format from './format.json';
3
+ let cachedAjv = null;
4
+ let cachedValidator = null;
5
+ function getValidator() {
6
+ if (!cachedAjv) {
7
+ cachedAjv = new Ajv({ allErrors: true });
8
+ cachedValidator = cachedAjv.compile(format);
9
+ }
10
+ return {
11
+ ajv: cachedAjv,
12
+ validator: cachedValidator,
13
+ };
14
+ }
15
+ /**
16
+ * Validate a MetaObject against the JSON schema
17
+ * @returns true if valid, or an object with errors and message if invalid
18
+ */
3
19
  export function validateMetaObject(obj) {
4
- const ajv = new Ajv({ allErrors: true });
5
- const valid = ajv.validate(format, obj);
20
+ const { ajv, validator } = getValidator();
21
+ const valid = validator(obj);
6
22
  if (valid)
7
23
  return true;
8
24
  return {
9
- errors: ajv.errors,
10
- message: ajv.errorsText(ajv.errors, { separator: '\n' }),
25
+ errors: validator.errors,
26
+ message: ajv.errorsText(validator.errors, { separator: '\n' }),
11
27
  };
12
28
  }
@@ -1,5 +1,5 @@
1
1
  import { print as gqlPrint } from 'graphql';
2
- import { camelize, pluralize, underscore } from 'inflection';
2
+ import { camelize, pluralize, underscore } from 'inflekt';
3
3
  import { createOne, deleteOne, getAll, getCount, getMany, getOne, patchOne, } from './ast';
4
4
  import { validateMetaObject } from './meta-object';
5
5
  export * as MetaObject from './meta-object';
@@ -9,7 +9,6 @@ export class QueryBuilder {
9
9
  _meta;
10
10
  _models;
11
11
  _model;
12
- _fields;
13
12
  _key;
14
13
  _queryName;
15
14
  _ast;
@@ -33,21 +32,16 @@ export class QueryBuilder {
33
32
  * Save all gql queries and mutations by model name for quicker lookup
34
33
  */
35
34
  initModelMap() {
36
- this._models = Object.keys(this._introspection).reduce((map, key) => {
37
- const defn = this._introspection[key];
38
- map = {
39
- ...map,
40
- [defn.model]: {
41
- ...map[defn.model],
42
- ...{ [key]: defn },
43
- },
44
- };
45
- return map;
46
- }, {});
35
+ this._models = {};
36
+ for (const [key, defn] of Object.entries(this._introspection)) {
37
+ if (!this._models[defn.model]) {
38
+ this._models[defn.model] = {};
39
+ }
40
+ this._models[defn.model][key] = defn;
41
+ }
47
42
  }
48
43
  clear() {
49
44
  this._model = '';
50
- this._fields = [];
51
45
  this._key = null;
52
46
  this._queryName = '';
53
47
  this._ast = null;
@@ -265,7 +259,8 @@ function pickScalarFields(selection, defn) {
265
259
  return true;
266
260
  return Object.keys(selection).includes(fieldName);
267
261
  })
268
- .filter((fieldName) => !isRelationalField(fieldName, modelMeta) && isInTableSchema(fieldName))
262
+ .filter((fieldName) => !isRelationalField(fieldName, modelMeta) &&
263
+ isInTableSchema(fieldName))
269
264
  .map((fieldName) => ({
270
265
  name: fieldName,
271
266
  isObject: false,
@@ -310,9 +305,10 @@ function pickAllFields(selection, defn) {
310
305
  }
311
306
  const referencedForeignConstraint = modelMeta.foreignConstraints.find((constraint) => constraint.fromKey.name === fieldName ||
312
307
  constraint.fromKey.alias === fieldName);
313
- const subFields = Object.keys(fieldOptions.select).filter((subField) => {
308
+ const selectOptions = fieldOptions;
309
+ const subFields = Object.keys(selectOptions.select).filter((subField) => {
314
310
  return (!isRelationalField(subField, modelMeta) &&
315
- isWhiteListed(fieldOptions.select[subField]));
311
+ isWhiteListed(selectOptions.select[subField]));
316
312
  });
317
313
  const isBelongTo = !!referencedForeignConstraint;
318
314
  const fieldSelection = {
@@ -320,7 +316,7 @@ function pickAllFields(selection, defn) {
320
316
  isObject: true,
321
317
  isBelongTo,
322
318
  selection: subFields.map((name) => ({ name, isObject: false })),
323
- variables: fieldOptions.variables,
319
+ variables: selectOptions.variables,
324
320
  };
325
321
  // Need to further expand selection of object fields,
326
322
  // but only non-graphql-builtin, non-relation fields
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Barrel export for all types
3
+ *
4
+ * Re-exports both the original QueryBuilder runtime types (core.ts)
5
+ * and the codegen-style types (schema, introspection, query, mutation, selection)
6
+ */
7
+ // Original QueryBuilder runtime types
8
+ export * from './core';
9
+ // Codegen-style schema types (CleanTable, CleanField, etc.)
10
+ export * from './schema';
11
+ // Introspection types
12
+ export * from './introspection';
13
+ // Query types (QueryOptions, Filter, etc.)
14
+ export * from './query';
15
+ // Mutation types
16
+ export * from './mutation';
17
+ // Selection types (FieldSelection presets, SimpleFieldSelection, etc.)
18
+ export * from './selection';