@soda-gql/core 0.1.0 → 0.2.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 +70 -135
- package/dist/adapter.cjs +35 -0
- package/dist/adapter.cjs.map +1 -0
- package/dist/adapter.d.cts +35 -0
- package/dist/adapter.d.cts.map +1 -0
- package/dist/adapter.d.ts +35 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +34 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index-B-erotAZ.d.cts +657 -0
- package/dist/index-B-erotAZ.d.cts.map +1 -0
- package/dist/index-Djr9A4KL.d.ts +657 -0
- package/dist/index-Djr9A4KL.d.ts.map +1 -0
- package/dist/index.cjs +430 -416
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +88 -3
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +88 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +399 -386
- package/dist/index.js.map +1 -1
- package/dist/runtime.cjs +85 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +40 -0
- package/dist/runtime.d.cts.map +1 -0
- package/dist/runtime.d.ts +40 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +82 -0
- package/dist/runtime.js.map +1 -0
- package/dist/schema-Bip7o0g3.cjs +128 -0
- package/dist/schema-Bip7o0g3.cjs.map +1 -0
- package/dist/{index-zGZ61WLt.d.cts → schema-BygZwEX8.d.ts} +246 -117
- package/dist/schema-BygZwEX8.d.ts.map +1 -0
- package/dist/schema-D9wIW5Dl.js +86 -0
- package/dist/schema-D9wIW5Dl.js.map +1 -0
- package/dist/{index-Db9ogofS.d.ts → schema-DRkKucYe.d.cts} +246 -117
- package/dist/schema-DRkKucYe.d.cts.map +1 -0
- package/dist/schema-builder-8zadflz-.d.cts +40 -0
- package/dist/schema-builder-8zadflz-.d.cts.map +1 -0
- package/dist/schema-builder-vwQtCGYI.d.ts +40 -0
- package/dist/schema-builder-vwQtCGYI.d.ts.map +1 -0
- package/package.json +34 -14
- package/dist/index-DYwkqPzd.d.ts +0 -1015
- package/dist/index-DYwkqPzd.d.ts.map +0 -1
- package/dist/index-Db9ogofS.d.ts.map +0 -1
- package/dist/index-Dth0NSJt.d.cts +0 -1015
- package/dist/index-Dth0NSJt.d.cts.map +0 -1
- package/dist/index-zGZ61WLt.d.cts.map +0 -1
- package/dist/merge-CeMx09is.js +0 -74
- package/dist/merge-CeMx09is.js.map +0 -1
- package/dist/merge-ZxKV1syS.cjs +0 -85
- package/dist/metadata/index.cjs +0 -62
- package/dist/metadata/index.d.cts +0 -71
- package/dist/metadata/index.d.cts.map +0 -1
- package/dist/metadata/index.d.ts +0 -71
- package/dist/metadata/index.d.ts.map +0 -1
- package/dist/metadata/index.js +0 -59
- package/dist/metadata/index.js.map +0 -1
- package/dist/runtime/index.cjs +0 -107
- package/dist/runtime/index.d.cts +0 -72
- package/dist/runtime/index.d.cts.map +0 -1
- package/dist/runtime/index.d.ts +0 -72
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js +0 -104
- package/dist/runtime/index.js.map +0 -1
- package/dist/slice-BuSNc8vw.js +0 -278
- package/dist/slice-BuSNc8vw.js.map +0 -1
- package/dist/slice-C-FIQK-f.cjs +0 -373
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,59 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_merge = require('./merge-ZxKV1syS.cjs');
|
|
1
|
+
const require_schema = require('./schema-Bip7o0g3.cjs');
|
|
3
2
|
let graphql = require("graphql");
|
|
4
3
|
|
|
4
|
+
//#region packages/core/src/types/type-foundation/var-ref.ts
|
|
5
|
+
var VarRef = class {
|
|
6
|
+
constructor(inner) {
|
|
7
|
+
this.inner = inner;
|
|
8
|
+
}
|
|
9
|
+
static getInner(varRef) {
|
|
10
|
+
return varRef.inner;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const isVarRef = (value) => {
|
|
14
|
+
return typeof value === "object" && value !== null && value instanceof VarRef;
|
|
15
|
+
};
|
|
16
|
+
const createVarRefFromVariable = (name) => {
|
|
17
|
+
return new VarRef({
|
|
18
|
+
type: "variable",
|
|
19
|
+
name
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const createVarRefFromConstValue = (value) => {
|
|
23
|
+
return new VarRef({
|
|
24
|
+
type: "const-value",
|
|
25
|
+
value
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
const getVarRefInner = (varRef) => {
|
|
29
|
+
return VarRef.getInner(varRef);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Get the variable name from a VarRef.
|
|
33
|
+
* Throws if the VarRef contains a const-value instead of a variable reference.
|
|
34
|
+
*/
|
|
35
|
+
const getVarRefName = (varRef) => {
|
|
36
|
+
const inner = VarRef.getInner(varRef);
|
|
37
|
+
if (inner.type !== "variable") throw new Error("Expected variable reference, got const-value");
|
|
38
|
+
return inner.name;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Get the const value from a VarRef.
|
|
42
|
+
* Throws if the VarRef contains a variable reference instead of a const-value.
|
|
43
|
+
*/
|
|
44
|
+
const getVarRefValue = (varRef) => {
|
|
45
|
+
const inner = VarRef.getInner(varRef);
|
|
46
|
+
if (inner.type !== "const-value") throw new Error("Expected const-value, got variable reference");
|
|
47
|
+
return inner.value;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
5
51
|
//#region packages/core/src/composer/build-document.ts
|
|
6
52
|
const buildArgumentValue = (value) => {
|
|
7
53
|
if (value === void 0) return null;
|
|
8
54
|
if (value === null) return { kind: graphql.Kind.NULL };
|
|
9
|
-
if (value instanceof
|
|
10
|
-
const inner =
|
|
55
|
+
if (value instanceof VarRef) {
|
|
56
|
+
const inner = VarRef.getInner(value);
|
|
11
57
|
if (inner.type === "variable") return {
|
|
12
58
|
kind: graphql.Kind.VARIABLE,
|
|
13
59
|
name: {
|
|
@@ -236,6 +282,161 @@ const buildDocument = (options) => {
|
|
|
236
282
|
};
|
|
237
283
|
};
|
|
238
284
|
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region packages/core/src/composer/colocate.ts
|
|
287
|
+
/**
|
|
288
|
+
* Creates a $colocate helper function for fragment colocation.
|
|
289
|
+
*
|
|
290
|
+
* $colocate takes an object of { label: fields } and applies prefix-based
|
|
291
|
+
* aliasing to each entry. This mirrors the structure of createExecutionResultParser
|
|
292
|
+
* from @soda-gql/colocation-tools.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* ```typescript
|
|
296
|
+
* // In operation definition
|
|
297
|
+
* query.operation({ name: "GetData" }, ({ f, $ }) => [
|
|
298
|
+
* $colocate({
|
|
299
|
+
* userCard: userCardFragment.embed({ userId: $.userId }),
|
|
300
|
+
* posts: postsFragment.embed({ userId: $.userId }),
|
|
301
|
+
* }),
|
|
302
|
+
* ]);
|
|
303
|
+
*
|
|
304
|
+
* // In parser definition (same labels)
|
|
305
|
+
* createExecutionResultParser({
|
|
306
|
+
* userCard: userCardProjection,
|
|
307
|
+
* posts: postsProjection,
|
|
308
|
+
* });
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
const createColocateHelper = () => {
|
|
312
|
+
/**
|
|
313
|
+
* Colocate multiple field selections with labeled prefixes.
|
|
314
|
+
*
|
|
315
|
+
* @param entries - Object mapping labels to field selections
|
|
316
|
+
* @returns Merged object of all prefixed field entries
|
|
317
|
+
*/
|
|
318
|
+
const $colocate = (entries) => Object.fromEntries(Object.entries(entries).flatMap(([label, fields]) => Object.entries(fields).map(([key, value]) => [`${label}_${key}`, value])));
|
|
319
|
+
return $colocate;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region packages/core/src/composer/field-path-context.ts
|
|
324
|
+
/**
|
|
325
|
+
* Shared mutable container for field path context.
|
|
326
|
+
* Only synchronous access is supported.
|
|
327
|
+
*/
|
|
328
|
+
const fieldPathContext = { current: null };
|
|
329
|
+
/**
|
|
330
|
+
* Get the current field path.
|
|
331
|
+
* Returns null if not in a field building context.
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* ```typescript
|
|
335
|
+
* import { getCurrentFieldPath } from '@soda-gql/core';
|
|
336
|
+
*
|
|
337
|
+
* // Inside a field builder or model embed:
|
|
338
|
+
* const path = getCurrentFieldPath();
|
|
339
|
+
* console.log(path?.full); // "$.user.posts[].author"
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
const getCurrentFieldPath = () => fieldPathContext.current;
|
|
343
|
+
/**
|
|
344
|
+
* Run a function with a specific field path context.
|
|
345
|
+
* Restores the previous path after the function completes.
|
|
346
|
+
*
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
const withFieldPath = (path, fn) => {
|
|
350
|
+
const previousPath = fieldPathContext.current;
|
|
351
|
+
fieldPathContext.current = path;
|
|
352
|
+
try {
|
|
353
|
+
return fn();
|
|
354
|
+
} finally {
|
|
355
|
+
fieldPathContext.current = previousPath;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Append a new segment to the current path.
|
|
360
|
+
*
|
|
361
|
+
* @internal
|
|
362
|
+
*/
|
|
363
|
+
const appendToPath = (parent, segment) => {
|
|
364
|
+
const listSuffix = segment.isList ? "[]" : "";
|
|
365
|
+
const newSegment = {
|
|
366
|
+
field: segment.field,
|
|
367
|
+
parent: segment.parentType,
|
|
368
|
+
isList: segment.isList
|
|
369
|
+
};
|
|
370
|
+
if (!parent) return {
|
|
371
|
+
full: `$.${segment.field}${listSuffix}`,
|
|
372
|
+
segments: [newSegment]
|
|
373
|
+
};
|
|
374
|
+
return {
|
|
375
|
+
full: `${parent.full}.${segment.field}${listSuffix}`,
|
|
376
|
+
segments: [...parent.segments, newSegment]
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
/**
|
|
380
|
+
* Check if a type specifier represents a list type.
|
|
381
|
+
* Matches patterns like "Type:![]!", "Type:![]?", "Type:?[]!", etc.
|
|
382
|
+
*
|
|
383
|
+
* @internal
|
|
384
|
+
*/
|
|
385
|
+
const isListType = (typeString) => {
|
|
386
|
+
return typeString.includes("[]");
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region packages/core/src/types/element/fields-builder.ts
|
|
391
|
+
const mergeFields = (fields) => Object.assign({}, ...fields);
|
|
392
|
+
|
|
393
|
+
//#endregion
|
|
394
|
+
//#region packages/core/src/types/element/lazy-evaluator.ts
|
|
395
|
+
/**
|
|
396
|
+
* Creates a lazy evaluator with caching, async support, and dependency ordering.
|
|
397
|
+
*
|
|
398
|
+
* @param define - Factory function that produces the value
|
|
399
|
+
* @param getDeps - Optional function returning dependencies to evaluate first
|
|
400
|
+
* @param createDepGenerator - Function to create evaluation generator for a dependency
|
|
401
|
+
* @returns An executor generator function
|
|
402
|
+
*/
|
|
403
|
+
const createLazyEvaluator = (define$1, getDeps, createDepGenerator) => {
|
|
404
|
+
let cache = null;
|
|
405
|
+
let promise = null;
|
|
406
|
+
return function* execute(context) {
|
|
407
|
+
if (cache) return cache.value;
|
|
408
|
+
if (promise) {
|
|
409
|
+
yield promise;
|
|
410
|
+
return cache.value;
|
|
411
|
+
}
|
|
412
|
+
if (getDeps) for (const dep of getDeps()) yield* createDepGenerator(dep);
|
|
413
|
+
const defined = define$1(context);
|
|
414
|
+
if (!(defined instanceof Promise)) return (cache = { value: defined }).value;
|
|
415
|
+
promise = defined.then((value) => {
|
|
416
|
+
cache = { value };
|
|
417
|
+
promise = null;
|
|
418
|
+
});
|
|
419
|
+
yield promise;
|
|
420
|
+
return cache.value;
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
/**
|
|
424
|
+
* Creates an evaluation generator from an executor.
|
|
425
|
+
* Wraps the executor's generator and discards its return value.
|
|
426
|
+
*/
|
|
427
|
+
function* createEvaluationGenerator(executor, context) {
|
|
428
|
+
yield* executor(context);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Executes the evaluator synchronously.
|
|
432
|
+
* Throws if async operation is encountered.
|
|
433
|
+
*/
|
|
434
|
+
const evaluateSync = (executor, context) => {
|
|
435
|
+
const result = executor(context).next();
|
|
436
|
+
if (!result.done) throw new Error("Async operation is not supported in sync evaluation.");
|
|
437
|
+
return result.value;
|
|
438
|
+
};
|
|
439
|
+
|
|
239
440
|
//#endregion
|
|
240
441
|
//#region packages/core/src/types/element/gql-element.ts
|
|
241
442
|
const GQL_ELEMENT_FACTORY = Symbol("GQL_ELEMENT_FACTORY");
|
|
@@ -244,40 +445,28 @@ var GqlElement = class GqlElement {
|
|
|
244
445
|
[GQL_ELEMENT_FACTORY];
|
|
245
446
|
[GQL_ELEMENT_CONTEXT] = null;
|
|
246
447
|
constructor(define$1, getDeps) {
|
|
247
|
-
|
|
248
|
-
let promise = null;
|
|
249
|
-
this[GQL_ELEMENT_FACTORY] = function* execute(context) {
|
|
250
|
-
if (cache) return cache.value;
|
|
251
|
-
if (promise) {
|
|
252
|
-
yield promise;
|
|
253
|
-
return cache.value;
|
|
254
|
-
}
|
|
255
|
-
if (getDeps) for (const dep of getDeps()) yield* GqlElement.createEvaluationGenerator(dep);
|
|
256
|
-
const defined = define$1(context);
|
|
257
|
-
if (!(defined instanceof Promise)) return (cache = { value: defined }).value;
|
|
258
|
-
promise = defined.then((value) => {
|
|
259
|
-
cache = { value };
|
|
260
|
-
promise = null;
|
|
261
|
-
});
|
|
262
|
-
yield promise;
|
|
263
|
-
return cache.value;
|
|
264
|
-
};
|
|
448
|
+
this[GQL_ELEMENT_FACTORY] = createLazyEvaluator(define$1, getDeps, GqlElement.createEvaluationGenerator);
|
|
265
449
|
Object.defineProperty(this, "$infer", { get() {
|
|
266
450
|
throw new Error("This property is only for type meta. Do not access this property directly.");
|
|
267
451
|
} });
|
|
268
452
|
}
|
|
453
|
+
attach(attachment) {
|
|
454
|
+
let cache = null;
|
|
455
|
+
Object.defineProperty(this, attachment.name, { get() {
|
|
456
|
+
if (cache) return cache;
|
|
457
|
+
GqlElement.evaluateInstantly(this);
|
|
458
|
+
return cache = attachment.createValue(this);
|
|
459
|
+
} });
|
|
460
|
+
return this;
|
|
461
|
+
}
|
|
269
462
|
static setContext(element, context) {
|
|
270
463
|
element[GQL_ELEMENT_CONTEXT] = context;
|
|
271
464
|
}
|
|
272
|
-
static
|
|
273
|
-
|
|
274
|
-
yield* element[GQL_ELEMENT_FACTORY](context);
|
|
465
|
+
static createEvaluationGenerator(element) {
|
|
466
|
+
return createEvaluationGenerator(element[GQL_ELEMENT_FACTORY], element[GQL_ELEMENT_CONTEXT]);
|
|
275
467
|
}
|
|
276
468
|
static evaluateInstantly(element) {
|
|
277
|
-
|
|
278
|
-
const result = element[GQL_ELEMENT_FACTORY](context).next();
|
|
279
|
-
if (!result.done) throw new Error("Async operation is not supported in sync evaluation.");
|
|
280
|
-
return result.value;
|
|
469
|
+
return evaluateSync(element[GQL_ELEMENT_FACTORY], element[GQL_ELEMENT_CONTEXT]);
|
|
281
470
|
}
|
|
282
471
|
static evaluateSync(element) {
|
|
283
472
|
GqlElement.evaluateInstantly(element);
|
|
@@ -288,44 +477,25 @@ var GqlElement = class GqlElement {
|
|
|
288
477
|
};
|
|
289
478
|
|
|
290
479
|
//#endregion
|
|
291
|
-
//#region packages/core/src/types/element/
|
|
292
|
-
var
|
|
480
|
+
//#region packages/core/src/types/element/fragment.ts
|
|
481
|
+
var Fragment = class Fragment extends GqlElement {
|
|
293
482
|
constructor(define$1) {
|
|
294
483
|
super(define$1);
|
|
295
484
|
}
|
|
296
|
-
get
|
|
297
|
-
return GqlElement.get(this).
|
|
298
|
-
}
|
|
299
|
-
get operationName() {
|
|
300
|
-
return GqlElement.get(this).operationName;
|
|
301
|
-
}
|
|
302
|
-
get variableNames() {
|
|
303
|
-
return GqlElement.get(this).variableNames;
|
|
304
|
-
}
|
|
305
|
-
get projectionPathGraph() {
|
|
306
|
-
return GqlElement.get(this).projectionPathGraph;
|
|
307
|
-
}
|
|
308
|
-
get document() {
|
|
309
|
-
return GqlElement.get(this).document;
|
|
310
|
-
}
|
|
311
|
-
get parse() {
|
|
312
|
-
return GqlElement.get(this).parse;
|
|
485
|
+
get typename() {
|
|
486
|
+
return GqlElement.get(this).typename;
|
|
313
487
|
}
|
|
314
|
-
get
|
|
315
|
-
return GqlElement.get(this).
|
|
488
|
+
get embed() {
|
|
489
|
+
return GqlElement.get(this).embed;
|
|
316
490
|
}
|
|
317
491
|
static create(define$1) {
|
|
318
|
-
return new
|
|
492
|
+
return new Fragment(define$1);
|
|
319
493
|
}
|
|
320
494
|
};
|
|
321
495
|
|
|
322
496
|
//#endregion
|
|
323
|
-
//#region packages/core/src/types/element/
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
//#endregion
|
|
327
|
-
//#region packages/core/src/types/element/inline-operation.ts
|
|
328
|
-
var InlineOperation = class InlineOperation extends GqlElement {
|
|
497
|
+
//#region packages/core/src/types/element/operation.ts
|
|
498
|
+
var Operation = class Operation extends GqlElement {
|
|
329
499
|
constructor(define$1) {
|
|
330
500
|
super(define$1);
|
|
331
501
|
}
|
|
@@ -348,131 +518,14 @@ var InlineOperation = class InlineOperation extends GqlElement {
|
|
|
348
518
|
return GqlElement.get(this).metadata;
|
|
349
519
|
}
|
|
350
520
|
static create(define$1) {
|
|
351
|
-
return new
|
|
521
|
+
return new Operation(define$1);
|
|
352
522
|
}
|
|
353
523
|
};
|
|
354
524
|
|
|
355
525
|
//#endregion
|
|
356
|
-
//#region packages/core/src/
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
super(define$1);
|
|
360
|
-
}
|
|
361
|
-
get typename() {
|
|
362
|
-
return GqlElement.get(this).typename;
|
|
363
|
-
}
|
|
364
|
-
get fragment() {
|
|
365
|
-
return GqlElement.get(this).fragment;
|
|
366
|
-
}
|
|
367
|
-
get normalize() {
|
|
368
|
-
return GqlElement.get(this).normalize;
|
|
369
|
-
}
|
|
370
|
-
static create(define$1) {
|
|
371
|
-
return new Model(define$1);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region packages/core/src/types/element/slice.ts
|
|
377
|
-
var Slice = class Slice extends GqlElement {
|
|
378
|
-
constructor(define$1) {
|
|
379
|
-
super(define$1);
|
|
380
|
-
}
|
|
381
|
-
get operationType() {
|
|
382
|
-
return GqlElement.get(this).operationType;
|
|
383
|
-
}
|
|
384
|
-
get embed() {
|
|
385
|
-
return GqlElement.get(this).embed;
|
|
386
|
-
}
|
|
387
|
-
static create(define$1) {
|
|
388
|
-
return new Slice(define$1);
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
//#endregion
|
|
393
|
-
//#region packages/core/src/composer/projection-path-graph.ts
|
|
394
|
-
function createPathGraph(paths) {
|
|
395
|
-
const intermediate = paths.reduce((acc, { label, raw, segments: [segment, ...segments] }) => {
|
|
396
|
-
if (segment) (acc[segment] || (acc[segment] = [])).push({
|
|
397
|
-
label,
|
|
398
|
-
raw,
|
|
399
|
-
segments
|
|
400
|
-
});
|
|
401
|
-
return acc;
|
|
402
|
-
}, {});
|
|
403
|
-
return {
|
|
404
|
-
matches: paths.map(({ label, raw, segments }) => ({
|
|
405
|
-
label,
|
|
406
|
-
path: raw,
|
|
407
|
-
exact: segments.length === 0
|
|
408
|
-
})),
|
|
409
|
-
children: require_slice.mapValues(intermediate, (paths$1) => createPathGraph(paths$1))
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
function createPathGraphFromSliceEntries(fragments) {
|
|
413
|
-
return createPathGraph(Object.entries(fragments).flatMap(([label, slice]) => Array.from(new Map(slice.projection.paths.map(({ full: raw, segments }) => {
|
|
414
|
-
const [first, ...rest] = segments;
|
|
415
|
-
return [raw, {
|
|
416
|
-
label,
|
|
417
|
-
raw,
|
|
418
|
-
segments: [`${label}_${first}`, ...rest]
|
|
419
|
-
}];
|
|
420
|
-
})).values())));
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
//#endregion
|
|
424
|
-
//#region packages/core/src/composer/composed-operation.ts
|
|
425
|
-
const createComposedOperationComposerFactory = (options = {}) => {
|
|
426
|
-
const { metadataAdapter } = options;
|
|
427
|
-
return (operationType) => {
|
|
428
|
-
return (options$1, builder) => {
|
|
429
|
-
return ComposedOperation.create(() => {
|
|
430
|
-
const { operationName } = options$1;
|
|
431
|
-
const variables = require_slice.mergeVarDefinitions(options$1.variables ?? []);
|
|
432
|
-
const $ = require_slice.createVarRefs(variables);
|
|
433
|
-
const fragments = builder({ $ });
|
|
434
|
-
const fields = Object.fromEntries(Object.entries(fragments).flatMap(([label, { getFields: fields$1 }]) => Object.entries(fields$1).map(([key, reference]) => [`${label}_${key}`, reference])));
|
|
435
|
-
const projectionPathGraph = createPathGraphFromSliceEntries(fragments);
|
|
436
|
-
const document = buildDocument({
|
|
437
|
-
operationName,
|
|
438
|
-
operationType,
|
|
439
|
-
variables,
|
|
440
|
-
fields
|
|
441
|
-
});
|
|
442
|
-
const operationMetadataResult = options$1.metadata?.({
|
|
443
|
-
$,
|
|
444
|
-
document
|
|
445
|
-
});
|
|
446
|
-
const sliceMetadataResults = Object.values(fragments).map((fragment) => fragment.metadata).filter((m) => m != null);
|
|
447
|
-
const mergeSliceMetadata = metadataAdapter?.mergeSliceMetadata ?? require_merge.defaultMergeSliceMetadata;
|
|
448
|
-
const createDefinition = (operationMetadata, sliceMetadataList) => {
|
|
449
|
-
const metadata = mergeSliceMetadata(operationMetadata ?? {}, sliceMetadataList);
|
|
450
|
-
return {
|
|
451
|
-
operationType,
|
|
452
|
-
operationName,
|
|
453
|
-
variableNames: Object.keys(variables),
|
|
454
|
-
projectionPathGraph,
|
|
455
|
-
document,
|
|
456
|
-
parse: require_slice.createExecutionResultParser({
|
|
457
|
-
fragments,
|
|
458
|
-
projectionPathGraph
|
|
459
|
-
}),
|
|
460
|
-
metadata: Object.keys(metadata).length > 0 ? metadata : void 0
|
|
461
|
-
};
|
|
462
|
-
};
|
|
463
|
-
const hasAsyncOperationMetadata = operationMetadataResult instanceof Promise;
|
|
464
|
-
const hasAsyncSliceMetadata = sliceMetadataResults.some((m) => m instanceof Promise);
|
|
465
|
-
if (hasAsyncOperationMetadata || hasAsyncSliceMetadata) return Promise.all([hasAsyncOperationMetadata ? operationMetadataResult : Promise.resolve(operationMetadataResult), Promise.all(sliceMetadataResults.map((m) => m instanceof Promise ? m : Promise.resolve(m)))]).then(([operationMetadata, sliceMetadataList]) => createDefinition(operationMetadata, sliceMetadataList));
|
|
466
|
-
return createDefinition(operationMetadataResult, sliceMetadataResults);
|
|
467
|
-
});
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
//#endregion
|
|
473
|
-
//#region packages/core/src/utils/wrap-by-key.ts
|
|
474
|
-
function wrapByKey(name, value) {
|
|
475
|
-
return { [name]: value };
|
|
526
|
+
//#region packages/core/src/utils/map-values.ts
|
|
527
|
+
function mapValues(obj, fn) {
|
|
528
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value, key)]));
|
|
476
529
|
}
|
|
477
530
|
|
|
478
531
|
//#endregion
|
|
@@ -498,32 +551,46 @@ const createFieldFactoriesInner = (schema, typeName) => {
|
|
|
498
551
|
if (!typeDef) throw new Error(`Type ${typeName} is not defined in schema objects`);
|
|
499
552
|
const entries = Object.entries(typeDef.fields).map(([fieldName, type]) => {
|
|
500
553
|
const factory = (fieldArgs, extras) => {
|
|
501
|
-
const wrap = (value) => wrapByKey(extras?.alias ?? fieldName, value);
|
|
554
|
+
const wrap = (value) => require_schema.wrapByKey(extras?.alias ?? fieldName, value);
|
|
502
555
|
if (type.kind === "object") {
|
|
503
|
-
const factoryReturn = ((nest) =>
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
556
|
+
const factoryReturn = ((nest) => {
|
|
557
|
+
const nestedFields = withFieldPath(appendToPath(getCurrentFieldPath(), {
|
|
558
|
+
field: fieldName,
|
|
559
|
+
parentType: typeName,
|
|
560
|
+
isList: isListType(type.modifier)
|
|
561
|
+
}), () => mergeFields(nest({ f: createFieldFactories(schema, type.name) })));
|
|
562
|
+
return wrap({
|
|
563
|
+
parent: typeName,
|
|
564
|
+
field: fieldName,
|
|
565
|
+
type,
|
|
566
|
+
args: fieldArgs ?? {},
|
|
567
|
+
directives: extras?.directives ?? {},
|
|
568
|
+
object: nestedFields,
|
|
569
|
+
union: null
|
|
570
|
+
});
|
|
571
|
+
});
|
|
512
572
|
return factoryReturn;
|
|
513
573
|
}
|
|
514
574
|
if (type.kind === "union") {
|
|
515
|
-
const factoryReturn = ((nest) =>
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
object: null,
|
|
522
|
-
union: require_slice.mapValues(nest, (builder, memberName) => {
|
|
575
|
+
const factoryReturn = ((nest) => {
|
|
576
|
+
const nestedUnion = withFieldPath(appendToPath(getCurrentFieldPath(), {
|
|
577
|
+
field: fieldName,
|
|
578
|
+
parentType: typeName,
|
|
579
|
+
isList: isListType(type.modifier)
|
|
580
|
+
}), () => mapValues(nest, (builder, memberName) => {
|
|
523
581
|
if (!builder) throw new Error(`Builder is undefined for member name: ${memberName}`);
|
|
524
582
|
return mergeFields(builder({ f: createFieldFactories(schema, memberName) }));
|
|
525
|
-
})
|
|
526
|
-
|
|
583
|
+
}));
|
|
584
|
+
return wrap({
|
|
585
|
+
parent: typeName,
|
|
586
|
+
field: fieldName,
|
|
587
|
+
type,
|
|
588
|
+
args: fieldArgs ?? {},
|
|
589
|
+
directives: extras?.directives ?? {},
|
|
590
|
+
object: null,
|
|
591
|
+
union: nestedUnion
|
|
592
|
+
});
|
|
593
|
+
});
|
|
527
594
|
return factoryReturn;
|
|
528
595
|
}
|
|
529
596
|
if (type.kind === "scalar" || type.kind === "enum" || type.kind === "typename") return wrap({
|
|
@@ -543,30 +610,117 @@ const createFieldFactoriesInner = (schema, typeName) => {
|
|
|
543
610
|
};
|
|
544
611
|
|
|
545
612
|
//#endregion
|
|
546
|
-
//#region packages/core/src/composer/
|
|
547
|
-
|
|
613
|
+
//#region packages/core/src/composer/fragment-usage-context.ts
|
|
614
|
+
/**
|
|
615
|
+
* Shared mutable container for collecting fragment usages.
|
|
616
|
+
* Only synchronous access is supported.
|
|
617
|
+
*/
|
|
618
|
+
const fragmentUsageContext = { current: null };
|
|
619
|
+
/**
|
|
620
|
+
* Run a function with fragment usage collection enabled.
|
|
621
|
+
* Returns both the function result and collected fragment usages.
|
|
622
|
+
*
|
|
623
|
+
* @internal
|
|
624
|
+
*/
|
|
625
|
+
const withFragmentUsageCollection = (fn) => {
|
|
626
|
+
const previousCollector = fragmentUsageContext.current;
|
|
627
|
+
const usages = [];
|
|
628
|
+
fragmentUsageContext.current = usages;
|
|
629
|
+
try {
|
|
630
|
+
return {
|
|
631
|
+
result: fn(),
|
|
632
|
+
usages
|
|
633
|
+
};
|
|
634
|
+
} finally {
|
|
635
|
+
fragmentUsageContext.current = previousCollector;
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
/**
|
|
639
|
+
* Record a fragment usage. Called when fragment.embed() is invoked.
|
|
640
|
+
* No-op if not in a collection context.
|
|
641
|
+
*
|
|
642
|
+
* @internal
|
|
643
|
+
*/
|
|
644
|
+
const recordFragmentUsage = (record) => {
|
|
645
|
+
if (fragmentUsageContext.current) fragmentUsageContext.current.push(record);
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
//#endregion
|
|
649
|
+
//#region packages/core/src/composer/input.ts
|
|
650
|
+
const mergeVarDefinitions = (definitions) => Object.assign({}, ...definitions);
|
|
651
|
+
const createVarAssignments = (definitions, providedValues) => {
|
|
652
|
+
return mapValues(definitions, (_definition, key) => {
|
|
653
|
+
const varName = key;
|
|
654
|
+
if (!providedValues || providedValues[varName] === void 0) return createVarRefFromConstValue(void 0);
|
|
655
|
+
const provided = providedValues[varName];
|
|
656
|
+
if (isVarRef(provided)) return provided;
|
|
657
|
+
return createVarRefFromConstValue(provided);
|
|
658
|
+
});
|
|
659
|
+
};
|
|
660
|
+
const createVarRefs = (definitions) => mapValues(definitions, (_ref, name) => createVarRefFromVariable(name));
|
|
661
|
+
|
|
662
|
+
//#endregion
|
|
663
|
+
//#region packages/core/src/composer/fragment.ts
|
|
664
|
+
const createGqlFragmentComposers = (schema, _adapter) => {
|
|
665
|
+
const createFragmentComposer = (typename) => {
|
|
666
|
+
return (options, builder) => {
|
|
667
|
+
const varDefinitions = mergeVarDefinitions(options.variables ?? []);
|
|
668
|
+
const { metadata } = options;
|
|
669
|
+
return Fragment.create(() => ({
|
|
670
|
+
typename,
|
|
671
|
+
embed: (variables) => {
|
|
672
|
+
const f = createFieldFactories(schema, typename);
|
|
673
|
+
const $ = createVarAssignments(varDefinitions, variables);
|
|
674
|
+
recordFragmentUsage({
|
|
675
|
+
metadataBuilder: metadata ? () => metadata({ $ }) : null,
|
|
676
|
+
path: getCurrentFieldPath()
|
|
677
|
+
});
|
|
678
|
+
return mergeFields(builder({
|
|
679
|
+
f,
|
|
680
|
+
$
|
|
681
|
+
}));
|
|
682
|
+
}
|
|
683
|
+
}));
|
|
684
|
+
};
|
|
685
|
+
};
|
|
686
|
+
return mapValues(schema.object, (_, typename) => createFragmentComposer(typename));
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region packages/core/src/types/metadata/adapter.ts
|
|
691
|
+
/**
|
|
692
|
+
* Creates the default adapter instance.
|
|
693
|
+
* @internal
|
|
694
|
+
*/
|
|
695
|
+
const createDefaultAdapter = () => ({ aggregateFragmentMetadata: (fragments) => fragments.map((m) => m.metadata) });
|
|
696
|
+
/**
|
|
697
|
+
* The default adapter instance.
|
|
698
|
+
*/
|
|
699
|
+
const defaultMetadataAdapter = createDefaultAdapter();
|
|
700
|
+
|
|
701
|
+
//#endregion
|
|
702
|
+
//#region packages/core/src/composer/operation.ts
|
|
703
|
+
const createOperationComposerFactory = (schema, adapter) => {
|
|
704
|
+
const resolvedAdapter = adapter ?? defaultMetadataAdapter;
|
|
548
705
|
return (operationType) => {
|
|
549
706
|
const operationTypeName = schema.operations[operationType];
|
|
550
707
|
if (operationTypeName === null) throw new Error(`Operation type ${operationType} is not defined in schema roots`);
|
|
551
708
|
return (options, fieldBuilder) => {
|
|
552
|
-
return
|
|
553
|
-
const { operationName } = options;
|
|
554
|
-
const variables =
|
|
555
|
-
const $ =
|
|
556
|
-
const
|
|
557
|
-
|
|
709
|
+
return Operation.create(() => {
|
|
710
|
+
const { name: operationName } = options;
|
|
711
|
+
const variables = mergeVarDefinitions(options.variables ?? []);
|
|
712
|
+
const $ = createVarRefs(variables);
|
|
713
|
+
const f = createFieldFactories(schema, operationTypeName);
|
|
714
|
+
const { result: fields, usages: fragmentUsages } = withFragmentUsageCollection(() => mergeFields(fieldBuilder({
|
|
715
|
+
f,
|
|
558
716
|
$
|
|
559
|
-
}));
|
|
717
|
+
})));
|
|
560
718
|
const document = buildDocument({
|
|
561
719
|
operationName,
|
|
562
720
|
operationType,
|
|
563
721
|
variables,
|
|
564
722
|
fields
|
|
565
723
|
});
|
|
566
|
-
const metadataResult = options.metadata?.({
|
|
567
|
-
$,
|
|
568
|
-
document
|
|
569
|
-
});
|
|
570
724
|
const createDefinition = (metadata) => ({
|
|
571
725
|
operationType,
|
|
572
726
|
operationName,
|
|
@@ -575,84 +729,42 @@ const createInlineOperationComposerFactory = (schema) => {
|
|
|
575
729
|
document,
|
|
576
730
|
metadata
|
|
577
731
|
});
|
|
578
|
-
if (
|
|
579
|
-
|
|
732
|
+
if (!fragmentUsages.some((u) => u.metadataBuilder) && !options.metadata) return createDefinition(void 0);
|
|
733
|
+
const fragmentMetadataResults = fragmentUsages.map((usage) => usage.metadataBuilder ? usage.metadataBuilder() : void 0);
|
|
734
|
+
const hasAsyncFragmentMetadata = fragmentMetadataResults.some((r) => r instanceof Promise);
|
|
735
|
+
const buildOperationMetadata = (resolvedFragmentMetadata) => {
|
|
736
|
+
const fragmentMetaInfos = fragmentUsages.map((usage, index) => ({
|
|
737
|
+
metadata: resolvedFragmentMetadata[index],
|
|
738
|
+
fieldPath: usage.path
|
|
739
|
+
}));
|
|
740
|
+
const aggregatedFragmentMetadata = resolvedAdapter.aggregateFragmentMetadata(fragmentMetaInfos);
|
|
741
|
+
const schemaLevel = resolvedAdapter.schemaLevel;
|
|
742
|
+
return options.metadata?.({
|
|
743
|
+
$,
|
|
744
|
+
document,
|
|
745
|
+
fragmentMetadata: aggregatedFragmentMetadata,
|
|
746
|
+
schemaLevel
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
if (hasAsyncFragmentMetadata) return Promise.all(fragmentMetadataResults).then(async (resolvedFragmentMetadata) => {
|
|
750
|
+
return createDefinition(await buildOperationMetadata(resolvedFragmentMetadata));
|
|
751
|
+
});
|
|
752
|
+
const operationMetadataResult = buildOperationMetadata(fragmentMetadataResults);
|
|
753
|
+
if (operationMetadataResult instanceof Promise) return operationMetadataResult.then(createDefinition);
|
|
754
|
+
return createDefinition(operationMetadataResult);
|
|
580
755
|
});
|
|
581
756
|
};
|
|
582
757
|
};
|
|
583
758
|
};
|
|
584
759
|
|
|
585
|
-
//#endregion
|
|
586
|
-
//#region packages/core/src/composer/model.ts
|
|
587
|
-
const createGqlModelComposers = (schema) => {
|
|
588
|
-
const createModelComposer = (typename) => {
|
|
589
|
-
return (options, builder, normalize) => Model.create(() => {
|
|
590
|
-
const varDefinitions = require_slice.mergeVarDefinitions(options.variables ?? []);
|
|
591
|
-
return {
|
|
592
|
-
typename,
|
|
593
|
-
fragment: (variables) => {
|
|
594
|
-
return mergeFields(builder({
|
|
595
|
-
f: createFieldFactories(schema, typename),
|
|
596
|
-
$: require_slice.createVarAssignments(varDefinitions, variables)
|
|
597
|
-
}));
|
|
598
|
-
},
|
|
599
|
-
normalize
|
|
600
|
-
};
|
|
601
|
-
});
|
|
602
|
-
};
|
|
603
|
-
return require_slice.mapValues(schema.object, (_, typename) => createModelComposer(typename));
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
//#endregion
|
|
607
|
-
//#region packages/core/src/composer/slice.ts
|
|
608
|
-
const createSliceComposerFactory = (schema) => {
|
|
609
|
-
return (operationType) => {
|
|
610
|
-
const operationTypeName = schema.operations[operationType];
|
|
611
|
-
if (operationTypeName === null) throw new Error(`Operation type ${operationType} is not defined in schema roots`);
|
|
612
|
-
return (options, fieldBuilder, projectionBuilder) => Slice.create(() => {
|
|
613
|
-
const varDefinitions = require_slice.mergeVarDefinitions(options.variables ?? []);
|
|
614
|
-
const projection = require_slice.handleProjectionBuilder(projectionBuilder);
|
|
615
|
-
const { metadata: metadataOption } = options;
|
|
616
|
-
return {
|
|
617
|
-
operationType,
|
|
618
|
-
embed: (variables) => {
|
|
619
|
-
const f = createFieldFactories(schema, operationTypeName);
|
|
620
|
-
const $ = require_slice.createVarAssignments(varDefinitions, variables);
|
|
621
|
-
const fields = mergeFields(fieldBuilder({
|
|
622
|
-
f,
|
|
623
|
-
$
|
|
624
|
-
}));
|
|
625
|
-
return {
|
|
626
|
-
variables,
|
|
627
|
-
getFields: () => fields,
|
|
628
|
-
projection,
|
|
629
|
-
metadata: metadataOption?.({ $ })
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
};
|
|
633
|
-
});
|
|
634
|
-
};
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
//#endregion
|
|
638
|
-
//#region packages/core/src/types/type-foundation/modified-type-name.ts
|
|
639
|
-
function parseModifiedTypeName(nameAndModifier) {
|
|
640
|
-
if (typeof nameAndModifier !== "string") throw new Error(`Invalid modified type name: ${nameAndModifier}`);
|
|
641
|
-
const [name, modifier] = nameAndModifier.split(":");
|
|
642
|
-
return {
|
|
643
|
-
name,
|
|
644
|
-
modifier
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
|
|
648
760
|
//#endregion
|
|
649
761
|
//#region packages/core/src/composer/var-builder.ts
|
|
650
762
|
const createVarBuilder = (schema) => {
|
|
651
763
|
const varBuilder = (varName) => {
|
|
652
764
|
const createVarSpecifierBuilder = (kind) => {
|
|
653
|
-
return (type, extras) => wrapByKey(varName, {
|
|
765
|
+
return (type, extras) => require_schema.wrapByKey(varName, {
|
|
654
766
|
kind,
|
|
655
|
-
...parseModifiedTypeName(type),
|
|
767
|
+
...require_schema.parseModifiedTypeName(type),
|
|
656
768
|
defaultValue: extras?.default ? { default: extras.default() } : null
|
|
657
769
|
});
|
|
658
770
|
};
|
|
@@ -667,41 +779,29 @@ const createVarBuilder = (schema) => {
|
|
|
667
779
|
}
|
|
668
780
|
};
|
|
669
781
|
};
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}) };
|
|
782
|
+
varBuilder.getName = getVarRefName;
|
|
783
|
+
varBuilder.getValue = getVarRefValue;
|
|
784
|
+
varBuilder.getInner = getVarRefInner;
|
|
785
|
+
return varBuilder;
|
|
675
786
|
};
|
|
676
787
|
|
|
677
788
|
//#endregion
|
|
678
789
|
//#region packages/core/src/composer/gql-composer.ts
|
|
679
790
|
const createGqlElementComposer = (schema, options = {}) => {
|
|
680
|
-
const {
|
|
681
|
-
const
|
|
682
|
-
const
|
|
683
|
-
const
|
|
684
|
-
const
|
|
791
|
+
const { adapter } = options;
|
|
792
|
+
const helpers = adapter?.helpers;
|
|
793
|
+
const metadataAdapter = adapter?.metadata;
|
|
794
|
+
const fragment = createGqlFragmentComposers(schema, metadataAdapter);
|
|
795
|
+
const createOperationComposer = createOperationComposerFactory(schema, metadataAdapter);
|
|
685
796
|
const composers = {
|
|
686
|
-
|
|
687
|
-
query: {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
inline: createInlineOperationComposer("query")
|
|
691
|
-
},
|
|
692
|
-
mutation: {
|
|
693
|
-
slice: createSliceComposer("mutation"),
|
|
694
|
-
composed: createComposedOperationFactory("mutation"),
|
|
695
|
-
inline: createInlineOperationComposer("mutation")
|
|
696
|
-
},
|
|
697
|
-
subscription: {
|
|
698
|
-
slice: createSliceComposer("subscription"),
|
|
699
|
-
composed: createComposedOperationFactory("subscription"),
|
|
700
|
-
inline: createInlineOperationComposer("subscription")
|
|
701
|
-
}
|
|
797
|
+
fragment,
|
|
798
|
+
query: { operation: createOperationComposer("query") },
|
|
799
|
+
mutation: { operation: createOperationComposer("mutation") },
|
|
800
|
+
subscription: { operation: createOperationComposer("subscription") }
|
|
702
801
|
};
|
|
703
802
|
const helper = {
|
|
704
|
-
|
|
803
|
+
$var: createVarBuilder(schema),
|
|
804
|
+
$colocate: createColocateHelper(),
|
|
705
805
|
...helpers ?? {}
|
|
706
806
|
};
|
|
707
807
|
const elementComposer = (composeElement) => composeElement(composers, helper);
|
|
@@ -709,124 +809,38 @@ const createGqlElementComposer = (schema, options = {}) => {
|
|
|
709
809
|
};
|
|
710
810
|
|
|
711
811
|
//#endregion
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Helper function for defining typed helpers with better inference.
|
|
715
|
-
* Use this when you need explicit typing or when type inference needs assistance.
|
|
716
|
-
*
|
|
717
|
-
* @example
|
|
718
|
-
* ```typescript
|
|
719
|
-
* const gql = createGqlElementComposer(schema, {
|
|
720
|
-
* helpers: defineHelpers({
|
|
721
|
-
* auth: {
|
|
722
|
-
* requiresLogin: () => ({ requiresAuth: true }),
|
|
723
|
-
* adminOnly: () => ({ requiresAuth: true, role: 'admin' }),
|
|
724
|
-
* },
|
|
725
|
-
* }),
|
|
726
|
-
* });
|
|
727
|
-
* ```
|
|
728
|
-
*/
|
|
729
|
-
const defineHelpers = (helpers) => helpers;
|
|
730
|
-
|
|
731
|
-
//#endregion
|
|
732
|
-
//#region packages/core/src/utils/type-meta.ts
|
|
733
|
-
const withTypeMeta = (target) => {
|
|
734
|
-
if (process.env.NODE_ENV !== "production") {
|
|
735
|
-
if (typeof target !== "object" && typeof target !== "function" || target === null) throw new Error("Target must be an object or a function.");
|
|
736
|
-
Object.defineProperty(target, "$type", { get() {
|
|
737
|
-
throw new Error("This property is only for type inference. Do not access this property directly.");
|
|
738
|
-
} });
|
|
739
|
-
}
|
|
740
|
-
return target;
|
|
741
|
-
};
|
|
742
|
-
|
|
743
|
-
//#endregion
|
|
744
|
-
//#region packages/core/src/schema/type-specifier-builder.ts
|
|
745
|
-
const createUnsafeInputTypeSpecifierFactory = (kind) => {
|
|
746
|
-
return (type, extras) => ({
|
|
747
|
-
kind,
|
|
748
|
-
...parseModifiedTypeName(type),
|
|
749
|
-
defaultValue: extras.default ? { default: extras.default() } : null
|
|
750
|
-
});
|
|
751
|
-
};
|
|
752
|
-
const unsafeInputType = {
|
|
753
|
-
scalar: createUnsafeInputTypeSpecifierFactory("scalar"),
|
|
754
|
-
enum: createUnsafeInputTypeSpecifierFactory("enum"),
|
|
755
|
-
input: createUnsafeInputTypeSpecifierFactory("input")
|
|
756
|
-
};
|
|
757
|
-
const createUnsafeOutputTypeSpecifierFactory = (kind) => {
|
|
758
|
-
return (type, extras) => ({
|
|
759
|
-
kind,
|
|
760
|
-
...parseModifiedTypeName(type),
|
|
761
|
-
arguments: extras.arguments ?? {}
|
|
762
|
-
});
|
|
763
|
-
};
|
|
764
|
-
const unsafeOutputType = {
|
|
765
|
-
scalar: createUnsafeOutputTypeSpecifierFactory("scalar"),
|
|
766
|
-
enum: createUnsafeOutputTypeSpecifierFactory("enum"),
|
|
767
|
-
object: createUnsafeOutputTypeSpecifierFactory("object"),
|
|
768
|
-
union: createUnsafeOutputTypeSpecifierFactory("union"),
|
|
769
|
-
typename: createUnsafeOutputTypeSpecifierFactory("typename")
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
//#endregion
|
|
773
|
-
//#region packages/core/src/schema/schema-builder.ts
|
|
774
|
-
const defineScalar = (name) => wrapByKey(name, withTypeMeta({ name }));
|
|
775
|
-
const define = (name) => ({
|
|
776
|
-
enum: (values) => withTypeMeta({
|
|
777
|
-
name,
|
|
778
|
-
values
|
|
779
|
-
}),
|
|
780
|
-
input: (fields) => ({
|
|
781
|
-
name,
|
|
782
|
-
fields
|
|
783
|
-
}),
|
|
784
|
-
object: (fields) => ({
|
|
785
|
-
name,
|
|
786
|
-
fields: {
|
|
787
|
-
__typename: unsafeOutputType.typename(`${name}:!`, {}),
|
|
788
|
-
...fields
|
|
789
|
-
}
|
|
790
|
-
}),
|
|
791
|
-
union: (types) => ({
|
|
792
|
-
name,
|
|
793
|
-
types
|
|
794
|
-
})
|
|
795
|
-
});
|
|
796
|
-
const defineOperationRoots = (operationRoots) => operationRoots;
|
|
797
|
-
|
|
798
|
-
//#endregion
|
|
799
|
-
exports.ComposedOperation = ComposedOperation;
|
|
812
|
+
exports.Fragment = Fragment;
|
|
800
813
|
exports.GqlElement = GqlElement;
|
|
801
|
-
exports.
|
|
802
|
-
exports.
|
|
803
|
-
exports.Projection = require_slice.Projection;
|
|
804
|
-
exports.Slice = Slice;
|
|
805
|
-
exports.SlicedExecutionResultEmpty = require_slice.SlicedExecutionResultEmpty;
|
|
806
|
-
exports.SlicedExecutionResultError = require_slice.SlicedExecutionResultError;
|
|
807
|
-
exports.SlicedExecutionResultSuccess = require_slice.SlicedExecutionResultSuccess;
|
|
814
|
+
exports.Operation = Operation;
|
|
815
|
+
exports.appendToPath = appendToPath;
|
|
808
816
|
exports.buildArgumentValue = buildArgumentValue;
|
|
809
817
|
exports.buildConstValueNode = buildConstValueNode;
|
|
810
818
|
exports.buildDocument = buildDocument;
|
|
811
819
|
exports.buildOperationTypeNode = buildOperationTypeNode;
|
|
812
820
|
exports.buildWithTypeModifier = buildWithTypeModifier;
|
|
813
|
-
exports.
|
|
821
|
+
exports.createColocateHelper = createColocateHelper;
|
|
822
|
+
exports.createDefaultAdapter = createDefaultAdapter;
|
|
814
823
|
exports.createFieldFactories = createFieldFactories;
|
|
815
824
|
exports.createGqlElementComposer = createGqlElementComposer;
|
|
816
|
-
exports.
|
|
817
|
-
exports.
|
|
818
|
-
exports.
|
|
819
|
-
exports.createVarAssignments = require_slice.createVarAssignments;
|
|
825
|
+
exports.createGqlFragmentComposers = createGqlFragmentComposers;
|
|
826
|
+
exports.createOperationComposerFactory = createOperationComposerFactory;
|
|
827
|
+
exports.createVarAssignments = createVarAssignments;
|
|
820
828
|
exports.createVarBuilder = createVarBuilder;
|
|
821
|
-
exports.createVarRefs =
|
|
822
|
-
exports.
|
|
823
|
-
exports.
|
|
824
|
-
exports.defineOperationRoots = defineOperationRoots;
|
|
825
|
-
exports.defineScalar = defineScalar;
|
|
826
|
-
exports.
|
|
827
|
-
exports.
|
|
828
|
-
exports.
|
|
829
|
+
exports.createVarRefs = createVarRefs;
|
|
830
|
+
exports.defaultMetadataAdapter = defaultMetadataAdapter;
|
|
831
|
+
exports.define = require_schema.define;
|
|
832
|
+
exports.defineOperationRoots = require_schema.defineOperationRoots;
|
|
833
|
+
exports.defineScalar = require_schema.defineScalar;
|
|
834
|
+
exports.getCurrentFieldPath = getCurrentFieldPath;
|
|
835
|
+
exports.getVarRefInner = getVarRefInner;
|
|
836
|
+
exports.getVarRefName = getVarRefName;
|
|
837
|
+
exports.getVarRefValue = getVarRefValue;
|
|
838
|
+
exports.isListType = isListType;
|
|
829
839
|
exports.mergeFields = mergeFields;
|
|
830
|
-
exports.mergeVarDefinitions =
|
|
831
|
-
exports.
|
|
832
|
-
exports.
|
|
840
|
+
exports.mergeVarDefinitions = mergeVarDefinitions;
|
|
841
|
+
exports.recordFragmentUsage = recordFragmentUsage;
|
|
842
|
+
exports.unsafeInputType = require_schema.unsafeInputType;
|
|
843
|
+
exports.unsafeOutputType = require_schema.unsafeOutputType;
|
|
844
|
+
exports.withFieldPath = withFieldPath;
|
|
845
|
+
exports.withFragmentUsageCollection = withFragmentUsageCollection;
|
|
846
|
+
//# sourceMappingURL=index.cjs.map
|