@constructive-io/graphql-codegen 4.6.1 → 4.7.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/client/error.d.ts +2 -93
- package/client/error.js +9 -273
- package/client/execute.d.ts +2 -55
- package/client/execute.js +5 -120
- package/client/typed-document.d.ts +2 -29
- package/client/typed-document.js +3 -39
- package/core/ast.d.ts +8 -10
- package/core/ast.js +17 -592
- package/core/custom-ast.d.ts +5 -33
- package/core/custom-ast.js +16 -203
- package/core/introspect/infer-tables.d.ts +2 -40
- package/core/introspect/infer-tables.js +4 -696
- package/core/introspect/schema-query.d.ts +3 -18
- package/core/introspect/schema-query.js +3 -118
- package/core/introspect/transform-schema.d.ts +2 -84
- package/core/introspect/transform-schema.js +14 -279
- package/core/introspect/transform.d.ts +2 -18
- package/core/introspect/transform.js +6 -39
- package/core/meta-object/convert.d.ts +2 -63
- package/core/meta-object/convert.js +4 -59
- package/core/meta-object/validate.d.ts +2 -7
- package/core/meta-object/validate.js +4 -30
- package/core/query-builder.d.ts +7 -46
- package/core/query-builder.js +8 -408
- package/core/types.d.ts +9 -139
- package/core/types.js +12 -26
- package/esm/client/error.d.ts +2 -93
- package/esm/client/error.js +2 -269
- package/esm/client/execute.d.ts +2 -55
- package/esm/client/execute.js +2 -118
- package/esm/client/typed-document.d.ts +2 -29
- package/esm/client/typed-document.js +2 -38
- package/esm/core/ast.d.ts +8 -10
- package/esm/core/ast.js +8 -550
- package/esm/core/custom-ast.d.ts +5 -33
- package/esm/core/custom-ast.js +5 -160
- package/esm/core/introspect/infer-tables.d.ts +2 -40
- package/esm/core/introspect/infer-tables.js +2 -695
- package/esm/core/introspect/schema-query.d.ts +3 -18
- package/esm/core/introspect/schema-query.js +2 -118
- package/esm/core/introspect/transform-schema.d.ts +2 -84
- package/esm/core/introspect/transform-schema.js +2 -269
- package/esm/core/introspect/transform.d.ts +2 -18
- package/esm/core/introspect/transform.js +2 -36
- package/esm/core/meta-object/convert.d.ts +2 -63
- package/esm/core/meta-object/convert.js +2 -58
- package/esm/core/meta-object/validate.d.ts +2 -7
- package/esm/core/meta-object/validate.js +2 -26
- package/esm/core/query-builder.d.ts +7 -46
- package/esm/core/query-builder.js +5 -373
- package/esm/core/types.d.ts +9 -139
- package/esm/core/types.js +9 -24
- package/esm/generators/field-selector.d.ts +5 -28
- package/esm/generators/field-selector.js +5 -379
- package/esm/generators/mutations.d.ts +5 -28
- package/esm/generators/mutations.js +5 -198
- package/esm/generators/naming-helpers.d.ts +3 -45
- package/esm/generators/naming-helpers.js +3 -151
- package/esm/generators/select.d.ts +6 -37
- package/esm/generators/select.js +6 -659
- package/generators/field-selector.d.ts +5 -28
- package/generators/field-selector.js +12 -385
- package/generators/mutations.d.ts +5 -28
- package/generators/mutations.js +9 -234
- package/generators/naming-helpers.d.ts +3 -45
- package/generators/naming-helpers.js +15 -164
- package/generators/select.d.ts +6 -37
- package/generators/select.js +17 -703
- package/package.json +7 -6
- package/core/meta-object/format.json +0 -93
- package/esm/core/meta-object/format.json +0 -93
|
@@ -1,48 +1,6 @@
|
|
|
1
|
-
import type { CleanTable } from '../types/schema';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Returns `null` for null, undefined, or whitespace-only strings.
|
|
5
|
-
*/
|
|
6
|
-
export declare function normalizeInflectionValue(value: string | null | undefined): string | null;
|
|
7
|
-
/**
|
|
8
|
-
* Convert PascalCase table name to camelCase plural for GraphQL queries.
|
|
9
|
-
* Prefers server-provided `table.query.all` / `table.inflection.allRows`
|
|
10
|
-
* when available, with guards against naive pluralisation drift and
|
|
11
|
-
* missing camelCase boundaries.
|
|
2
|
+
* Re-export naming helpers from @constructive-io/graphql-query.
|
|
12
3
|
*
|
|
13
|
-
*
|
|
14
|
-
*/
|
|
15
|
-
export declare function toCamelCasePlural(tableName: string, table?: CleanTable | null): string;
|
|
16
|
-
/**
|
|
17
|
-
* Convert PascalCase table name to camelCase singular field name.
|
|
18
|
-
* Prefers server-provided names when available.
|
|
19
|
-
*/
|
|
20
|
-
export declare function toCamelCaseSingular(tableName: string, table?: CleanTable | null): string;
|
|
21
|
-
export declare function toCreateMutationName(tableName: string, table?: CleanTable | null): string;
|
|
22
|
-
export declare function toUpdateMutationName(tableName: string, table?: CleanTable | null): string;
|
|
23
|
-
export declare function toDeleteMutationName(tableName: string, table?: CleanTable | null): string;
|
|
24
|
-
export declare function toCreateInputTypeName(tableName: string, table?: CleanTable | null): string;
|
|
25
|
-
export declare function toUpdateInputTypeName(tableName: string): string;
|
|
26
|
-
export declare function toDeleteInputTypeName(tableName: string): string;
|
|
27
|
-
export declare function toFilterTypeName(tableName: string, table?: CleanTable | null): string;
|
|
28
|
-
/**
|
|
29
|
-
* Resolve PostGraphile patch field name.
|
|
30
|
-
* In v5 this is typically entity-specific: e.g. "userPatch", "contactPatch".
|
|
31
|
-
* Prefers the value discovered from the schema (`table.query.patchFieldName`
|
|
32
|
-
* or `table.inflection.patchField`), falls back to `${singularName}Patch`.
|
|
33
|
-
*/
|
|
34
|
-
export declare function toPatchFieldName(tableName: string, table?: CleanTable | null): string;
|
|
35
|
-
/**
|
|
36
|
-
* Convert camelCase field name to SCREAMING_SNAKE_CASE for PostGraphile
|
|
37
|
-
* orderBy enums.
|
|
38
|
-
*
|
|
39
|
-
* "displayName" -> "DISPLAY_NAME_ASC"
|
|
40
|
-
* "createdAt" -> "CREATED_AT_DESC"
|
|
41
|
-
* "id" -> "ID_ASC"
|
|
42
|
-
*/
|
|
43
|
-
export declare function toOrderByEnumValue(fieldName: string, direction: 'asc' | 'desc'): string;
|
|
44
|
-
/**
|
|
45
|
-
* Generate the PostGraphile OrderBy enum type name for a table.
|
|
46
|
-
* Prefers server-provided `table.inflection.orderByType` when available.
|
|
4
|
+
* Server-aware inflection naming functions now live in graphql-query.
|
|
47
5
|
*/
|
|
48
|
-
export
|
|
6
|
+
export { normalizeInflectionValue, toCamelCaseSingular, toCreateMutationName, toUpdateMutationName, toDeleteMutationName, toCreateInputTypeName, toUpdateInputTypeName, toDeleteInputTypeName, toFilterTypeName, toPatchFieldName, toOrderByEnumValue, } from '@constructive-io/graphql-query';
|
|
@@ -1,169 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeInflectionValue =
|
|
4
|
-
exports.toCamelCasePlural = toCamelCasePlural;
|
|
5
|
-
exports.toCamelCaseSingular = toCamelCaseSingular;
|
|
6
|
-
exports.toCreateMutationName = toCreateMutationName;
|
|
7
|
-
exports.toUpdateMutationName = toUpdateMutationName;
|
|
8
|
-
exports.toDeleteMutationName = toDeleteMutationName;
|
|
9
|
-
exports.toCreateInputTypeName = toCreateInputTypeName;
|
|
10
|
-
exports.toUpdateInputTypeName = toUpdateInputTypeName;
|
|
11
|
-
exports.toDeleteInputTypeName = toDeleteInputTypeName;
|
|
12
|
-
exports.toFilterTypeName = toFilterTypeName;
|
|
13
|
-
exports.toPatchFieldName = toPatchFieldName;
|
|
14
|
-
exports.toOrderByEnumValue = toOrderByEnumValue;
|
|
15
|
-
exports.toOrderByTypeName = toOrderByTypeName;
|
|
3
|
+
exports.toOrderByEnumValue = exports.toPatchFieldName = exports.toFilterTypeName = exports.toDeleteInputTypeName = exports.toUpdateInputTypeName = exports.toCreateInputTypeName = exports.toDeleteMutationName = exports.toUpdateMutationName = exports.toCreateMutationName = exports.toCamelCaseSingular = exports.normalizeInflectionValue = void 0;
|
|
16
4
|
/**
|
|
17
|
-
*
|
|
5
|
+
* Re-export naming helpers from @constructive-io/graphql-query.
|
|
18
6
|
*
|
|
19
|
-
*
|
|
20
|
-
* (stored on `table.query` and `table.inflection` by `infer-tables.ts`)
|
|
21
|
-
* and fall back to local inflection when introspection data is unavailable.
|
|
22
|
-
*
|
|
23
|
-
* Back-ported from Dashboard's `packages/data/src/query-generator.ts`.
|
|
24
|
-
*/
|
|
25
|
-
const inflekt_1 = require("inflekt");
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// Internal helpers
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
/**
|
|
30
|
-
* Safely normalise a server-provided inflection value.
|
|
31
|
-
* Returns `null` for null, undefined, or whitespace-only strings.
|
|
32
|
-
*/
|
|
33
|
-
function normalizeInflectionValue(value) {
|
|
34
|
-
if (typeof value !== 'string')
|
|
35
|
-
return null;
|
|
36
|
-
const trimmed = value.trim();
|
|
37
|
-
return trimmed.length > 0 ? trimmed : null;
|
|
38
|
-
}
|
|
39
|
-
// ---------------------------------------------------------------------------
|
|
40
|
-
// Plural / Singular
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
/**
|
|
43
|
-
* Convert PascalCase table name to camelCase plural for GraphQL queries.
|
|
44
|
-
* Prefers server-provided `table.query.all` / `table.inflection.allRows`
|
|
45
|
-
* when available, with guards against naive pluralisation drift and
|
|
46
|
-
* missing camelCase boundaries.
|
|
47
|
-
*
|
|
48
|
-
* Example: "ActionGoal" -> "actionGoals", "User" -> "users", "Person" -> "people"
|
|
49
|
-
*/
|
|
50
|
-
function toCamelCasePlural(tableName, table) {
|
|
51
|
-
const singular = (0, inflekt_1.camelize)(tableName, true);
|
|
52
|
-
const inflectedPlural = (0, inflekt_1.pluralize)(singular);
|
|
53
|
-
const serverPluralCandidates = [
|
|
54
|
-
table?.query?.all,
|
|
55
|
-
table?.inflection?.allRows,
|
|
56
|
-
];
|
|
57
|
-
for (const candidateRaw of serverPluralCandidates) {
|
|
58
|
-
const candidate = normalizeInflectionValue(candidateRaw);
|
|
59
|
-
if (!candidate)
|
|
60
|
-
continue;
|
|
61
|
-
// Guard against known fallback drift:
|
|
62
|
-
// 1. Naive pluralisation: "activitys" instead of "activities"
|
|
63
|
-
const isNaivePlural = candidate === `${singular}s` && candidate !== inflectedPlural;
|
|
64
|
-
// 2. Missing camelCase boundaries: "deliveryzones" instead of "deliveryZones"
|
|
65
|
-
const isMiscased = candidate !== inflectedPlural &&
|
|
66
|
-
candidate.toLowerCase() === inflectedPlural.toLowerCase();
|
|
67
|
-
if (isNaivePlural || isMiscased)
|
|
68
|
-
continue;
|
|
69
|
-
return candidate;
|
|
70
|
-
}
|
|
71
|
-
return inflectedPlural;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Convert PascalCase table name to camelCase singular field name.
|
|
75
|
-
* Prefers server-provided names when available.
|
|
76
|
-
*/
|
|
77
|
-
function toCamelCaseSingular(tableName, table) {
|
|
78
|
-
const localSingular = (0, inflekt_1.camelize)(tableName, true);
|
|
79
|
-
for (const candidateRaw of [
|
|
80
|
-
table?.query?.one,
|
|
81
|
-
table?.inflection?.tableFieldName,
|
|
82
|
-
]) {
|
|
83
|
-
const candidate = normalizeInflectionValue(candidateRaw);
|
|
84
|
-
if (!candidate)
|
|
85
|
-
continue;
|
|
86
|
-
// Reject miscased versions: "deliveryzone" vs "deliveryZone"
|
|
87
|
-
if (candidate !== localSingular &&
|
|
88
|
-
candidate.toLowerCase() === localSingular.toLowerCase())
|
|
89
|
-
continue;
|
|
90
|
-
return candidate;
|
|
91
|
-
}
|
|
92
|
-
return localSingular;
|
|
93
|
-
}
|
|
94
|
-
// ---------------------------------------------------------------------------
|
|
95
|
-
// Mutation names
|
|
96
|
-
// ---------------------------------------------------------------------------
|
|
97
|
-
function toCreateMutationName(tableName, table) {
|
|
98
|
-
return (normalizeInflectionValue(table?.query?.create) ?? `create${tableName}`);
|
|
99
|
-
}
|
|
100
|
-
function toUpdateMutationName(tableName, table) {
|
|
101
|
-
return (normalizeInflectionValue(table?.query?.update) ?? `update${tableName}`);
|
|
102
|
-
}
|
|
103
|
-
function toDeleteMutationName(tableName, table) {
|
|
104
|
-
return (normalizeInflectionValue(table?.query?.delete) ?? `delete${tableName}`);
|
|
105
|
-
}
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
// Input / type names
|
|
108
|
-
// ---------------------------------------------------------------------------
|
|
109
|
-
function toCreateInputTypeName(tableName, table) {
|
|
110
|
-
return (normalizeInflectionValue(table?.inflection?.createInputType) ??
|
|
111
|
-
`Create${tableName}Input`);
|
|
112
|
-
}
|
|
113
|
-
function toUpdateInputTypeName(tableName) {
|
|
114
|
-
return `Update${tableName}Input`;
|
|
115
|
-
}
|
|
116
|
-
function toDeleteInputTypeName(tableName) {
|
|
117
|
-
return `Delete${tableName}Input`;
|
|
118
|
-
}
|
|
119
|
-
function toFilterTypeName(tableName, table) {
|
|
120
|
-
return (normalizeInflectionValue(table?.inflection?.filterType) ??
|
|
121
|
-
`${tableName}Filter`);
|
|
122
|
-
}
|
|
123
|
-
// ---------------------------------------------------------------------------
|
|
124
|
-
// Patch field name
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
/**
|
|
127
|
-
* Resolve PostGraphile patch field name.
|
|
128
|
-
* In v5 this is typically entity-specific: e.g. "userPatch", "contactPatch".
|
|
129
|
-
* Prefers the value discovered from the schema (`table.query.patchFieldName`
|
|
130
|
-
* or `table.inflection.patchField`), falls back to `${singularName}Patch`.
|
|
131
|
-
*/
|
|
132
|
-
function toPatchFieldName(tableName, table) {
|
|
133
|
-
// First check the patch field name discovered from UpdateXxxInput
|
|
134
|
-
const introspectedPatch = normalizeInflectionValue(table?.query?.patchFieldName);
|
|
135
|
-
if (introspectedPatch)
|
|
136
|
-
return introspectedPatch;
|
|
137
|
-
// Then check the inflection table
|
|
138
|
-
const explicitPatchField = normalizeInflectionValue(table?.inflection?.patchField);
|
|
139
|
-
if (explicitPatchField)
|
|
140
|
-
return explicitPatchField;
|
|
141
|
-
return `${toCamelCaseSingular(tableName, table)}Patch`;
|
|
142
|
-
}
|
|
143
|
-
// ---------------------------------------------------------------------------
|
|
144
|
-
// OrderBy helpers
|
|
145
|
-
// ---------------------------------------------------------------------------
|
|
146
|
-
/**
|
|
147
|
-
* Convert camelCase field name to SCREAMING_SNAKE_CASE for PostGraphile
|
|
148
|
-
* orderBy enums.
|
|
149
|
-
*
|
|
150
|
-
* "displayName" -> "DISPLAY_NAME_ASC"
|
|
151
|
-
* "createdAt" -> "CREATED_AT_DESC"
|
|
152
|
-
* "id" -> "ID_ASC"
|
|
153
|
-
*/
|
|
154
|
-
function toOrderByEnumValue(fieldName, direction) {
|
|
155
|
-
const screaming = fieldName
|
|
156
|
-
.replace(/([a-z0-9])([A-Z])/g, '$1_$2')
|
|
157
|
-
.toUpperCase();
|
|
158
|
-
return `${screaming}_${direction.toUpperCase()}`;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Generate the PostGraphile OrderBy enum type name for a table.
|
|
162
|
-
* Prefers server-provided `table.inflection.orderByType` when available.
|
|
7
|
+
* Server-aware inflection naming functions now live in graphql-query.
|
|
163
8
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
9
|
+
var graphql_query_1 = require("@constructive-io/graphql-query");
|
|
10
|
+
Object.defineProperty(exports, "normalizeInflectionValue", { enumerable: true, get: function () { return graphql_query_1.normalizeInflectionValue; } });
|
|
11
|
+
Object.defineProperty(exports, "toCamelCaseSingular", { enumerable: true, get: function () { return graphql_query_1.toCamelCaseSingular; } });
|
|
12
|
+
Object.defineProperty(exports, "toCreateMutationName", { enumerable: true, get: function () { return graphql_query_1.toCreateMutationName; } });
|
|
13
|
+
Object.defineProperty(exports, "toUpdateMutationName", { enumerable: true, get: function () { return graphql_query_1.toUpdateMutationName; } });
|
|
14
|
+
Object.defineProperty(exports, "toDeleteMutationName", { enumerable: true, get: function () { return graphql_query_1.toDeleteMutationName; } });
|
|
15
|
+
Object.defineProperty(exports, "toCreateInputTypeName", { enumerable: true, get: function () { return graphql_query_1.toCreateInputTypeName; } });
|
|
16
|
+
Object.defineProperty(exports, "toUpdateInputTypeName", { enumerable: true, get: function () { return graphql_query_1.toUpdateInputTypeName; } });
|
|
17
|
+
Object.defineProperty(exports, "toDeleteInputTypeName", { enumerable: true, get: function () { return graphql_query_1.toDeleteInputTypeName; } });
|
|
18
|
+
Object.defineProperty(exports, "toFilterTypeName", { enumerable: true, get: function () { return graphql_query_1.toFilterTypeName; } });
|
|
19
|
+
Object.defineProperty(exports, "toPatchFieldName", { enumerable: true, get: function () { return graphql_query_1.toPatchFieldName; } });
|
|
20
|
+
Object.defineProperty(exports, "toOrderByEnumValue", { enumerable: true, get: function () { return graphql_query_1.toOrderByEnumValue; } });
|
package/generators/select.d.ts
CHANGED
|
@@ -1,39 +1,8 @@
|
|
|
1
|
-
import { TypedDocumentString } from '../client/typed-document';
|
|
2
|
-
import { QueryBuilder } from '../core/query-builder';
|
|
3
|
-
import type { IntrospectionSchema, MetaObject } from '../core/types';
|
|
4
|
-
import type { QueryOptions } from '../types/query';
|
|
5
|
-
import type { CleanTable } from '../types/schema';
|
|
6
|
-
export { toCamelCasePlural, toOrderByTypeName } from './naming-helpers';
|
|
7
1
|
/**
|
|
8
|
-
*
|
|
2
|
+
* Re-export select query generators from @constructive-io/graphql-query.
|
|
3
|
+
*
|
|
4
|
+
* The canonical implementations of buildSelect, buildFindOne, buildCount,
|
|
5
|
+
* cleanTableToMetaObject, createASTQueryBuilder, generateIntrospectionSchema,
|
|
6
|
+
* toCamelCasePlural, and toOrderByTypeName now live in graphql-query.
|
|
9
7
|
*/
|
|
10
|
-
export
|
|
11
|
-
/**
|
|
12
|
-
* Generate basic IntrospectionSchema from CleanTable array
|
|
13
|
-
* This creates a minimal schema for AST generation
|
|
14
|
-
*/
|
|
15
|
-
export declare function generateIntrospectionSchema(tables: CleanTable[]): IntrospectionSchema;
|
|
16
|
-
/**
|
|
17
|
-
* Create AST-based query builder for a table
|
|
18
|
-
*/
|
|
19
|
-
export declare function createASTQueryBuilder(tables: CleanTable[]): QueryBuilder;
|
|
20
|
-
/**
|
|
21
|
-
* Build a SELECT query for a table with optional filtering, sorting, and pagination
|
|
22
|
-
* Uses direct AST generation without intermediate conversions
|
|
23
|
-
*/
|
|
24
|
-
export declare function buildSelect(table: CleanTable, allTables: readonly CleanTable[], options?: QueryOptions): TypedDocumentString<Record<string, unknown>, QueryOptions>;
|
|
25
|
-
/**
|
|
26
|
-
* Build a single row query by primary key or unique field
|
|
27
|
-
*/
|
|
28
|
-
export declare function buildFindOne(table: CleanTable, _pkField?: string): TypedDocumentString<Record<string, unknown>, Record<string, unknown>>;
|
|
29
|
-
/**
|
|
30
|
-
* Build a count query for a table
|
|
31
|
-
*/
|
|
32
|
-
export declare function buildCount(table: CleanTable): TypedDocumentString<{
|
|
33
|
-
[key: string]: {
|
|
34
|
-
totalCount: number;
|
|
35
|
-
};
|
|
36
|
-
}, {
|
|
37
|
-
condition?: Record<string, unknown>;
|
|
38
|
-
filter?: Record<string, unknown>;
|
|
39
|
-
}>;
|
|
8
|
+
export { buildSelect, buildFindOne, buildCount, cleanTableToMetaObject, createASTQueryBuilder, generateIntrospectionSchema, toCamelCasePlural, toOrderByTypeName, } from '@constructive-io/graphql-query';
|