@constructive-io/graphql-codegen 3.2.0 → 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.
- package/README.md +25 -30
- package/cli/index.js +36 -41
- package/cli/shared.d.ts +15 -17
- package/cli/shared.js +113 -21
- package/client/error.js +31 -9
- package/client/execute.js +2 -2
- package/client/index.d.ts +3 -3
- package/client/index.js +6 -6
- package/core/ast.d.ts +1 -1
- package/core/ast.js +1 -1
- package/core/codegen/babel-ast.d.ts +1 -1
- package/core/codegen/babel-ast.js +2 -2
- package/core/codegen/barrel.d.ts +0 -6
- package/core/codegen/barrel.js +22 -19
- package/core/codegen/client.d.ts +2 -12
- package/core/codegen/client.js +7 -21
- package/core/codegen/custom-mutations.d.ts +0 -14
- package/core/codegen/custom-mutations.js +139 -88
- package/core/codegen/custom-queries.d.ts +0 -14
- package/core/codegen/custom-queries.js +483 -193
- package/core/codegen/hooks-ast.d.ts +75 -0
- package/core/codegen/hooks-ast.js +522 -0
- package/core/codegen/index.d.ts +16 -18
- package/core/codegen/index.js +42 -88
- package/core/codegen/invalidation.d.ts +1 -7
- package/core/codegen/invalidation.js +50 -16
- package/core/codegen/mutation-keys.d.ts +1 -10
- package/core/codegen/mutation-keys.js +22 -8
- package/core/codegen/mutations.d.ts +0 -13
- package/core/codegen/mutations.js +301 -366
- package/core/codegen/orm/barrel.d.ts +0 -5
- package/core/codegen/orm/barrel.js +5 -0
- package/core/codegen/orm/client-generator.d.ts +0 -5
- package/core/codegen/orm/client-generator.js +7 -2
- package/core/codegen/orm/client.js +3 -1
- package/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/core/codegen/orm/custom-ops-generator.js +104 -51
- package/core/codegen/orm/index.d.ts +4 -4
- package/core/codegen/orm/index.js +28 -15
- package/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/core/codegen/orm/input-types-generator.js +85 -23
- package/core/codegen/orm/model-generator.d.ts +0 -5
- package/core/codegen/orm/model-generator.js +309 -131
- package/core/codegen/orm/select-types.d.ts +19 -14
- package/core/codegen/queries.d.ts +0 -8
- package/core/codegen/queries.js +360 -559
- package/core/codegen/query-keys.d.ts +1 -1
- package/core/codegen/query-keys.js +37 -23
- package/core/codegen/scalars.js +3 -1
- package/core/codegen/schema-types-generator.d.ts +1 -1
- package/core/codegen/schema-types-generator.js +17 -2
- package/core/codegen/select-helpers.d.ts +19 -0
- package/core/codegen/select-helpers.js +40 -0
- package/core/codegen/selection.d.ts +4 -0
- package/core/codegen/selection.js +65 -0
- package/core/codegen/shared/index.d.ts +2 -15
- package/core/codegen/shared/index.js +17 -4
- package/core/codegen/templates/hooks-client.ts +49 -0
- package/core/codegen/templates/hooks-selection.ts +58 -0
- package/core/codegen/templates/orm-client.ts +8 -6
- package/core/codegen/templates/query-builder.ts +250 -46
- package/core/codegen/templates/select-types.ts +31 -14
- package/core/codegen/type-resolver.d.ts +1 -5
- package/core/codegen/type-resolver.js +0 -22
- package/core/codegen/types.d.ts +0 -3
- package/core/codegen/types.js +71 -14
- package/core/codegen/utils.d.ts +1 -4
- package/core/codegen/utils.js +4 -1
- package/core/config/index.d.ts +1 -1
- package/core/config/resolver.js +1 -3
- package/core/generate.js +38 -50
- package/core/index.d.ts +3 -3
- package/core/index.js +3 -4
- package/core/introspect/index.d.ts +6 -6
- package/core/introspect/index.js +5 -8
- package/core/introspect/infer-tables.d.ts +0 -14
- package/core/introspect/infer-tables.js +15 -1
- package/core/introspect/source/database.js +1 -1
- package/core/introspect/source/endpoint.d.ts +0 -6
- package/core/introspect/source/endpoint.js +7 -1
- package/core/introspect/source/index.d.ts +4 -4
- package/core/introspect/source/index.js +5 -9
- package/core/introspect/source/pgpm-module.js +3 -3
- package/core/introspect/transform-schema.d.ts +2 -2
- package/core/introspect/transform-schema.js +2 -2
- package/core/output/index.d.ts +1 -1
- package/core/output/index.js +2 -2
- package/core/output/writer.d.ts +3 -0
- package/core/output/writer.js +20 -1
- package/core/pipeline/index.d.ts +2 -2
- package/core/query-builder.d.ts +2 -2
- package/core/query-builder.js +1 -1
- package/core/watch/index.d.ts +4 -4
- package/core/watch/index.js +9 -9
- package/core/watch/orchestrator.js +5 -3
- package/esm/cli/index.js +37 -42
- package/esm/cli/shared.d.ts +15 -17
- package/esm/cli/shared.js +103 -20
- package/esm/client/error.js +31 -9
- package/esm/client/execute.js +2 -2
- package/esm/client/index.d.ts +3 -3
- package/esm/client/index.js +3 -3
- package/esm/core/ast.d.ts +1 -1
- package/esm/core/ast.js +1 -1
- package/esm/core/codegen/babel-ast.d.ts +1 -1
- package/esm/core/codegen/babel-ast.js +2 -2
- package/esm/core/codegen/barrel.d.ts +0 -6
- package/esm/core/codegen/barrel.js +23 -20
- package/esm/core/codegen/client.d.ts +2 -12
- package/esm/core/codegen/client.js +7 -21
- package/esm/core/codegen/custom-mutations.d.ts +0 -14
- package/esm/core/codegen/custom-mutations.js +141 -90
- package/esm/core/codegen/custom-queries.d.ts +0 -14
- package/esm/core/codegen/custom-queries.js +486 -196
- package/esm/core/codegen/hooks-ast.d.ts +75 -0
- package/esm/core/codegen/hooks-ast.js +424 -0
- package/esm/core/codegen/index.d.ts +16 -18
- package/esm/core/codegen/index.js +26 -71
- package/esm/core/codegen/invalidation.d.ts +1 -7
- package/esm/core/codegen/invalidation.js +51 -17
- package/esm/core/codegen/mutation-keys.d.ts +1 -10
- package/esm/core/codegen/mutation-keys.js +23 -9
- package/esm/core/codegen/mutations.d.ts +0 -13
- package/esm/core/codegen/mutations.js +302 -367
- package/esm/core/codegen/orm/barrel.d.ts +0 -5
- package/esm/core/codegen/orm/barrel.js +6 -1
- package/esm/core/codegen/orm/client-generator.d.ts +0 -5
- package/esm/core/codegen/orm/client-generator.js +7 -2
- package/esm/core/codegen/orm/client.js +3 -1
- package/esm/core/codegen/orm/custom-ops-generator.d.ts +0 -6
- package/esm/core/codegen/orm/custom-ops-generator.js +103 -50
- package/esm/core/codegen/orm/index.d.ts +4 -4
- package/esm/core/codegen/orm/index.js +25 -12
- package/esm/core/codegen/orm/input-types-generator.d.ts +1 -13
- package/esm/core/codegen/orm/input-types-generator.js +85 -23
- package/esm/core/codegen/orm/model-generator.d.ts +0 -5
- package/esm/core/codegen/orm/model-generator.js +310 -132
- package/esm/core/codegen/orm/select-types.d.ts +19 -14
- package/esm/core/codegen/queries.d.ts +0 -8
- package/esm/core/codegen/queries.js +362 -561
- package/esm/core/codegen/query-keys.d.ts +1 -1
- package/esm/core/codegen/query-keys.js +38 -24
- package/esm/core/codegen/scalars.js +3 -1
- package/esm/core/codegen/schema-types-generator.d.ts +1 -1
- package/esm/core/codegen/schema-types-generator.js +17 -2
- package/esm/core/codegen/select-helpers.d.ts +19 -0
- package/esm/core/codegen/select-helpers.js +35 -0
- package/esm/core/codegen/selection.d.ts +4 -0
- package/esm/core/codegen/selection.js +29 -0
- package/esm/core/codegen/shared/index.d.ts +2 -15
- package/esm/core/codegen/shared/index.js +16 -3
- package/esm/core/codegen/type-resolver.d.ts +1 -5
- package/esm/core/codegen/type-resolver.js +1 -22
- package/esm/core/codegen/types.d.ts +0 -3
- package/esm/core/codegen/types.js +72 -15
- package/esm/core/codegen/utils.d.ts +1 -4
- package/esm/core/codegen/utils.js +4 -1
- package/esm/core/config/index.d.ts +1 -1
- package/esm/core/config/resolver.js +2 -4
- package/esm/core/generate.js +38 -50
- package/esm/core/index.d.ts +3 -3
- package/esm/core/index.js +2 -3
- package/esm/core/introspect/index.d.ts +6 -6
- package/esm/core/introspect/index.js +3 -6
- package/esm/core/introspect/infer-tables.d.ts +0 -14
- package/esm/core/introspect/infer-tables.js +16 -2
- package/esm/core/introspect/source/database.js +2 -2
- package/esm/core/introspect/source/endpoint.d.ts +0 -6
- package/esm/core/introspect/source/endpoint.js +7 -1
- package/esm/core/introspect/source/index.d.ts +4 -4
- package/esm/core/introspect/source/index.js +6 -10
- package/esm/core/introspect/source/pgpm-module.js +3 -3
- package/esm/core/introspect/transform-schema.d.ts +2 -2
- package/esm/core/introspect/transform-schema.js +2 -2
- package/esm/core/output/index.d.ts +1 -1
- package/esm/core/output/index.js +1 -1
- package/esm/core/output/writer.d.ts +3 -0
- package/esm/core/output/writer.js +20 -1
- package/esm/core/pipeline/index.d.ts +2 -2
- package/esm/core/pipeline/index.js +2 -2
- package/esm/core/query-builder.d.ts +2 -2
- package/esm/core/query-builder.js +2 -2
- package/esm/core/watch/index.d.ts +4 -4
- package/esm/core/watch/index.js +3 -3
- package/esm/core/watch/orchestrator.js +5 -3
- package/esm/generators/index.d.ts +3 -3
- package/esm/generators/index.js +3 -3
- package/esm/generators/mutations.d.ts +1 -1
- package/esm/generators/select.d.ts +1 -1
- package/esm/index.d.ts +3 -3
- package/esm/index.js +1 -4
- package/esm/types/config.d.ts +0 -10
- package/esm/types/config.js +0 -2
- package/esm/types/index.d.ts +6 -6
- package/esm/types/index.js +1 -1
- package/generators/index.d.ts +3 -3
- package/generators/index.js +8 -8
- package/generators/mutations.d.ts +1 -1
- package/generators/select.d.ts +1 -1
- package/index.d.ts +3 -3
- package/index.js +11 -5
- package/package.json +11 -11
- package/types/config.d.ts +0 -10
- package/types/config.js +0 -2
- package/types/index.d.ts +6 -6
- package/types/index.js +2 -2
- package/core/codegen/gql-ast.d.ts +0 -41
- package/core/codegen/gql-ast.js +0 -353
- package/core/codegen/schema-gql-ast.d.ts +0 -51
- package/core/codegen/schema-gql-ast.js +0 -385
- package/core/codegen/templates/client.browser.ts +0 -271
- package/core/codegen/templates/client.node.ts +0 -337
- package/esm/core/codegen/gql-ast.d.ts +0 -41
- package/esm/core/codegen/gql-ast.js +0 -312
- package/esm/core/codegen/schema-gql-ast.d.ts +0 -51
- package/esm/core/codegen/schema-gql-ast.js +0 -343
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CleanTable, CleanOperation } from '../../types/schema';
|
|
2
1
|
import type { QueryKeyConfig } from '../../types/config';
|
|
2
|
+
import type { CleanOperation, CleanTable } from '../../types/schema';
|
|
3
3
|
export interface QueryKeyGeneratorOptions {
|
|
4
4
|
tables: CleanTable[];
|
|
5
5
|
customQueries: CleanOperation[];
|
|
@@ -45,8 +45,8 @@ exports.generateQueryKeysFile = generateQueryKeysFile;
|
|
|
45
45
|
* @see https://tanstack.com/query/docs/framework/react/community/lukemorales-query-key-factory
|
|
46
46
|
*/
|
|
47
47
|
const t = __importStar(require("@babel/types"));
|
|
48
|
-
const utils_1 = require("./utils");
|
|
49
48
|
const babel_ast_1 = require("./babel-ast");
|
|
49
|
+
const utils_1 = require("./utils");
|
|
50
50
|
/**
|
|
51
51
|
* Get all ancestor entities for a given entity based on relationships
|
|
52
52
|
*/
|
|
@@ -112,11 +112,13 @@ function buildByParentProperty(entityKey, typeName, parent, fkField) {
|
|
|
112
112
|
const arrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)(fkField, t.tsStringKeyword())], (0, babel_ast_1.constArray)([
|
|
113
113
|
t.stringLiteral(entityKey),
|
|
114
114
|
t.objectExpression([
|
|
115
|
-
t.objectProperty(t.identifier(fkField), t.identifier(fkField), false, true)
|
|
116
|
-
])
|
|
115
|
+
t.objectProperty(t.identifier(fkField), t.identifier(fkField), false, true),
|
|
116
|
+
]),
|
|
117
117
|
]));
|
|
118
118
|
const prop = t.objectProperty(t.identifier(`by${parentUpper}`), arrowFn);
|
|
119
|
-
(0, babel_ast_1.addJSDocComment)(prop, [
|
|
119
|
+
(0, babel_ast_1.addJSDocComment)(prop, [
|
|
120
|
+
`${typeName} queries scoped to a specific ${parentLower}`,
|
|
121
|
+
]);
|
|
120
122
|
return prop;
|
|
121
123
|
}
|
|
122
124
|
/**
|
|
@@ -128,14 +130,18 @@ function buildScopedProperty(keysName, typeName, relationship, ancestors) {
|
|
|
128
130
|
const statements = [];
|
|
129
131
|
if (relationship.parent) {
|
|
130
132
|
statements.push(t.ifStatement(t.optionalMemberExpression(t.identifier('scope'), t.identifier(relationship.foreignKey), false, true), t.blockStatement([
|
|
131
|
-
t.returnStatement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier(`by${(0, utils_1.ucFirst)(relationship.parent)}`)), [
|
|
133
|
+
t.returnStatement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier(`by${(0, utils_1.ucFirst)(relationship.parent)}`)), [
|
|
134
|
+
t.memberExpression(t.identifier('scope'), t.identifier(relationship.foreignKey)),
|
|
135
|
+
])),
|
|
132
136
|
])));
|
|
133
137
|
}
|
|
134
138
|
for (const ancestor of ancestors) {
|
|
135
139
|
const ancestorLower = (0, utils_1.lcFirst)(ancestor);
|
|
136
140
|
const fkField = `${ancestorLower}Id`;
|
|
137
141
|
statements.push(t.ifStatement(t.optionalMemberExpression(t.identifier('scope'), t.identifier(fkField), false, true), t.blockStatement([
|
|
138
|
-
t.returnStatement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier(`by${(0, utils_1.ucFirst)(ancestor)}`)), [
|
|
142
|
+
t.returnStatement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier(`by${(0, utils_1.ucFirst)(ancestor)}`)), [
|
|
143
|
+
t.memberExpression(t.identifier('scope'), t.identifier(fkField)),
|
|
144
|
+
])),
|
|
139
145
|
])));
|
|
140
146
|
}
|
|
141
147
|
statements.push(t.returnStatement(t.memberExpression(t.identifier(keysName), t.identifier('all'))));
|
|
@@ -151,7 +157,7 @@ function buildScopedListsProperty(keysName, scopeTypeName) {
|
|
|
151
157
|
const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
|
|
152
158
|
const arrowFn = t.arrowFunctionExpression([scopeParam], (0, babel_ast_1.constArray)([
|
|
153
159
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('scoped')), [t.identifier('scope')])),
|
|
154
|
-
t.stringLiteral('list')
|
|
160
|
+
t.stringLiteral('list'),
|
|
155
161
|
]));
|
|
156
162
|
const prop = t.objectProperty(t.identifier('lists'), arrowFn);
|
|
157
163
|
(0, babel_ast_1.addJSDocComment)(prop, ['List query keys (optionally scoped)']);
|
|
@@ -165,7 +171,7 @@ function buildScopedListProperty(keysName, scopeTypeName) {
|
|
|
165
171
|
const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
|
|
166
172
|
const arrowFn = t.arrowFunctionExpression([variablesParam, scopeParam], (0, babel_ast_1.constArray)([
|
|
167
173
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('lists')), [t.identifier('scope')])),
|
|
168
|
-
t.identifier('variables')
|
|
174
|
+
t.identifier('variables'),
|
|
169
175
|
]));
|
|
170
176
|
const prop = t.objectProperty(t.identifier('list'), arrowFn);
|
|
171
177
|
(0, babel_ast_1.addJSDocComment)(prop, ['List query key with variables']);
|
|
@@ -178,7 +184,7 @@ function buildScopedDetailsProperty(keysName, scopeTypeName) {
|
|
|
178
184
|
const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
|
|
179
185
|
const arrowFn = t.arrowFunctionExpression([scopeParam], (0, babel_ast_1.constArray)([
|
|
180
186
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('scoped')), [t.identifier('scope')])),
|
|
181
|
-
t.stringLiteral('detail')
|
|
187
|
+
t.stringLiteral('detail'),
|
|
182
188
|
]));
|
|
183
189
|
const prop = t.objectProperty(t.identifier('details'), arrowFn);
|
|
184
190
|
(0, babel_ast_1.addJSDocComment)(prop, ['Detail query keys (optionally scoped)']);
|
|
@@ -192,7 +198,7 @@ function buildScopedDetailProperty(keysName, scopeTypeName) {
|
|
|
192
198
|
const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
|
|
193
199
|
const arrowFn = t.arrowFunctionExpression([idParam, scopeParam], (0, babel_ast_1.constArray)([
|
|
194
200
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('details')), [t.identifier('scope')])),
|
|
195
|
-
t.identifier('id')
|
|
201
|
+
t.identifier('id'),
|
|
196
202
|
]));
|
|
197
203
|
const prop = t.objectProperty(t.identifier('detail'), arrowFn);
|
|
198
204
|
(0, babel_ast_1.addJSDocComment)(prop, ['Detail query key for specific item']);
|
|
@@ -204,7 +210,7 @@ function buildScopedDetailProperty(keysName, scopeTypeName) {
|
|
|
204
210
|
function buildSimpleListsProperty(keysName) {
|
|
205
211
|
const arrowFn = t.arrowFunctionExpression([], (0, babel_ast_1.constArray)([
|
|
206
212
|
t.spreadElement(t.memberExpression(t.identifier(keysName), t.identifier('all'))),
|
|
207
|
-
t.stringLiteral('list')
|
|
213
|
+
t.stringLiteral('list'),
|
|
208
214
|
]));
|
|
209
215
|
const prop = t.objectProperty(t.identifier('lists'), arrowFn);
|
|
210
216
|
(0, babel_ast_1.addJSDocComment)(prop, ['List query keys']);
|
|
@@ -217,7 +223,7 @@ function buildSimpleListProperty(keysName) {
|
|
|
217
223
|
const variablesParam = (0, babel_ast_1.typedParam)('variables', t.tsTypeReference(t.identifier('object')), true);
|
|
218
224
|
const arrowFn = t.arrowFunctionExpression([variablesParam], (0, babel_ast_1.constArray)([
|
|
219
225
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('lists')), [])),
|
|
220
|
-
t.identifier('variables')
|
|
226
|
+
t.identifier('variables'),
|
|
221
227
|
]));
|
|
222
228
|
const prop = t.objectProperty(t.identifier('list'), arrowFn);
|
|
223
229
|
(0, babel_ast_1.addJSDocComment)(prop, ['List query key with variables']);
|
|
@@ -229,7 +235,7 @@ function buildSimpleListProperty(keysName) {
|
|
|
229
235
|
function buildSimpleDetailsProperty(keysName) {
|
|
230
236
|
const arrowFn = t.arrowFunctionExpression([], (0, babel_ast_1.constArray)([
|
|
231
237
|
t.spreadElement(t.memberExpression(t.identifier(keysName), t.identifier('all'))),
|
|
232
|
-
t.stringLiteral('detail')
|
|
238
|
+
t.stringLiteral('detail'),
|
|
233
239
|
]));
|
|
234
240
|
const prop = t.objectProperty(t.identifier('details'), arrowFn);
|
|
235
241
|
(0, babel_ast_1.addJSDocComment)(prop, ['Detail query keys']);
|
|
@@ -242,7 +248,7 @@ function buildSimpleDetailProperty(keysName) {
|
|
|
242
248
|
const idParam = (0, babel_ast_1.typedParam)('id', t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()]));
|
|
243
249
|
const arrowFn = t.arrowFunctionExpression([idParam], (0, babel_ast_1.constArray)([
|
|
244
250
|
t.spreadElement(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('details')), [])),
|
|
245
|
-
t.identifier('id')
|
|
251
|
+
t.identifier('id'),
|
|
246
252
|
]));
|
|
247
253
|
const prop = t.objectProperty(t.identifier('detail'), arrowFn);
|
|
248
254
|
(0, babel_ast_1.addJSDocComment)(prop, ['Detail query key for specific item']);
|
|
@@ -283,7 +289,7 @@ function generateEntityKeysDeclaration(table, relationships, generateScopedKeys)
|
|
|
283
289
|
properties.push(buildSimpleDetailProperty(keysName));
|
|
284
290
|
}
|
|
285
291
|
return t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
286
|
-
t.variableDeclarator(t.identifier(keysName), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
|
|
292
|
+
t.variableDeclarator(t.identifier(keysName), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
|
|
287
293
|
]));
|
|
288
294
|
}
|
|
289
295
|
/**
|
|
@@ -310,7 +316,7 @@ function generateCustomQueryKeysDeclaration(operations) {
|
|
|
310
316
|
properties.push(prop);
|
|
311
317
|
}
|
|
312
318
|
return t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
313
|
-
t.variableDeclarator(t.identifier('customQueryKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
|
|
319
|
+
t.variableDeclarator(t.identifier('customQueryKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
|
|
314
320
|
]));
|
|
315
321
|
}
|
|
316
322
|
/**
|
|
@@ -327,7 +333,7 @@ function generateUnifiedStoreDeclaration(tables, hasCustomQueries) {
|
|
|
327
333
|
properties.push(t.objectProperty(t.identifier('custom'), t.identifier('customQueryKeys')));
|
|
328
334
|
}
|
|
329
335
|
const decl = t.exportNamedDeclaration(t.variableDeclaration('const', [
|
|
330
|
-
t.variableDeclarator(t.identifier('queryKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
|
|
336
|
+
t.variableDeclarator(t.identifier('queryKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
|
|
331
337
|
]));
|
|
332
338
|
(0, babel_ast_1.addJSDocComment)(decl, [
|
|
333
339
|
'Unified query key store',
|
|
@@ -384,7 +390,9 @@ function generateQueryKeysFile(options) {
|
|
|
384
390
|
statements.push(generateUnifiedStoreDeclaration(tables, queryOperations.length > 0));
|
|
385
391
|
// Generate QueryKeyScope type
|
|
386
392
|
const scopeTypeDecl = t.exportNamedDeclaration(t.tsTypeAliasDeclaration(t.identifier('QueryKeyScope'), null, (0, babel_ast_1.keyofTypeof)('queryKeys')));
|
|
387
|
-
(0, babel_ast_1.addJSDocComment)(scopeTypeDecl, [
|
|
393
|
+
(0, babel_ast_1.addJSDocComment)(scopeTypeDecl, [
|
|
394
|
+
'Type representing all available query key scopes',
|
|
395
|
+
]);
|
|
388
396
|
statements.push(scopeTypeDecl);
|
|
389
397
|
// Generate code from AST
|
|
390
398
|
const code = (0, babel_ast_1.generateCode)(statements);
|
|
@@ -407,7 +415,7 @@ ${description}
|
|
|
407
415
|
`;
|
|
408
416
|
// Add scope types section if present
|
|
409
417
|
if (generateScopedKeys && Object.keys(relationships).length > 0) {
|
|
410
|
-
const hasScopes = tables.some(table => {
|
|
418
|
+
const hasScopes = tables.some((table) => {
|
|
411
419
|
const { typeName } = (0, utils_1.getTableNames)(table);
|
|
412
420
|
return !!relationships[typeName.toLowerCase()];
|
|
413
421
|
});
|
|
@@ -428,7 +436,9 @@ ${description}
|
|
|
428
436
|
for (let i = 0; i < codeLines.length; i++) {
|
|
429
437
|
const line = codeLines[i];
|
|
430
438
|
// Detect transition from scope types to entity keys
|
|
431
|
-
if (inScopeTypes &&
|
|
439
|
+
if (inScopeTypes &&
|
|
440
|
+
line.startsWith('export const') &&
|
|
441
|
+
line.includes('Keys =')) {
|
|
432
442
|
content += `// ============================================================================
|
|
433
443
|
// Entity Query Keys
|
|
434
444
|
// ============================================================================
|
|
@@ -438,7 +448,8 @@ ${description}
|
|
|
438
448
|
addedEntitySection = true;
|
|
439
449
|
}
|
|
440
450
|
// Detect custom query keys section
|
|
441
|
-
if (!addedCustomSection &&
|
|
451
|
+
if (!addedCustomSection &&
|
|
452
|
+
line.startsWith('export const customQueryKeys')) {
|
|
442
453
|
content += `
|
|
443
454
|
// ============================================================================
|
|
444
455
|
// Custom Query Keys
|
|
@@ -463,11 +474,14 @@ ${description}
|
|
|
463
474
|
if (!addedEntitySection && !inScopeTypes) {
|
|
464
475
|
const firstExportIndex = content.indexOf('\nexport const');
|
|
465
476
|
if (firstExportIndex !== -1) {
|
|
466
|
-
content =
|
|
477
|
+
content =
|
|
478
|
+
content.slice(0, firstExportIndex) +
|
|
479
|
+
`
|
|
467
480
|
// ============================================================================
|
|
468
481
|
// Entity Query Keys
|
|
469
482
|
// ============================================================================
|
|
470
|
-
` +
|
|
483
|
+
` +
|
|
484
|
+
content.slice(firstExportIndex);
|
|
471
485
|
}
|
|
472
486
|
}
|
|
473
487
|
return {
|
package/core/codegen/scalars.js
CHANGED
|
@@ -68,7 +68,9 @@ exports.BASE_FILTER_TYPE_NAMES = new Set([
|
|
|
68
68
|
...Array.from(LIST_FILTER_SCALARS).map((s) => `${s}ListFilter`),
|
|
69
69
|
]);
|
|
70
70
|
function scalarToTsType(scalarName, options = {}) {
|
|
71
|
-
return options.overrides?.[scalarName] ??
|
|
71
|
+
return (options.overrides?.[scalarName] ??
|
|
72
|
+
exports.SCALAR_TS_MAP[scalarName] ??
|
|
73
|
+
(options.unknownScalar === 'unknown' ? 'unknown' : scalarName));
|
|
72
74
|
}
|
|
73
75
|
/** Get the filter type for a scalar (handles both scalar and array types) */
|
|
74
76
|
function scalarToFilterType(scalarName, isArray = false) {
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
*
|
|
12
12
|
* Uses Babel AST for robust code generation.
|
|
13
13
|
*/
|
|
14
|
-
import type { TypeRegistry } from '../../types/schema';
|
|
15
14
|
import * as t from '@babel/types';
|
|
15
|
+
import type { TypeRegistry } from '../../types/schema';
|
|
16
16
|
export interface GeneratedSchemaTypesFile {
|
|
17
17
|
fileName: string;
|
|
18
18
|
content: string;
|
|
@@ -34,10 +34,23 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generateSchemaTypesFile = generateSchemaTypesFile;
|
|
37
|
+
/**
|
|
38
|
+
* Schema types generator for React Query hooks (non-ORM mode)
|
|
39
|
+
*
|
|
40
|
+
* Generates TypeScript interfaces for:
|
|
41
|
+
* 1. INPUT_OBJECT types (e.g., BootstrapUserInput, LoginInput)
|
|
42
|
+
* 2. Payload OBJECT types (e.g., BootstrapUserPayload, LoginPayload)
|
|
43
|
+
* 3. ENUM types (e.g., FieldCategory, TableCategory)
|
|
44
|
+
*
|
|
45
|
+
* These types are referenced by custom mutation/query hooks but not generated
|
|
46
|
+
* elsewhere in non-ORM mode.
|
|
47
|
+
*
|
|
48
|
+
* Uses Babel AST for robust code generation.
|
|
49
|
+
*/
|
|
37
50
|
const t = __importStar(require("@babel/types"));
|
|
38
51
|
const babel_ast_1 = require("./babel-ast");
|
|
39
|
-
const type_resolver_1 = require("./type-resolver");
|
|
40
52
|
const scalars_1 = require("./scalars");
|
|
53
|
+
const type_resolver_1 = require("./type-resolver");
|
|
41
54
|
const utils_1 = require("./utils");
|
|
42
55
|
const SKIP_TYPES = new Set([
|
|
43
56
|
...scalars_1.SCALAR_NAMES,
|
|
@@ -267,7 +280,9 @@ function generateSchemaTypesFile(options) {
|
|
|
267
280
|
allStatements.push(...inputResult.statements);
|
|
268
281
|
allStatements.push(...payloadResult.statements);
|
|
269
282
|
const code = (0, babel_ast_1.generateCode)(allStatements);
|
|
270
|
-
const content = (0, utils_1.getGeneratedFileHeader)('GraphQL schema types for custom operations') +
|
|
283
|
+
const content = (0, utils_1.getGeneratedFileHeader)('GraphQL schema types for custom operations') +
|
|
284
|
+
'\n\n' +
|
|
285
|
+
code;
|
|
271
286
|
return {
|
|
272
287
|
fileName: 'schema-types.ts',
|
|
273
288
|
content,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for select type resolution in custom operations
|
|
3
|
+
*
|
|
4
|
+
* Used by custom-queries.ts, custom-mutations.ts, and orm/custom-ops-generator.ts
|
|
5
|
+
*/
|
|
6
|
+
import type { CleanArgument } from '../../types/schema';
|
|
7
|
+
/**
|
|
8
|
+
* Types that don't need Select types (scalars + root query/mutation types)
|
|
9
|
+
*/
|
|
10
|
+
export declare const NON_SELECT_TYPES: Set<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the Select type name for a return type.
|
|
13
|
+
* Returns null for scalar types, Connection types, and root types.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getSelectTypeName(returnType: CleanArgument['type']): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap a type reference in InferSelectResult, handling NON_NULL and LIST wrappers.
|
|
18
|
+
*/
|
|
19
|
+
export declare function wrapInferSelectResult(typeRef: CleanArgument['type'], payloadTypeName: string, selectType?: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NON_SELECT_TYPES = void 0;
|
|
4
|
+
exports.getSelectTypeName = getSelectTypeName;
|
|
5
|
+
exports.wrapInferSelectResult = wrapInferSelectResult;
|
|
6
|
+
const scalars_1 = require("./scalars");
|
|
7
|
+
const type_resolver_1 = require("./type-resolver");
|
|
8
|
+
/**
|
|
9
|
+
* Types that don't need Select types (scalars + root query/mutation types)
|
|
10
|
+
*/
|
|
11
|
+
exports.NON_SELECT_TYPES = new Set([
|
|
12
|
+
...scalars_1.SCALAR_NAMES,
|
|
13
|
+
'Query',
|
|
14
|
+
'Mutation',
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Get the Select type name for a return type.
|
|
18
|
+
* Returns null for scalar types, Connection types, and root types.
|
|
19
|
+
*/
|
|
20
|
+
function getSelectTypeName(returnType) {
|
|
21
|
+
const baseName = (0, type_resolver_1.getTypeBaseName)(returnType);
|
|
22
|
+
if (baseName &&
|
|
23
|
+
!exports.NON_SELECT_TYPES.has(baseName) &&
|
|
24
|
+
!baseName.endsWith('Connection')) {
|
|
25
|
+
return `${baseName}Select`;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Wrap a type reference in InferSelectResult, handling NON_NULL and LIST wrappers.
|
|
31
|
+
*/
|
|
32
|
+
function wrapInferSelectResult(typeRef, payloadTypeName, selectType = 'S') {
|
|
33
|
+
if (typeRef.kind === 'NON_NULL' && typeRef.ofType) {
|
|
34
|
+
return wrapInferSelectResult(typeRef.ofType, payloadTypeName, selectType);
|
|
35
|
+
}
|
|
36
|
+
if (typeRef.kind === 'LIST' && typeRef.ofType) {
|
|
37
|
+
return `${wrapInferSelectResult(typeRef.ofType, payloadTypeName, selectType)}[]`;
|
|
38
|
+
}
|
|
39
|
+
return `InferSelectResult<${payloadTypeName}, ${selectType}>`;
|
|
40
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateSelectionFile = generateSelectionFile;
|
|
37
|
+
/**
|
|
38
|
+
* Selection helper generator for React Query hooks
|
|
39
|
+
*
|
|
40
|
+
* Uses template-copy pattern: reads hooks-selection.ts from templates/
|
|
41
|
+
* and writes it to the output directory with a generated file header.
|
|
42
|
+
*/
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const utils_1 = require("./utils");
|
|
46
|
+
function findTemplateFile(templateName) {
|
|
47
|
+
const templatePath = path.join(__dirname, 'templates', templateName);
|
|
48
|
+
if (fs.existsSync(templatePath)) {
|
|
49
|
+
return templatePath;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`Could not find template file: ${templateName}. Searched in: ${templatePath}`);
|
|
52
|
+
}
|
|
53
|
+
function readTemplateFile(templateName, description) {
|
|
54
|
+
const templatePath = findTemplateFile(templateName);
|
|
55
|
+
let content = fs.readFileSync(templatePath, 'utf-8');
|
|
56
|
+
const headerPattern = /\/\*\*[\s\S]*?\* NOTE: This file is read at codegen time and written to output\.[\s\S]*?\*\/\n*/;
|
|
57
|
+
content = content.replace(headerPattern, (0, utils_1.getGeneratedFileHeader)(description) + '\n');
|
|
58
|
+
return content;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate selection.ts content - shared selection types + runtime mappers
|
|
62
|
+
*/
|
|
63
|
+
function generateSelectionFile() {
|
|
64
|
+
return readTemplateFile('hooks-selection.ts', 'Selection helpers for React Query hooks');
|
|
65
|
+
}
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared types generator
|
|
3
|
-
*
|
|
4
|
-
* Generates shared TypeScript types that can be imported by both
|
|
5
|
-
* React Query SDK and ORM client outputs.
|
|
6
|
-
*
|
|
7
|
-
* Output structure:
|
|
8
|
-
* shared/
|
|
9
|
-
* index.ts - Barrel export
|
|
10
|
-
* types.ts - Entity interfaces
|
|
11
|
-
* schema-types.ts - Enums, input types, payload types
|
|
12
|
-
* filters.ts - Filter types (StringFilter, IntFilter, etc.)
|
|
13
|
-
*/
|
|
14
|
-
import type { CleanTable, CleanOperation, TypeRegistry } from '../../../types/schema';
|
|
15
1
|
import type { GraphQLSDKConfigTarget } from '../../../types/config';
|
|
2
|
+
import type { CleanOperation, CleanTable, TypeRegistry } from '../../../types/schema';
|
|
16
3
|
export interface GeneratedFile {
|
|
17
4
|
path: string;
|
|
18
5
|
content: string;
|
|
@@ -35,5 +22,5 @@ export interface GenerateSharedResult {
|
|
|
35
22
|
* Generate shared types that can be imported by both React Query SDK and ORM client
|
|
36
23
|
*/
|
|
37
24
|
export declare function generateSharedTypes(options: GenerateSharedOptions): GenerateSharedResult;
|
|
38
|
-
export { generateTypesFile } from '../types';
|
|
39
25
|
export { generateSchemaTypesFile } from '../schema-types-generator';
|
|
26
|
+
export { generateTypesFile } from '../types';
|
|
@@ -33,12 +33,25 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
36
|
+
exports.generateTypesFile = exports.generateSchemaTypesFile = void 0;
|
|
37
37
|
exports.generateSharedTypes = generateSharedTypes;
|
|
38
|
+
/**
|
|
39
|
+
* Shared types generator
|
|
40
|
+
*
|
|
41
|
+
* Generates shared TypeScript types that can be imported by both
|
|
42
|
+
* React Query SDK and ORM client outputs.
|
|
43
|
+
*
|
|
44
|
+
* Output structure:
|
|
45
|
+
* shared/
|
|
46
|
+
* index.ts - Barrel export
|
|
47
|
+
* types.ts - Entity interfaces
|
|
48
|
+
* schema-types.ts - Enums, input types, payload types
|
|
49
|
+
* filters.ts - Filter types (StringFilter, IntFilter, etc.)
|
|
50
|
+
*/
|
|
38
51
|
const t = __importStar(require("@babel/types"));
|
|
39
52
|
const babel_ast_1 = require("../babel-ast");
|
|
40
|
-
const types_1 = require("../types");
|
|
41
53
|
const schema_types_generator_1 = require("../schema-types-generator");
|
|
54
|
+
const types_1 = require("../types");
|
|
42
55
|
const utils_1 = require("../utils");
|
|
43
56
|
/**
|
|
44
57
|
* Helper to create export * from './module' statement
|
|
@@ -112,7 +125,7 @@ function generateSharedBarrel(hasSchemaTypes) {
|
|
|
112
125
|
}
|
|
113
126
|
return (0, babel_ast_1.generateCode)(statements);
|
|
114
127
|
}
|
|
115
|
-
var types_2 = require("../types");
|
|
116
|
-
Object.defineProperty(exports, "generateTypesFile", { enumerable: true, get: function () { return types_2.generateTypesFile; } });
|
|
117
128
|
var schema_types_generator_2 = require("../schema-types-generator");
|
|
118
129
|
Object.defineProperty(exports, "generateSchemaTypesFile", { enumerable: true, get: function () { return schema_types_generator_2.generateSchemaTypesFile; } });
|
|
130
|
+
var types_2 = require("../types");
|
|
131
|
+
Object.defineProperty(exports, "generateTypesFile", { enumerable: true, get: function () { return types_2.generateTypesFile; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ORM client wrapper for React Query hooks
|
|
3
|
+
*
|
|
4
|
+
* This is the RUNTIME code that gets copied to generated output.
|
|
5
|
+
* Provides configure/getClient singleton for React Query hooks to access the ORM.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This file is read at codegen time and written to output.
|
|
8
|
+
* Any changes here will affect all generated hook clients.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { createClient } from '../orm';
|
|
12
|
+
import type { OrmClientConfig } from '../orm/client';
|
|
13
|
+
|
|
14
|
+
export type { OrmClientConfig } from '../orm/client';
|
|
15
|
+
export type { GraphQLAdapter, GraphQLError, QueryResult } from '../orm/client';
|
|
16
|
+
export { GraphQLRequestError } from '../orm/client';
|
|
17
|
+
|
|
18
|
+
type OrmClientInstance = ReturnType<typeof createClient>;
|
|
19
|
+
let client: OrmClientInstance | null = null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Configure the ORM client for React Query hooks
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { configure } from './generated/hooks';
|
|
27
|
+
*
|
|
28
|
+
* configure({
|
|
29
|
+
* endpoint: 'https://api.example.com/graphql',
|
|
30
|
+
* headers: { Authorization: 'Bearer <token>' },
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function configure(config: OrmClientConfig): void {
|
|
35
|
+
client = createClient(config);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get the configured ORM client instance
|
|
40
|
+
* @throws Error if configure() has not been called
|
|
41
|
+
*/
|
|
42
|
+
export function getClient(): OrmClientInstance {
|
|
43
|
+
if (!client) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
'ORM client not configured. Call configure() before using hooks.',
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return client;
|
|
49
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Selection helpers for React Query hooks
|
|
3
|
+
*
|
|
4
|
+
* This is the RUNTIME code that gets copied to generated output.
|
|
5
|
+
* Provides selection types and runtime mappers between hook-facing
|
|
6
|
+
* `selection` params and ORM-facing args (`select`, `where`, `orderBy`, etc.).
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This file is read at codegen time and written to output.
|
|
9
|
+
* Any changes here will affect all generated hook selection helpers.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export interface SelectionConfig<TFields> {
|
|
13
|
+
fields: TFields;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ListSelectionConfig<
|
|
17
|
+
TFields,
|
|
18
|
+
TWhere,
|
|
19
|
+
TOrderBy,
|
|
20
|
+
> extends SelectionConfig<TFields> {
|
|
21
|
+
where?: TWhere;
|
|
22
|
+
orderBy?: TOrderBy[];
|
|
23
|
+
first?: number;
|
|
24
|
+
last?: number;
|
|
25
|
+
after?: string;
|
|
26
|
+
before?: string;
|
|
27
|
+
offset?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function buildSelectionArgs<TFields>(
|
|
31
|
+
selection: SelectionConfig<TFields>,
|
|
32
|
+
): { select: TFields } {
|
|
33
|
+
return { select: selection.fields };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function buildListSelectionArgs<TFields, TWhere, TOrderBy>(
|
|
37
|
+
selection: ListSelectionConfig<TFields, TWhere, TOrderBy>,
|
|
38
|
+
): {
|
|
39
|
+
select: TFields;
|
|
40
|
+
where?: TWhere;
|
|
41
|
+
orderBy?: TOrderBy[];
|
|
42
|
+
first?: number;
|
|
43
|
+
last?: number;
|
|
44
|
+
after?: string;
|
|
45
|
+
before?: string;
|
|
46
|
+
offset?: number;
|
|
47
|
+
} {
|
|
48
|
+
return {
|
|
49
|
+
select: selection.fields,
|
|
50
|
+
where: selection.where,
|
|
51
|
+
orderBy: selection.orderBy,
|
|
52
|
+
first: selection.first,
|
|
53
|
+
last: selection.last,
|
|
54
|
+
after: selection.after,
|
|
55
|
+
before: selection.before,
|
|
56
|
+
offset: selection.offset,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -29,14 +29,14 @@ export class FetchAdapter implements GraphQLAdapter {
|
|
|
29
29
|
|
|
30
30
|
constructor(
|
|
31
31
|
private endpoint: string,
|
|
32
|
-
headers?: Record<string, string
|
|
32
|
+
headers?: Record<string, string>,
|
|
33
33
|
) {
|
|
34
34
|
this.headers = headers ?? {};
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async execute<T>(
|
|
38
38
|
document: string,
|
|
39
|
-
variables?: Record<string, unknown
|
|
39
|
+
variables?: Record<string, unknown>,
|
|
40
40
|
): Promise<QueryResult<T>> {
|
|
41
41
|
const response = await fetch(this.endpoint, {
|
|
42
42
|
method: 'POST',
|
|
@@ -55,7 +55,9 @@ export class FetchAdapter implements GraphQLAdapter {
|
|
|
55
55
|
return {
|
|
56
56
|
ok: false,
|
|
57
57
|
data: null,
|
|
58
|
-
errors: [
|
|
58
|
+
errors: [
|
|
59
|
+
{ message: `HTTP ${response.status}: ${response.statusText}` },
|
|
60
|
+
],
|
|
59
61
|
};
|
|
60
62
|
}
|
|
61
63
|
|
|
@@ -108,7 +110,7 @@ export interface OrmClientConfig {
|
|
|
108
110
|
export class GraphQLRequestError extends Error {
|
|
109
111
|
constructor(
|
|
110
112
|
public readonly errors: GraphQLError[],
|
|
111
|
-
public readonly data: unknown = null
|
|
113
|
+
public readonly data: unknown = null,
|
|
112
114
|
) {
|
|
113
115
|
const messages = errors.map((e) => e.message).join('; ');
|
|
114
116
|
super(`GraphQL Error: ${messages}`);
|
|
@@ -126,14 +128,14 @@ export class OrmClient {
|
|
|
126
128
|
this.adapter = new FetchAdapter(config.endpoint, config.headers);
|
|
127
129
|
} else {
|
|
128
130
|
throw new Error(
|
|
129
|
-
'OrmClientConfig requires either an endpoint or a custom adapter'
|
|
131
|
+
'OrmClientConfig requires either an endpoint or a custom adapter',
|
|
130
132
|
);
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
|
|
134
136
|
async execute<T>(
|
|
135
137
|
document: string,
|
|
136
|
-
variables?: Record<string, unknown
|
|
138
|
+
variables?: Record<string, unknown>,
|
|
137
139
|
): Promise<QueryResult<T>> {
|
|
138
140
|
return this.adapter.execute<T>(document, variables);
|
|
139
141
|
}
|