@soda-gql/core 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +67 -55
  2. package/dist/adapter.cjs +1 -1
  3. package/dist/adapter.d.cts +2 -2
  4. package/dist/adapter.d.ts +2 -2
  5. package/dist/adapter.js +1 -1
  6. package/dist/{index-Djr9A4KL.d.ts → index-CVmfSjJv.d.ts} +160 -231
  7. package/dist/index-CVmfSjJv.d.ts.map +1 -0
  8. package/dist/{index-B-erotAZ.d.cts → index-eFR-ZKOA.d.cts} +160 -231
  9. package/dist/index-eFR-ZKOA.d.cts.map +1 -0
  10. package/dist/index.cjs +260 -147
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +13 -4
  13. package/dist/index.d.cts.map +1 -1
  14. package/dist/index.d.ts +13 -4
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +259 -146
  17. package/dist/index.js.map +1 -1
  18. package/dist/runtime.cjs +1 -1
  19. package/dist/runtime.cjs.map +1 -1
  20. package/dist/runtime.d.cts +2 -2
  21. package/dist/runtime.d.ts +2 -2
  22. package/dist/runtime.js +1 -1
  23. package/dist/runtime.js.map +1 -1
  24. package/dist/{schema-BygZwEX8.d.ts → schema-5Vfg289u.d.cts} +162 -74
  25. package/dist/schema-5Vfg289u.d.cts.map +1 -0
  26. package/dist/{schema-D9wIW5Dl.js → schema-BbCrsNkQ.js} +2 -2
  27. package/dist/{schema-D9wIW5Dl.js.map → schema-BbCrsNkQ.js.map} +1 -1
  28. package/dist/{schema-DRkKucYe.d.cts → schema-DnlCvCK4.d.ts} +162 -74
  29. package/dist/schema-DnlCvCK4.d.ts.map +1 -0
  30. package/dist/{schema-Bip7o0g3.cjs → schema-DuWaRhdp.cjs} +1 -7
  31. package/dist/{schema-Bip7o0g3.cjs.map → schema-DuWaRhdp.cjs.map} +1 -1
  32. package/dist/{schema-builder-vwQtCGYI.d.ts → schema-builder-D_K9ESSn.d.ts} +2 -2
  33. package/dist/{schema-builder-vwQtCGYI.d.ts.map → schema-builder-D_K9ESSn.d.ts.map} +1 -1
  34. package/dist/{schema-builder-8zadflz-.d.cts → schema-builder-cy5uLVP1.d.cts} +2 -2
  35. package/dist/{schema-builder-8zadflz-.d.cts.map → schema-builder-cy5uLVP1.d.cts.map} +1 -1
  36. package/package.json +1 -1
  37. package/dist/index-B-erotAZ.d.cts.map +0 -1
  38. package/dist/index-Djr9A4KL.d.ts.map +0 -1
  39. package/dist/schema-BygZwEX8.d.ts.map +0 -1
  40. package/dist/schema-DRkKucYe.d.cts.map +0 -1
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as unsafeOutputType, i as unsafeInputType, n as defineOperationRoots, o as parseModifiedTypeName, r as defineScalar, s as wrapByKey, t as define } from "./schema-D9wIW5Dl.js";
1
+ import { a as unsafeOutputType, i as unsafeInputType, n as defineOperationRoots, o as wrapByKey, r as defineScalar, t as define } from "./schema-BbCrsNkQ.js";
2
2
  import { Kind, OperationTypeNode } from "graphql";
3
3
 
4
4
  //#region packages/core/src/types/type-foundation/var-ref.ts
@@ -13,15 +13,25 @@ var VarRef = class {
13
13
  const isVarRef = (value) => {
14
14
  return typeof value === "object" && value !== null && value instanceof VarRef;
15
15
  };
16
+ /**
17
+ * Recursively checks if a NestedValue contains any VarRef.
18
+ * Used by getVarRefValue to determine if it's safe to return as ConstValue.
19
+ */
20
+ const hasVarRefInside = (value) => {
21
+ if (isVarRef(value)) return true;
22
+ if (Array.isArray(value)) return value.some(hasVarRefInside);
23
+ if (typeof value === "object" && value !== null) return Object.values(value).some(hasVarRefInside);
24
+ return false;
25
+ };
16
26
  const createVarRefFromVariable = (name) => {
17
27
  return new VarRef({
18
28
  type: "variable",
19
29
  name
20
30
  });
21
31
  };
22
- const createVarRefFromConstValue = (value) => {
32
+ const createVarRefFromNestedValue = (value) => {
23
33
  return new VarRef({
24
- type: "const-value",
34
+ type: "nested-value",
25
35
  value
26
36
  });
27
37
  };
@@ -30,22 +40,97 @@ const getVarRefInner = (varRef) => {
30
40
  };
31
41
  /**
32
42
  * Get the variable name from a VarRef.
33
- * Throws if the VarRef contains a const-value instead of a variable reference.
43
+ * Throws if the VarRef contains a nested-value instead of a variable reference.
34
44
  */
35
45
  const getVarRefName = (varRef) => {
36
46
  const inner = VarRef.getInner(varRef);
37
- if (inner.type !== "variable") throw new Error("Expected variable reference, got const-value");
47
+ if (inner.type !== "variable") throw new Error("Expected variable reference, got nested-value");
38
48
  return inner.name;
39
49
  };
40
50
  /**
41
51
  * Get the const value from a VarRef.
42
- * Throws if the VarRef contains a variable reference instead of a const-value.
52
+ * Throws if the VarRef contains a variable reference instead of a nested-value,
53
+ * or if the nested-value contains any VarRef inside.
43
54
  */
44
55
  const getVarRefValue = (varRef) => {
45
56
  const inner = VarRef.getInner(varRef);
46
- if (inner.type !== "const-value") throw new Error("Expected const-value, got variable reference");
57
+ if (inner.type !== "nested-value") throw new Error("Expected nested-value, got variable reference");
58
+ if (hasVarRefInside(inner.value)) throw new Error("Cannot get const value: nested-value contains VarRef");
47
59
  return inner.value;
48
60
  };
61
+ const ProxyInnerRegistry = /* @__PURE__ */ new WeakMap();
62
+ const getProxyInner = (proxy) => {
63
+ const inner = ProxyInnerRegistry.get(proxy);
64
+ if (!inner) throw new Error(`Proxy inner not found`);
65
+ return inner;
66
+ };
67
+ const createProxy = (current) => {
68
+ const proxy = new Proxy(Object.create(null), { get(_, property) {
69
+ if (typeof property === "symbol") throw new Error(`Prohibited property access: ${String(property)}`);
70
+ if (current.inner.type === "variable") throw new Error(`Cannot access children of variable at path [${current.segments.join(".")}]`);
71
+ if (typeof current.inner.value === "object" && current.inner.value !== null) {
72
+ const value = current.inner.value[property];
73
+ return createProxy({
74
+ inner: isVarRef(value) ? getVarRefInner(value) : {
75
+ type: "nested-value",
76
+ value
77
+ },
78
+ segments: [...current.segments, property]
79
+ });
80
+ }
81
+ throw new Error(`Cannot access children of primitive value at path [${current.segments.join(".")}]`);
82
+ } });
83
+ ProxyInnerRegistry.set(proxy, {
84
+ inner: current.inner,
85
+ segments: current.segments
86
+ });
87
+ return proxy;
88
+ };
89
+ /**
90
+ * Get the variable name from a VarRef at a specific path.
91
+ *
92
+ * @param varRef - The VarRef containing a nested-value
93
+ * @param selector - Path builder function, e.g., p => p.user.age
94
+ * @returns The variable name at the specified path
95
+ * @throws If path doesn't lead to a VarRef with type "variable"
96
+ *
97
+ * @example
98
+ * const ref = createVarRefFromNestedValue({
99
+ * user: { age: someVariableRef }
100
+ * });
101
+ * getNameAt(ref, p => p.user.age); // returns the variable name
102
+ */
103
+ const getNameAt = (varRef, selector) => {
104
+ const inner = getProxyInner(selector(createProxy({
105
+ inner: VarRef.getInner(varRef),
106
+ segments: []
107
+ })));
108
+ if (inner.inner.type !== "variable") throw new Error(`Value at path [${inner.segments.join(".")}] is not a variable`);
109
+ return inner.inner.name;
110
+ };
111
+ /**
112
+ * Get the const value from a nested-value VarRef at a specific path.
113
+ *
114
+ * @param varRef - The VarRef containing a nested-value
115
+ * @param pathFn - Path builder function, e.g., p => p.user.name
116
+ * @returns The const value at the specified path
117
+ * @throws If path leads to a VarRef or if value contains VarRef inside
118
+ *
119
+ * @example
120
+ * const ref = createVarRefFromNestedValue({
121
+ * user: { name: "Alice", age: someVariableRef }
122
+ * });
123
+ * getValueAt(ref, p => p.user.name); // returns "Alice"
124
+ */
125
+ const getValueAt = (varRef, selector) => {
126
+ const inner = getProxyInner(selector(createProxy({
127
+ inner: VarRef.getInner(varRef),
128
+ segments: []
129
+ })));
130
+ if (inner.inner.type !== "nested-value") throw new Error(`Value at path [${inner.segments.join(".")}] is not a nested-value`);
131
+ if (hasVarRefInside(inner.inner.value)) throw new Error(`Value at path [${inner.segments.join(".")}] contains nested VarRef`);
132
+ return inner.inner.value;
133
+ };
49
134
 
50
135
  //#endregion
51
136
  //#region packages/core/src/composer/build-document.ts
@@ -61,7 +146,7 @@ const buildArgumentValue = (value) => {
61
146
  value: inner.name
62
147
  }
63
148
  };
64
- if (inner.type === "const-value") return buildConstValueNode(inner.value);
149
+ if (inner.type === "nested-value") return buildArgumentValue(inner.value);
65
150
  throw new Error(`Unknown var ref type: ${inner}`);
66
151
  }
67
152
  if (Array.isArray(value)) return {
@@ -294,12 +379,13 @@ const buildDocument = (options) => {
294
379
  * @example
295
380
  * ```typescript
296
381
  * // In operation definition
297
- * query.operation({ name: "GetData" }, ({ f, $ }) => [
298
- * $colocate({
299
- * userCard: userCardFragment.embed({ userId: $.userId }),
300
- * posts: postsFragment.embed({ userId: $.userId }),
382
+ * query.operation({
383
+ * name: "GetData",
384
+ * fields: ({ $ }) => $colocate({
385
+ * userCard: userCardFragment.spread({ userId: $.userId }),
386
+ * posts: postsFragment.spread({ userId: $.userId }),
301
387
  * }),
302
- * ]);
388
+ * });
303
389
  *
304
390
  * // In parser definition (same labels)
305
391
  * createExecutionResultParser({
@@ -334,7 +420,7 @@ const fieldPathContext = { current: null };
334
420
  * ```typescript
335
421
  * import { getCurrentFieldPath } from '@soda-gql/core';
336
422
  *
337
- * // Inside a field builder or model embed:
423
+ * // Inside a field builder or model spread:
338
424
  * const path = getCurrentFieldPath();
339
425
  * console.log(path?.full); // "$.user.posts[].author"
340
426
  * ```
@@ -387,8 +473,91 @@ const isListType = (typeString) => {
387
473
  };
388
474
 
389
475
  //#endregion
390
- //#region packages/core/src/types/element/fields-builder.ts
391
- const mergeFields = (fields) => Object.assign({}, ...fields);
476
+ //#region packages/core/src/utils/map-values.ts
477
+ function mapValues(obj, fn) {
478
+ return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, fn(value, key)]));
479
+ }
480
+
481
+ //#endregion
482
+ //#region packages/core/src/composer/fields-builder.ts
483
+ const cacheMapBySchema = /* @__PURE__ */ new WeakMap();
484
+ const ensureCacheMapBySchema = (schema) => {
485
+ const cachedCacheMap = cacheMapBySchema.get(schema);
486
+ if (cachedCacheMap) return cachedCacheMap;
487
+ const cacheMap = /* @__PURE__ */ new Map();
488
+ cacheMapBySchema.set(schema, cacheMap);
489
+ return cacheMap;
490
+ };
491
+ const createFieldFactories = (schema, typeName) => {
492
+ const cacheMap = ensureCacheMapBySchema(schema);
493
+ const cached = cacheMap.get(typeName);
494
+ if (cached) return cached;
495
+ const factories = createFieldFactoriesInner(schema, typeName);
496
+ cacheMap.set(typeName, factories);
497
+ return factories;
498
+ };
499
+ const createFieldFactoriesInner = (schema, typeName) => {
500
+ const typeDef = schema.object[typeName];
501
+ if (!typeDef) throw new Error(`Type ${typeName} is not defined in schema objects`);
502
+ const entries = Object.entries(typeDef.fields).map(([fieldName, type]) => {
503
+ const factory = (fieldArgs, extras) => {
504
+ const wrap = (value) => wrapByKey(extras?.alias ?? fieldName, value);
505
+ if (type.kind === "object") {
506
+ const factoryReturn = ((nest) => {
507
+ const nestedFields = withFieldPath(appendToPath(getCurrentFieldPath(), {
508
+ field: fieldName,
509
+ parentType: typeName,
510
+ isList: isListType(type.modifier)
511
+ }), () => nest({ f: createFieldFactories(schema, type.name) }));
512
+ return wrap({
513
+ parent: typeName,
514
+ field: fieldName,
515
+ type,
516
+ args: fieldArgs ?? {},
517
+ directives: extras?.directives ?? {},
518
+ object: nestedFields,
519
+ union: null
520
+ });
521
+ });
522
+ return factoryReturn;
523
+ }
524
+ if (type.kind === "union") {
525
+ const factoryReturn = ((nest) => {
526
+ const nestedUnion = withFieldPath(appendToPath(getCurrentFieldPath(), {
527
+ field: fieldName,
528
+ parentType: typeName,
529
+ isList: isListType(type.modifier)
530
+ }), () => mapValues(nest, (builder, memberName) => {
531
+ if (!builder) throw new Error(`Builder is undefined for member name: ${memberName}`);
532
+ return builder({ f: createFieldFactories(schema, memberName) });
533
+ }));
534
+ return wrap({
535
+ parent: typeName,
536
+ field: fieldName,
537
+ type,
538
+ args: fieldArgs ?? {},
539
+ directives: extras?.directives ?? {},
540
+ object: null,
541
+ union: nestedUnion
542
+ });
543
+ });
544
+ return factoryReturn;
545
+ }
546
+ if (type.kind === "scalar" || type.kind === "enum" || type.kind === "typename") return wrap({
547
+ parent: typeName,
548
+ field: fieldName,
549
+ type,
550
+ args: fieldArgs ?? {},
551
+ directives: extras?.directives ?? {},
552
+ object: null,
553
+ union: null
554
+ });
555
+ throw new Error(`Unsupported field type: ${type}`);
556
+ };
557
+ return [fieldName, factory];
558
+ });
559
+ return Object.fromEntries(entries);
560
+ };
392
561
 
393
562
  //#endregion
394
563
  //#region packages/core/src/types/element/lazy-evaluator.ts
@@ -485,8 +654,8 @@ var Fragment = class Fragment extends GqlElement {
485
654
  get typename() {
486
655
  return GqlElement.get(this).typename;
487
656
  }
488
- get embed() {
489
- return GqlElement.get(this).embed;
657
+ get spread() {
658
+ return GqlElement.get(this).spread;
490
659
  }
491
660
  static create(define$1) {
492
661
  return new Fragment(define$1);
@@ -522,93 +691,6 @@ var Operation = class Operation extends GqlElement {
522
691
  }
523
692
  };
524
693
 
525
- //#endregion
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)]));
529
- }
530
-
531
- //#endregion
532
- //#region packages/core/src/composer/fields-builder.ts
533
- const cacheMapBySchema = /* @__PURE__ */ new WeakMap();
534
- const ensureCacheMapBySchema = (schema) => {
535
- const cachedCacheMap = cacheMapBySchema.get(schema);
536
- if (cachedCacheMap) return cachedCacheMap;
537
- const cacheMap = /* @__PURE__ */ new Map();
538
- cacheMapBySchema.set(schema, cacheMap);
539
- return cacheMap;
540
- };
541
- const createFieldFactories = (schema, typeName) => {
542
- const cacheMap = ensureCacheMapBySchema(schema);
543
- const cached = cacheMap.get(typeName);
544
- if (cached) return cached;
545
- const factories = createFieldFactoriesInner(schema, typeName);
546
- cacheMap.set(typeName, factories);
547
- return factories;
548
- };
549
- const createFieldFactoriesInner = (schema, typeName) => {
550
- const typeDef = schema.object[typeName];
551
- if (!typeDef) throw new Error(`Type ${typeName} is not defined in schema objects`);
552
- const entries = Object.entries(typeDef.fields).map(([fieldName, type]) => {
553
- const factory = (fieldArgs, extras) => {
554
- const wrap = (value) => wrapByKey(extras?.alias ?? fieldName, value);
555
- if (type.kind === "object") {
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
- });
572
- return factoryReturn;
573
- }
574
- if (type.kind === "union") {
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) => {
581
- if (!builder) throw new Error(`Builder is undefined for member name: ${memberName}`);
582
- return mergeFields(builder({ f: createFieldFactories(schema, memberName) }));
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
- });
594
- return factoryReturn;
595
- }
596
- if (type.kind === "scalar" || type.kind === "enum" || type.kind === "typename") return wrap({
597
- parent: typeName,
598
- field: fieldName,
599
- type,
600
- args: fieldArgs ?? {},
601
- directives: extras?.directives ?? {},
602
- object: null,
603
- union: null
604
- });
605
- throw new Error(`Unsupported field type: ${type}`);
606
- };
607
- return [fieldName, factory];
608
- });
609
- return Object.fromEntries(entries);
610
- };
611
-
612
694
  //#endregion
613
695
  //#region packages/core/src/composer/fragment-usage-context.ts
614
696
  /**
@@ -636,7 +718,7 @@ const withFragmentUsageCollection = (fn) => {
636
718
  }
637
719
  };
638
720
  /**
639
- * Record a fragment usage. Called when fragment.embed() is invoked.
721
+ * Record a fragment usage. Called when fragment.spread() is invoked.
640
722
  * No-op if not in a collection context.
641
723
  *
642
724
  * @internal
@@ -647,14 +729,13 @@ const recordFragmentUsage = (record) => {
647
729
 
648
730
  //#endregion
649
731
  //#region packages/core/src/composer/input.ts
650
- const mergeVarDefinitions = (definitions) => Object.assign({}, ...definitions);
651
732
  const createVarAssignments = (definitions, providedValues) => {
652
733
  return mapValues(definitions, (_definition, key) => {
653
734
  const varName = key;
654
- if (!providedValues || providedValues[varName] === void 0) return createVarRefFromConstValue(void 0);
735
+ if (!providedValues || providedValues[varName] === void 0) return createVarRefFromNestedValue(void 0);
655
736
  const provided = providedValues[varName];
656
737
  if (isVarRef(provided)) return provided;
657
- return createVarRefFromConstValue(provided);
738
+ return createVarRefFromNestedValue(provided);
658
739
  });
659
740
  };
660
741
  const createVarRefs = (definitions) => mapValues(definitions, (_ref, name) => createVarRefFromVariable(name));
@@ -663,22 +744,22 @@ const createVarRefs = (definitions) => mapValues(definitions, (_ref, name) => cr
663
744
  //#region packages/core/src/composer/fragment.ts
664
745
  const createGqlFragmentComposers = (schema, _adapter) => {
665
746
  const createFragmentComposer = (typename) => {
666
- return (options, builder) => {
667
- const varDefinitions = mergeVarDefinitions(options.variables ?? []);
668
- const { metadata } = options;
747
+ return (options) => {
748
+ const varDefinitions = options.variables ?? {};
749
+ const { metadata, fields } = options;
669
750
  return Fragment.create(() => ({
670
751
  typename,
671
- embed: (variables) => {
752
+ spread: (variables) => {
672
753
  const f = createFieldFactories(schema, typename);
673
754
  const $ = createVarAssignments(varDefinitions, variables);
674
755
  recordFragmentUsage({
675
756
  metadataBuilder: metadata ? () => metadata({ $ }) : null,
676
757
  path: getCurrentFieldPath()
677
758
  });
678
- return mergeFields(builder({
759
+ return fields({
679
760
  f,
680
761
  $
681
- }));
762
+ });
682
763
  }
683
764
  }));
684
765
  };
@@ -705,16 +786,16 @@ const createOperationComposerFactory = (schema, adapter) => {
705
786
  return (operationType) => {
706
787
  const operationTypeName = schema.operations[operationType];
707
788
  if (operationTypeName === null) throw new Error(`Operation type ${operationType} is not defined in schema roots`);
708
- return (options, fieldBuilder) => {
789
+ return (options) => {
709
790
  return Operation.create(() => {
710
791
  const { name: operationName } = options;
711
- const variables = mergeVarDefinitions(options.variables ?? []);
792
+ const variables = options.variables ?? {};
712
793
  const $ = createVarRefs(variables);
713
794
  const f = createFieldFactories(schema, operationTypeName);
714
- const { result: fields, usages: fragmentUsages } = withFragmentUsageCollection(() => mergeFields(fieldBuilder({
795
+ const { result: fields, usages: fragmentUsages } = withFragmentUsageCollection(() => options.fields({
715
796
  f,
716
797
  $
717
- })));
798
+ }));
718
799
  const document = buildDocument({
719
800
  operationName,
720
801
  operationType,
@@ -759,55 +840,87 @@ const createOperationComposerFactory = (schema, adapter) => {
759
840
 
760
841
  //#endregion
761
842
  //#region packages/core/src/composer/var-builder.ts
762
- const createVarBuilder = (schema) => {
843
+ /**
844
+ * Creates a variable method for a specific input type.
845
+ * This is used by codegen to generate type-specific variable methods.
846
+ *
847
+ * @deprecated Use createVarMethodFactory instead for proper type inference with nested input objects.
848
+ */
849
+ const createVarMethod = (kind, typeName) => {
850
+ return (modifier, extras) => ({
851
+ kind,
852
+ name: typeName,
853
+ modifier,
854
+ defaultValue: extras?.default ? { default: extras.default() } : null,
855
+ directives: extras?.directives ?? {}
856
+ });
857
+ };
858
+ /**
859
+ * Creates a factory function for generating schema-scoped variable methods.
860
+ * This ensures proper type inference for nested input objects by binding the schema type upfront.
861
+ *
862
+ * @example
863
+ * ```typescript
864
+ * const createMethod = createVarMethodFactory<typeof schema>();
865
+ * const inputTypeMethods = {
866
+ * Boolean: createMethod("scalar", "Boolean"),
867
+ * user_bool_exp: createMethod("input", "user_bool_exp"),
868
+ * } satisfies InputTypeMethods<typeof schema>;
869
+ * ```
870
+ */
871
+ const createVarMethodFactory = () => {
872
+ return (kind, typeName) => {
873
+ return ((modifier, extras) => ({
874
+ kind,
875
+ name: typeName,
876
+ modifier,
877
+ defaultValue: extras?.default ? { default: extras.default() } : null,
878
+ directives: extras?.directives ?? {}
879
+ }));
880
+ };
881
+ };
882
+ /**
883
+ * Creates a variable builder that uses injected input type methods.
884
+ */
885
+ const createVarBuilder = (inputTypeMethods) => {
763
886
  const varBuilder = (varName) => {
764
- const createVarSpecifierBuilder = (kind) => {
765
- return (type, extras) => wrapByKey(varName, {
766
- kind,
767
- ...parseModifiedTypeName(type),
768
- defaultValue: extras?.default ? { default: extras.default() } : null
769
- });
770
- };
771
- return {
772
- scalar: createVarSpecifierBuilder("scalar"),
773
- enum: createVarSpecifierBuilder("enum"),
774
- input: createVarSpecifierBuilder("input"),
775
- byField: (typeName, fieldName, argName) => {
776
- const argTypeRef = schema.object[typeName]?.fields[fieldName]?.arguments[argName];
777
- if (!argTypeRef) throw new Error(`Argument ${argName} not found in field ${fieldName} of type ${typeName}`);
778
- return { ...argTypeRef };
779
- }
780
- };
887
+ const wrappedMethods = {};
888
+ for (const [typeName, method] of Object.entries(inputTypeMethods)) Object.defineProperty(wrappedMethods, typeName, {
889
+ value: ((modifier, extras) => wrapByKey(varName, method(modifier, extras))),
890
+ writable: false,
891
+ configurable: true
892
+ });
893
+ return wrappedMethods;
781
894
  };
782
895
  varBuilder.getName = getVarRefName;
783
896
  varBuilder.getValue = getVarRefValue;
784
897
  varBuilder.getInner = getVarRefInner;
898
+ varBuilder.getNameAt = getNameAt;
899
+ varBuilder.getValueAt = getValueAt;
785
900
  return varBuilder;
786
901
  };
787
902
 
788
903
  //#endregion
789
904
  //#region packages/core/src/composer/gql-composer.ts
790
- const createGqlElementComposer = (schema, options = {}) => {
791
- const { adapter } = options;
905
+ const createGqlElementComposer = (schema, options) => {
906
+ const { adapter, inputTypeMethods } = options;
792
907
  const helpers = adapter?.helpers;
793
908
  const metadataAdapter = adapter?.metadata;
794
909
  const fragment = createGqlFragmentComposers(schema, metadataAdapter);
795
910
  const createOperationComposer = createOperationComposerFactory(schema, metadataAdapter);
796
- const composers = {
911
+ const context = {
797
912
  fragment,
798
913
  query: { operation: createOperationComposer("query") },
799
914
  mutation: { operation: createOperationComposer("mutation") },
800
- subscription: { operation: createOperationComposer("subscription") }
801
- };
802
- const helper = {
803
- $var: createVarBuilder(schema),
915
+ subscription: { operation: createOperationComposer("subscription") },
916
+ $var: createVarBuilder(inputTypeMethods),
804
917
  $colocate: createColocateHelper(),
805
918
  ...helpers ?? {}
806
919
  };
807
- const elementComposer = (composeElement) => composeElement(composers, helper);
920
+ const elementComposer = (composeElement) => composeElement(context);
808
921
  return elementComposer;
809
922
  };
810
923
 
811
924
  //#endregion
812
- export { Fragment, GqlElement, Operation, appendToPath, buildArgumentValue, buildConstValueNode, buildDocument, buildOperationTypeNode, buildWithTypeModifier, createColocateHelper, createDefaultAdapter, createFieldFactories, createGqlElementComposer, createGqlFragmentComposers, createOperationComposerFactory, createVarAssignments, createVarBuilder, createVarRefs, defaultMetadataAdapter, define, defineOperationRoots, defineScalar, getCurrentFieldPath, getVarRefInner, getVarRefName, getVarRefValue, isListType, mergeFields, mergeVarDefinitions, recordFragmentUsage, unsafeInputType, unsafeOutputType, withFieldPath, withFragmentUsageCollection };
925
+ export { Fragment, GqlElement, Operation, appendToPath, buildArgumentValue, buildConstValueNode, buildDocument, buildOperationTypeNode, buildWithTypeModifier, createColocateHelper, createDefaultAdapter, createFieldFactories, createGqlElementComposer, createGqlFragmentComposers, createOperationComposerFactory, createVarAssignments, createVarBuilder, createVarMethod, createVarMethodFactory, createVarRefs, defaultMetadataAdapter, define, defineOperationRoots, defineScalar, getCurrentFieldPath, getVarRefInner, getVarRefName, getVarRefValue, isListType, recordFragmentUsage, unsafeInputType, unsafeOutputType, withFieldPath, withFragmentUsageCollection };
813
926
  //# sourceMappingURL=index.js.map