@constructive-io/graphql-query 2.4.7 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ast.d.ts +10 -38
- package/ast.js +291 -343
- package/custom-ast.d.ts +20 -3
- package/custom-ast.js +115 -15
- package/esm/ast.js +290 -340
- package/esm/custom-ast.js +111 -15
- package/esm/index.js +2 -341
- package/esm/meta-object/convert.js +14 -9
- package/esm/meta-object/format.json +56 -16
- package/esm/meta-object/validate.js +1 -1
- package/esm/query-builder.js +379 -0
- package/esm/types.js +24 -0
- package/index.d.ts +2 -21
- package/index.js +7 -346
- package/meta-object/convert.d.ts +62 -3
- package/meta-object/convert.js +14 -9
- package/meta-object/format.json +56 -16
- package/meta-object/validate.js +1 -1
- package/package.json +3 -3
- package/query-builder.d.ts +47 -0
- package/query-builder.js +416 -0
- package/types.d.ts +139 -0
- package/types.js +28 -0
package/custom-ast.d.ts
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
1
|
+
import type { CleanField, MetaField } from './types';
|
|
2
|
+
export declare function getCustomAst(fieldDefn?: MetaField): any;
|
|
3
|
+
/**
|
|
4
|
+
* Generate custom AST for CleanField type - handles GraphQL types that need subfield selections
|
|
5
|
+
*/
|
|
6
|
+
export declare function getCustomAstForCleanField(field: CleanField): any;
|
|
7
|
+
/**
|
|
8
|
+
* Check if a CleanField requires subfield selection based on its GraphQL type
|
|
9
|
+
*/
|
|
10
|
+
export declare function requiresSubfieldSelection(field: CleanField): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Generate AST for GeometryPoint type
|
|
13
|
+
*/
|
|
14
|
+
export declare function geometryPointAst(name: string): any;
|
|
15
|
+
/**
|
|
16
|
+
* Generate AST for GeometryGeometryCollection type
|
|
17
|
+
*/
|
|
18
|
+
export declare function geometryCollectionAst(name: string): any;
|
|
19
|
+
export declare function geometryAst(name: string): any;
|
|
20
|
+
export declare function intervalAst(name: string): any;
|
|
4
21
|
export declare function isIntervalType(obj: any): boolean;
|
package/custom-ast.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// @ts-nocheck
|
|
3
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
3
|
if (k2 === undefined) k2 = k;
|
|
5
4
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -35,11 +34,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
34
|
})();
|
|
36
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
36
|
exports.getCustomAst = getCustomAst;
|
|
37
|
+
exports.getCustomAstForCleanField = getCustomAstForCleanField;
|
|
38
|
+
exports.requiresSubfieldSelection = requiresSubfieldSelection;
|
|
39
|
+
exports.geometryPointAst = geometryPointAst;
|
|
40
|
+
exports.geometryCollectionAst = geometryCollectionAst;
|
|
38
41
|
exports.geometryAst = geometryAst;
|
|
39
42
|
exports.intervalAst = intervalAst;
|
|
40
43
|
exports.isIntervalType = isIntervalType;
|
|
41
44
|
const t = __importStar(require("gql-ast"));
|
|
42
45
|
function getCustomAst(fieldDefn) {
|
|
46
|
+
if (!fieldDefn) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
43
49
|
const { pgType } = fieldDefn.type;
|
|
44
50
|
if (pgType === 'geometry') {
|
|
45
51
|
return geometryAst(fieldDefn.name);
|
|
@@ -48,15 +54,116 @@ function getCustomAst(fieldDefn) {
|
|
|
48
54
|
return intervalAst(fieldDefn.name);
|
|
49
55
|
}
|
|
50
56
|
return t.field({
|
|
51
|
-
name: fieldDefn.name
|
|
57
|
+
name: fieldDefn.name,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate custom AST for CleanField type - handles GraphQL types that need subfield selections
|
|
62
|
+
*/
|
|
63
|
+
function getCustomAstForCleanField(field) {
|
|
64
|
+
const { name, type } = field;
|
|
65
|
+
const { gqlType, pgType } = type;
|
|
66
|
+
// Handle by GraphQL type first (this is what the error messages reference)
|
|
67
|
+
if (gqlType === 'GeometryPoint') {
|
|
68
|
+
return geometryPointAst(name);
|
|
69
|
+
}
|
|
70
|
+
if (gqlType === 'Interval') {
|
|
71
|
+
return intervalAst(name);
|
|
72
|
+
}
|
|
73
|
+
if (gqlType === 'GeometryGeometryCollection') {
|
|
74
|
+
return geometryCollectionAst(name);
|
|
75
|
+
}
|
|
76
|
+
// Handle by pgType as fallback
|
|
77
|
+
if (pgType === 'geometry') {
|
|
78
|
+
return geometryAst(name);
|
|
79
|
+
}
|
|
80
|
+
if (pgType === 'interval') {
|
|
81
|
+
return intervalAst(name);
|
|
82
|
+
}
|
|
83
|
+
// Return simple field for scalar types
|
|
84
|
+
return t.field({
|
|
85
|
+
name,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if a CleanField requires subfield selection based on its GraphQL type
|
|
90
|
+
*/
|
|
91
|
+
function requiresSubfieldSelection(field) {
|
|
92
|
+
const { gqlType } = field.type;
|
|
93
|
+
// Complex GraphQL types that require subfield selection
|
|
94
|
+
const complexTypes = [
|
|
95
|
+
'GeometryPoint',
|
|
96
|
+
'Interval',
|
|
97
|
+
'GeometryGeometryCollection',
|
|
98
|
+
'GeoJSON',
|
|
99
|
+
];
|
|
100
|
+
return complexTypes.includes(gqlType);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Generate AST for GeometryPoint type
|
|
104
|
+
*/
|
|
105
|
+
function geometryPointAst(name) {
|
|
106
|
+
return t.field({
|
|
107
|
+
name,
|
|
108
|
+
selectionSet: t.selectionSet({
|
|
109
|
+
selections: toFieldArray(['x', 'y']),
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generate AST for GeometryGeometryCollection type
|
|
115
|
+
*/
|
|
116
|
+
function geometryCollectionAst(name) {
|
|
117
|
+
// Manually create inline fragment since gql-ast doesn't support it
|
|
118
|
+
const inlineFragment = {
|
|
119
|
+
kind: 'InlineFragment',
|
|
120
|
+
typeCondition: {
|
|
121
|
+
kind: 'NamedType',
|
|
122
|
+
name: {
|
|
123
|
+
kind: 'Name',
|
|
124
|
+
value: 'GeometryPoint',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
selectionSet: {
|
|
128
|
+
kind: 'SelectionSet',
|
|
129
|
+
selections: [
|
|
130
|
+
{
|
|
131
|
+
kind: 'Field',
|
|
132
|
+
name: {
|
|
133
|
+
kind: 'Name',
|
|
134
|
+
value: 'x',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
kind: 'Field',
|
|
139
|
+
name: {
|
|
140
|
+
kind: 'Name',
|
|
141
|
+
value: 'y',
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
return t.field({
|
|
148
|
+
name,
|
|
149
|
+
selectionSet: t.selectionSet({
|
|
150
|
+
selections: [
|
|
151
|
+
t.field({
|
|
152
|
+
name: 'geometries',
|
|
153
|
+
selectionSet: t.selectionSet({
|
|
154
|
+
selections: [inlineFragment], // gql-ast limitation with inline fragments
|
|
155
|
+
}),
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
}),
|
|
52
159
|
});
|
|
53
160
|
}
|
|
54
161
|
function geometryAst(name) {
|
|
55
162
|
return t.field({
|
|
56
163
|
name,
|
|
57
164
|
selectionSet: t.selectionSet({
|
|
58
|
-
selections: toFieldArray(['geojson'])
|
|
59
|
-
})
|
|
165
|
+
selections: toFieldArray(['geojson']),
|
|
166
|
+
}),
|
|
60
167
|
});
|
|
61
168
|
}
|
|
62
169
|
function intervalAst(name) {
|
|
@@ -69,21 +176,14 @@ function intervalAst(name) {
|
|
|
69
176
|
'minutes',
|
|
70
177
|
'months',
|
|
71
178
|
'seconds',
|
|
72
|
-
'years'
|
|
73
|
-
])
|
|
74
|
-
})
|
|
179
|
+
'years',
|
|
180
|
+
]),
|
|
181
|
+
}),
|
|
75
182
|
});
|
|
76
183
|
}
|
|
77
184
|
function toFieldArray(strArr) {
|
|
78
185
|
return strArr.map((fieldName) => t.field({ name: fieldName }));
|
|
79
186
|
}
|
|
80
187
|
function isIntervalType(obj) {
|
|
81
|
-
return [
|
|
82
|
-
'days',
|
|
83
|
-
'hours',
|
|
84
|
-
'minutes',
|
|
85
|
-
'months',
|
|
86
|
-
'seconds',
|
|
87
|
-
'years'
|
|
88
|
-
].every((key) => obj.hasOwnProperty(key));
|
|
188
|
+
return ['days', 'hours', 'minutes', 'months', 'seconds', 'years'].every((key) => obj.hasOwnProperty(key));
|
|
89
189
|
}
|