@ptdgrp/typedgql 1.0.0-beta.13 → 1.0.0-beta.15
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/dist/index.cjs +61 -36
- package/dist/index.d.cts +41 -7
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +41 -7
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +61 -36
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +5 -1
- package/dist/node.d.cts.map +1 -1
- package/dist/node.d.mts +5 -1
- package/dist/node.d.mts.map +1 -1
- package/dist/node.mjs +1 -1
- package/dist/{options-CaWo97vV.d.cts → options-BWcHrC-1.d.mts} +14 -8
- package/dist/options-BWcHrC-1.d.mts.map +1 -0
- package/dist/{options-D2L-tv7C.d.mts → options-CgrZ2der.d.cts} +14 -8
- package/dist/options-CgrZ2der.d.cts.map +1 -0
- package/dist/{schema-loader-DxKAN2ER.cjs → schema-loader-DolAa42F.cjs} +247 -135
- package/dist/{schema-loader-CB4j3yYF.mjs → schema-loader-vNpUWFmU.mjs} +214 -136
- package/dist/schema-loader-vNpUWFmU.mjs.map +1 -0
- package/dist/vite.cjs +1 -1
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.mts +1 -1
- package/dist/vite.mjs +1 -1
- package/package.json +1 -1
- package/dist/options-CaWo97vV.d.cts.map +0 -1
- package/dist/options-D2L-tv7C.d.mts.map +0 -1
- package/dist/schema-loader-CB4j3yYF.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -104,21 +104,43 @@ const registerSchemaType = (type) => {
|
|
|
104
104
|
//#endregion
|
|
105
105
|
//#region src/runtime/parameter.ts
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Runtime marker for `ParameterRef`.
|
|
108
108
|
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
109
|
+
* We use a unique symbol instead of string keys to avoid accidental collision
|
|
110
|
+
* with user objects passed as argument literals.
|
|
111
111
|
*/
|
|
112
112
|
const __marker = Symbol("__parameter_ref_marker");
|
|
113
113
|
var ParameterRef = class ParameterRef {
|
|
114
114
|
[__marker] = true;
|
|
115
|
-
constructor(name,
|
|
115
|
+
constructor(name, explicitType) {
|
|
116
116
|
this.name = name;
|
|
117
|
-
this.
|
|
117
|
+
this.explicitType = explicitType;
|
|
118
118
|
if (name.startsWith("$")) throw new Error("parameter name cannot start with '$'");
|
|
119
119
|
}
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Represents a GraphQL variable reference used in DSL argument objects.
|
|
122
|
+
*
|
|
123
|
+
* Example:
|
|
124
|
+
* - `id: ParameterRef.of("postId")` -> `id: $postId`
|
|
125
|
+
*
|
|
126
|
+
* Main use cases:
|
|
127
|
+
* 1. Rename/bind a field argument to a different variable name.
|
|
128
|
+
* 2. Explicitly annotate variable type when runtime cannot infer it from a
|
|
129
|
+
* field argument position (for example directive args or nested literals).
|
|
130
|
+
*
|
|
131
|
+
* When `explicitType` is NOT needed:
|
|
132
|
+
* - Field arg slot with schema type:
|
|
133
|
+
* `q.user({ id: ParameterRef.of("userId") }, (u) => u.id)`
|
|
134
|
+
* `id` type is inferred from schema (`ID!`).
|
|
135
|
+
*
|
|
136
|
+
* When `explicitType` IS needed:
|
|
137
|
+
* - Directive arg slot:
|
|
138
|
+
* `node.$directive("include", { if: ParameterRef.of("withEmail", "Boolean!") })`
|
|
139
|
+
* - Nested input slot without direct arg type context:
|
|
140
|
+
* `q.search({ filter: { keyword: ParameterRef.of("kw", "String!") } }, ...)`
|
|
141
|
+
*/
|
|
142
|
+
static of(name, explicitType) {
|
|
143
|
+
return new ParameterRef(name, explicitType);
|
|
122
144
|
}
|
|
123
145
|
};
|
|
124
146
|
|
|
@@ -414,7 +436,7 @@ var SerializeContext = class SerializeContext {
|
|
|
414
436
|
t(name);
|
|
415
437
|
if (field.argGraphQLTypes) {
|
|
416
438
|
const meta = sel._enumInputMetadata;
|
|
417
|
-
this.acceptArgs(field.args, field.argGraphQLTypes, meta);
|
|
439
|
+
this.acceptArgs(field.args, field.argGraphQLTypes, meta, `field '${runtime.schemaType.name}.${name}'`);
|
|
418
440
|
}
|
|
419
441
|
this.acceptDirectives(field.fieldOptionsValue?.directives);
|
|
420
442
|
}
|
|
@@ -456,10 +478,10 @@ var SerializeContext = class SerializeContext {
|
|
|
456
478
|
if (!directives) return;
|
|
457
479
|
for (const [directive, args] of directives) {
|
|
458
480
|
this.writer.text(`\n@${directive}`);
|
|
459
|
-
this.acceptArgs(args);
|
|
481
|
+
this.acceptArgs(args, void 0, void 0, `directive '@${directive}'`);
|
|
460
482
|
}
|
|
461
483
|
}
|
|
462
|
-
acceptArgs(args, argGraphQLTypeMap, enumInputMetadata) {
|
|
484
|
+
acceptArgs(args, argGraphQLTypeMap, enumInputMetadata, argContext = "argument") {
|
|
463
485
|
if (!args) return;
|
|
464
486
|
const t = this.writer.text.bind(this.writer);
|
|
465
487
|
let hasField;
|
|
@@ -481,7 +503,7 @@ var SerializeContext = class SerializeContext {
|
|
|
481
503
|
const typeName = argGraphQLTypeMap.get(argName);
|
|
482
504
|
if (typeName !== void 0) if (arg?.[__marker]) {
|
|
483
505
|
const ref = arg;
|
|
484
|
-
this.registerVariableType(ref, typeName, false,
|
|
506
|
+
this.registerVariableType(ref, typeName, false, `${argContext}.${argName}`);
|
|
485
507
|
t(`${argName}: $${ref.name}`);
|
|
486
508
|
} else {
|
|
487
509
|
t(`${argName}: `);
|
|
@@ -490,8 +512,8 @@ var SerializeContext = class SerializeContext {
|
|
|
490
512
|
else throw new Error(`Unknown argument '${argName}'`);
|
|
491
513
|
} else if (arg?.[__marker]) {
|
|
492
514
|
const ref = arg;
|
|
493
|
-
if (!ref.
|
|
494
|
-
this.registerVariableType(ref, ref.
|
|
515
|
+
if (!ref.explicitType) throw new Error(`Cannot infer the type of directive argument '${ref.name}'; an explicit type annotation is required.`);
|
|
516
|
+
this.registerVariableType(ref, ref.explicitType, false, `${argContext}.${argName}`);
|
|
495
517
|
t(`${argName}: $${ref.name}`);
|
|
496
518
|
} else {
|
|
497
519
|
t(`${argName}: `);
|
|
@@ -500,7 +522,7 @@ var SerializeContext = class SerializeContext {
|
|
|
500
522
|
}
|
|
501
523
|
});
|
|
502
524
|
}
|
|
503
|
-
acceptLiteral(value, metaType,
|
|
525
|
+
acceptLiteral(value, metaType, explicitType) {
|
|
504
526
|
const t = this.writer.text.bind(this.writer);
|
|
505
527
|
if (value == null) {
|
|
506
528
|
t("null");
|
|
@@ -520,8 +542,8 @@ var SerializeContext = class SerializeContext {
|
|
|
520
542
|
}
|
|
521
543
|
if (value?.[__marker]) {
|
|
522
544
|
const ref = value;
|
|
523
|
-
if (!
|
|
524
|
-
this.registerVariableType(ref,
|
|
545
|
+
if (!explicitType && !ref.explicitType) throw new Error(`Cannot infer the nested type of argument '${ref.name}'; an explicit type annotation is required.`);
|
|
546
|
+
this.registerVariableType(ref, explicitType, true, "nested argument");
|
|
525
547
|
t(`$${ref.name}`);
|
|
526
548
|
return;
|
|
527
549
|
}
|
|
@@ -530,7 +552,7 @@ var SerializeContext = class SerializeContext {
|
|
|
530
552
|
return;
|
|
531
553
|
}
|
|
532
554
|
if (Array.isArray(value) || value instanceof Set) {
|
|
533
|
-
const elementGraphQLTypeName = SerializeContext.elementTypeName(
|
|
555
|
+
const elementGraphQLTypeName = SerializeContext.elementTypeName(explicitType);
|
|
534
556
|
this.writer.scope({ type: "array" }, () => {
|
|
535
557
|
for (const e of value) {
|
|
536
558
|
this.writer.separator(", ");
|
|
@@ -555,12 +577,15 @@ var SerializeContext = class SerializeContext {
|
|
|
555
577
|
});
|
|
556
578
|
}
|
|
557
579
|
registerVariableType(ref, expectedTypeName, allowImplicitFromRef = false, context = "argument") {
|
|
558
|
-
const typeName = expectedTypeName ?? (allowImplicitFromRef ? ref.
|
|
559
|
-
if (!typeName) throw new Error(`
|
|
560
|
-
if (ref.
|
|
580
|
+
const typeName = expectedTypeName ?? (allowImplicitFromRef ? ref.explicitType : void 0);
|
|
581
|
+
if (!typeName) throw new Error(`Cannot infer the type of directive argument '${ref.name}'; an explicit type annotation is required.`);
|
|
582
|
+
if (ref.explicitType && ref.explicitType !== typeName) throw new Error(`Variable '$${ref.name}' has conflicting GraphQL types at ${context}: inferred '${typeName}', but ParameterRef declares '${ref.explicitType}'`);
|
|
561
583
|
const existing = this.variableTypeMap.get(ref.name);
|
|
562
|
-
if (existing && existing !== typeName) throw new Error(`
|
|
563
|
-
this.variableTypeMap.set(ref.name,
|
|
584
|
+
if (existing && existing.typeName !== typeName) throw new Error(`Variable '$${ref.name}' has conflicting GraphQL types: first '${existing.typeName}' at ${existing.source}, then '${typeName}' at ${context}`);
|
|
585
|
+
this.variableTypeMap.set(ref.name, {
|
|
586
|
+
typeName,
|
|
587
|
+
source: context
|
|
588
|
+
});
|
|
564
589
|
}
|
|
565
590
|
static enumMetaType(meta, typeName) {
|
|
566
591
|
if (!meta || !typeName) return void 0;
|
|
@@ -720,13 +745,15 @@ const createChildSelectionProxy = (schemaType, enumInputMetadata) => {
|
|
|
720
745
|
void 0
|
|
721
746
|
], false, ""), proxyHandler(schemaType));
|
|
722
747
|
};
|
|
723
|
-
const
|
|
724
|
-
if (!
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
748
|
+
const resolveAutoPropagatedArgs = (declaredArgTypeMap, providedArgs) => {
|
|
749
|
+
if (!declaredArgTypeMap?.size) return providedArgs;
|
|
750
|
+
const autoArgs = {};
|
|
751
|
+
for (const argName of declaredArgTypeMap.keys()) autoArgs[argName] = ParameterRef.of(argName);
|
|
752
|
+
if (!providedArgs) return autoArgs;
|
|
753
|
+
return {
|
|
754
|
+
...autoArgs,
|
|
755
|
+
...providedArgs
|
|
756
|
+
};
|
|
730
757
|
};
|
|
731
758
|
const resolveAssociationTarget = (fieldName, fieldTargetTypeName, ownerTypeName) => {
|
|
732
759
|
if (!fieldTargetTypeName) throw new Error(`Field "${fieldName}" has no target type`);
|
|
@@ -793,8 +820,8 @@ const proxyHandler = (schemaType) => {
|
|
|
793
820
|
let { args, childSelectionFactory, childSelection } = parseAssociationArgs(argArray);
|
|
794
821
|
if (childSelectionFactory) childSelection = childSelectionFactory(createChildSelectionProxy(targetSchemaType, target._enumInputMetadata));
|
|
795
822
|
if (!childSelection) throw new Error(`Field "${p}" requires a child selection`);
|
|
796
|
-
|
|
797
|
-
return new Proxy(target.addField(p,
|
|
823
|
+
const resolvedArgs = resolveAutoPropagatedArgs(field.argGraphQLTypeMap, args);
|
|
824
|
+
return new Proxy(target.addField(p, resolvedArgs, childSelection), handler);
|
|
798
825
|
};
|
|
799
826
|
if (field.isFunction) return new Proxy(DUMMY, methodHandler(target, handler, p));
|
|
800
827
|
return new Proxy(target.addField(p), handler);
|
|
@@ -862,11 +889,9 @@ const methodHandler = (targetSelection, handler, field) => {
|
|
|
862
889
|
return new Proxy(current, handler);
|
|
863
890
|
}
|
|
864
891
|
let { args, child, optionsValue } = parseMethodArgs(argArray);
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
return new Proxy(targetSelection.addField(field, args, child, optionsValue), handler);
|
|
892
|
+
const declaredArgTypeMap = targetSelection.schemaType.fields.get(field)?.argGraphQLTypeMap;
|
|
893
|
+
const resolvedArgs = resolveAutoPropagatedArgs(declaredArgTypeMap, args);
|
|
894
|
+
return new Proxy(targetSelection.addField(field, resolvedArgs, child, optionsValue), handler);
|
|
870
895
|
} };
|
|
871
896
|
};
|
|
872
897
|
const DUMMY = () => {};
|
package/dist/index.d.cts
CHANGED
|
@@ -74,18 +74,48 @@ declare const createSchemaType: <E extends string>(name: E, category: SchemaType
|
|
|
74
74
|
//#endregion
|
|
75
75
|
//#region src/runtime/parameter.d.ts
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Runtime marker for `ParameterRef`.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
79
|
+
* We use a unique symbol instead of string keys to avoid accidental collision
|
|
80
|
+
* with user objects passed as argument literals.
|
|
81
81
|
*/
|
|
82
82
|
declare const __marker: unique symbol;
|
|
83
83
|
declare class ParameterRef<TName extends string> {
|
|
84
|
+
/** GraphQL variable name without `$` prefix. */
|
|
84
85
|
readonly name: TName;
|
|
85
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Optional GraphQL type annotation (e.g. `Boolean!`, `[String!]`).
|
|
88
|
+
*
|
|
89
|
+
* - Field argument position: usually omitted, type can be inferred from
|
|
90
|
+
* schema `argGraphQLTypeMap`.
|
|
91
|
+
* - Directive/nested position: usually required to register variable type.
|
|
92
|
+
*/
|
|
93
|
+
readonly explicitType?: string | undefined;
|
|
86
94
|
readonly [__marker] = true;
|
|
87
95
|
private constructor();
|
|
88
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Represents a GraphQL variable reference used in DSL argument objects.
|
|
98
|
+
*
|
|
99
|
+
* Example:
|
|
100
|
+
* - `id: ParameterRef.of("postId")` -> `id: $postId`
|
|
101
|
+
*
|
|
102
|
+
* Main use cases:
|
|
103
|
+
* 1. Rename/bind a field argument to a different variable name.
|
|
104
|
+
* 2. Explicitly annotate variable type when runtime cannot infer it from a
|
|
105
|
+
* field argument position (for example directive args or nested literals).
|
|
106
|
+
*
|
|
107
|
+
* When `explicitType` is NOT needed:
|
|
108
|
+
* - Field arg slot with schema type:
|
|
109
|
+
* `q.user({ id: ParameterRef.of("userId") }, (u) => u.id)`
|
|
110
|
+
* `id` type is inferred from schema (`ID!`).
|
|
111
|
+
*
|
|
112
|
+
* When `explicitType` IS needed:
|
|
113
|
+
* - Directive arg slot:
|
|
114
|
+
* `node.$directive("include", { if: ParameterRef.of("withEmail", "Boolean!") })`
|
|
115
|
+
* - Nested input slot without direct arg type context:
|
|
116
|
+
* `q.search({ filter: { keyword: ParameterRef.of("kw", "String!") } }, ...)`
|
|
117
|
+
*/
|
|
118
|
+
static of<TName extends string>(name: TName, explicitType?: string): ParameterRef<TName>;
|
|
89
119
|
}
|
|
90
120
|
type AcceptableVariables<T extends object> = { [K in keyof T]: T[K] | ParameterRef<string> };
|
|
91
121
|
type UnresolvedVariables<T, TVariables> = ReversedType<UnresolvedNames<UnresolvedRefs<T>>, TVariables>;
|
|
@@ -128,7 +158,7 @@ interface SelectionRuntime<E extends string = string> {
|
|
|
128
158
|
readonly operationName?: string;
|
|
129
159
|
readonly fieldMap: ReadonlyMap<string, FieldSelection>;
|
|
130
160
|
readonly directiveMap: ReadonlyMap<string, DirectiveArgs>;
|
|
131
|
-
readonly variableTypeMap: ReadonlyMap<string,
|
|
161
|
+
readonly variableTypeMap: ReadonlyMap<string, VariableTypeRegistration>;
|
|
132
162
|
findField(fieldKey: string): FieldSelection | undefined;
|
|
133
163
|
findFieldsByName(fieldName: string): readonly FieldSelection[];
|
|
134
164
|
findFieldByName(fieldName: string): FieldSelection | undefined;
|
|
@@ -141,6 +171,10 @@ type ShapeOf<F> = F extends Selection<string, infer M, object> ? M : never;
|
|
|
141
171
|
type VariablesOf<T> = T extends Selection<string, object, infer TVariables> ? TVariables : never;
|
|
142
172
|
type Expand<T> = T extends ReadonlyArray<infer U> ? ReadonlyArray<Expand<U>> : T extends Array<infer U> ? Array<Expand<U>> : T extends object ? { [K in keyof T]: Expand<T[K]> } : T;
|
|
143
173
|
type ValueOrThunk<T> = T | (() => T);
|
|
174
|
+
interface VariableTypeRegistration {
|
|
175
|
+
readonly typeName: string;
|
|
176
|
+
readonly source: string;
|
|
177
|
+
}
|
|
144
178
|
interface FieldSelection {
|
|
145
179
|
readonly name: string;
|
|
146
180
|
readonly argGraphQLTypes?: ReadonlyMap<string, string>;
|
|
@@ -252,7 +286,7 @@ declare class SelectionImpl<E extends string, T extends object, TVariables exten
|
|
|
252
286
|
withOperationName<F extends SelectionImpl<string, object, object>>(operationName?: string): F;
|
|
253
287
|
get fieldMap(): ReadonlyMap<string, FieldSelection>;
|
|
254
288
|
get directiveMap(): ReadonlyMap<string, DirectiveArgs>;
|
|
255
|
-
get variableTypeMap(): ReadonlyMap<string,
|
|
289
|
+
get variableTypeMap(): ReadonlyMap<string, VariableTypeRegistration>;
|
|
256
290
|
findField(fieldKey: string): FieldSelection | undefined;
|
|
257
291
|
findFieldsByName(fieldName: string): readonly FieldSelection[];
|
|
258
292
|
findFieldByName(fieldName: string): FieldSelection | undefined;
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/runtime/schema.ts","../src/runtime/parameter.ts","../src/runtime/field-options.ts","../src/runtime/types.ts","../src/runtime/enum-metadata.ts","../src/runtime/selection.ts","../src/runtime/proxy.ts","../src/runtime/text-builder.ts","../src/runtime/cyrb53.ts"],"mappings":";;AAYA;;;;;AAcA;;;;KAdY,kBAAA;AAqBZ;;;;;;;;;;;;AAAA,KAPY,mBAAA;;;;UAOK,UAAA;EAMN;EAAA,SAJA,IAAA,EAAM,CAAA;EAMN;EAAA,SAJA,QAAA,EAAU,kBAAA;EAIqB;EAAA,SAF/B,UAAA,WAAqB,UAAA;EAIb;EAAA,SAFR,SAAA,EAAW,WAAA,SAAoB,WAAA;EAEQ;EAAA,SAAvC,MAAA,EAAQ,WAAA,SAAoB,WAAA;AAAA;;;;UAMtB,WAAA;EAIN;EAAA,SAFA,IAAA;EAIA;EAAA,SAFA,QAAA,EAAU,mBAAA;EAIV;EAAA,SAFA,iBAAA,EAAmB,WAAA;EAMnB;EAAA,SAJA,cAAA;EAQA;EAAA,SANA,QAAA;EAMa;EAAA,SAJb,aAAA;EAsCV;EAAA,SApCU,UAAA;EAUT;EAAA,SARS,aAAA;AAAA;AAAA,cAOE,2BAAA,GACX,QAAA,aACC,UAAA;AAAA,cA2BU,yBAAA,GACX,QAAA,UACA,OAAA,QAAe,UAAA;AAAA,KASZ,eAAA;EAAA,SAGU,IAAA;EAAA,SACA,QAAA,EAAU,mBAAA;EAAA,SACV,WAAA;EAAA,SACA,iBAAA;IAAA,UAAgC,GAAA;EAAA;EAAA,SAChC,cAAA;AAAA;AAAA,cAKF,gBAAA,qBACX,IAAA,EAAM,CAAA,EACN,QAAA,EAAU,kBAAA,EACV,UAAA,WAAqB,UAAA,IACrB,cAAA,WAAyB,eAAA,OACxB,UAAA,CAAW,CAAA;;;;AArHd;;;;;cCNa,QAAA;AAAA,cAEA,YAAA
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/runtime/schema.ts","../src/runtime/parameter.ts","../src/runtime/field-options.ts","../src/runtime/types.ts","../src/runtime/enum-metadata.ts","../src/runtime/selection.ts","../src/runtime/proxy.ts","../src/runtime/text-builder.ts","../src/runtime/cyrb53.ts"],"mappings":";;AAYA;;;;;AAcA;;;;KAdY,kBAAA;AAqBZ;;;;;;;;;;;;AAAA,KAPY,mBAAA;;;;UAOK,UAAA;EAMN;EAAA,SAJA,IAAA,EAAM,CAAA;EAMN;EAAA,SAJA,QAAA,EAAU,kBAAA;EAIqB;EAAA,SAF/B,UAAA,WAAqB,UAAA;EAIb;EAAA,SAFR,SAAA,EAAW,WAAA,SAAoB,WAAA;EAEQ;EAAA,SAAvC,MAAA,EAAQ,WAAA,SAAoB,WAAA;AAAA;;;;UAMtB,WAAA;EAIN;EAAA,SAFA,IAAA;EAIA;EAAA,SAFA,QAAA,EAAU,mBAAA;EAIV;EAAA,SAFA,iBAAA,EAAmB,WAAA;EAMnB;EAAA,SAJA,cAAA;EAQA;EAAA,SANA,QAAA;EAMa;EAAA,SAJb,aAAA;EAsCV;EAAA,SApCU,UAAA;EAUT;EAAA,SARS,aAAA;AAAA;AAAA,cAOE,2BAAA,GACX,QAAA,aACC,UAAA;AAAA,cA2BU,yBAAA,GACX,QAAA,UACA,OAAA,QAAe,UAAA;AAAA,KASZ,eAAA;EAAA,SAGU,IAAA;EAAA,SACA,QAAA,EAAU,mBAAA;EAAA,SACV,WAAA;EAAA,SACA,iBAAA;IAAA,UAAgC,GAA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,MAAA;cAEY,MAAA;EAE7B,IAAA,CAAK,KAAA;EAsBL,KAAA,CAAM,OAAA,EAAS,YAAA,EAAc,MAAA;EA0B7B,SAAA,CAAU,KAAA;EAWV,QAAA,CAAA;EAAA,QAIQ,WAAA;EAAA,QAOA,SAAA;AAAA;;;cCzGG,MAAA,GAAU,GAAA,UAAa,IAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -74,18 +74,48 @@ declare const createSchemaType: <E extends string>(name: E, category: SchemaType
|
|
|
74
74
|
//#endregion
|
|
75
75
|
//#region src/runtime/parameter.d.ts
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Runtime marker for `ParameterRef`.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
79
|
+
* We use a unique symbol instead of string keys to avoid accidental collision
|
|
80
|
+
* with user objects passed as argument literals.
|
|
81
81
|
*/
|
|
82
82
|
declare const __marker: unique symbol;
|
|
83
83
|
declare class ParameterRef<TName extends string> {
|
|
84
|
+
/** GraphQL variable name without `$` prefix. */
|
|
84
85
|
readonly name: TName;
|
|
85
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Optional GraphQL type annotation (e.g. `Boolean!`, `[String!]`).
|
|
88
|
+
*
|
|
89
|
+
* - Field argument position: usually omitted, type can be inferred from
|
|
90
|
+
* schema `argGraphQLTypeMap`.
|
|
91
|
+
* - Directive/nested position: usually required to register variable type.
|
|
92
|
+
*/
|
|
93
|
+
readonly explicitType?: string | undefined;
|
|
86
94
|
readonly [__marker] = true;
|
|
87
95
|
private constructor();
|
|
88
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Represents a GraphQL variable reference used in DSL argument objects.
|
|
98
|
+
*
|
|
99
|
+
* Example:
|
|
100
|
+
* - `id: ParameterRef.of("postId")` -> `id: $postId`
|
|
101
|
+
*
|
|
102
|
+
* Main use cases:
|
|
103
|
+
* 1. Rename/bind a field argument to a different variable name.
|
|
104
|
+
* 2. Explicitly annotate variable type when runtime cannot infer it from a
|
|
105
|
+
* field argument position (for example directive args or nested literals).
|
|
106
|
+
*
|
|
107
|
+
* When `explicitType` is NOT needed:
|
|
108
|
+
* - Field arg slot with schema type:
|
|
109
|
+
* `q.user({ id: ParameterRef.of("userId") }, (u) => u.id)`
|
|
110
|
+
* `id` type is inferred from schema (`ID!`).
|
|
111
|
+
*
|
|
112
|
+
* When `explicitType` IS needed:
|
|
113
|
+
* - Directive arg slot:
|
|
114
|
+
* `node.$directive("include", { if: ParameterRef.of("withEmail", "Boolean!") })`
|
|
115
|
+
* - Nested input slot without direct arg type context:
|
|
116
|
+
* `q.search({ filter: { keyword: ParameterRef.of("kw", "String!") } }, ...)`
|
|
117
|
+
*/
|
|
118
|
+
static of<TName extends string>(name: TName, explicitType?: string): ParameterRef<TName>;
|
|
89
119
|
}
|
|
90
120
|
type AcceptableVariables<T extends object> = { [K in keyof T]: T[K] | ParameterRef<string> };
|
|
91
121
|
type UnresolvedVariables<T, TVariables> = ReversedType<UnresolvedNames<UnresolvedRefs<T>>, TVariables>;
|
|
@@ -128,7 +158,7 @@ interface SelectionRuntime<E extends string = string> {
|
|
|
128
158
|
readonly operationName?: string;
|
|
129
159
|
readonly fieldMap: ReadonlyMap<string, FieldSelection>;
|
|
130
160
|
readonly directiveMap: ReadonlyMap<string, DirectiveArgs>;
|
|
131
|
-
readonly variableTypeMap: ReadonlyMap<string,
|
|
161
|
+
readonly variableTypeMap: ReadonlyMap<string, VariableTypeRegistration>;
|
|
132
162
|
findField(fieldKey: string): FieldSelection | undefined;
|
|
133
163
|
findFieldsByName(fieldName: string): readonly FieldSelection[];
|
|
134
164
|
findFieldByName(fieldName: string): FieldSelection | undefined;
|
|
@@ -141,6 +171,10 @@ type ShapeOf<F> = F extends Selection<string, infer M, object> ? M : never;
|
|
|
141
171
|
type VariablesOf<T> = T extends Selection<string, object, infer TVariables> ? TVariables : never;
|
|
142
172
|
type Expand<T> = T extends ReadonlyArray<infer U> ? ReadonlyArray<Expand<U>> : T extends Array<infer U> ? Array<Expand<U>> : T extends object ? { [K in keyof T]: Expand<T[K]> } : T;
|
|
143
173
|
type ValueOrThunk<T> = T | (() => T);
|
|
174
|
+
interface VariableTypeRegistration {
|
|
175
|
+
readonly typeName: string;
|
|
176
|
+
readonly source: string;
|
|
177
|
+
}
|
|
144
178
|
interface FieldSelection {
|
|
145
179
|
readonly name: string;
|
|
146
180
|
readonly argGraphQLTypes?: ReadonlyMap<string, string>;
|
|
@@ -252,7 +286,7 @@ declare class SelectionImpl<E extends string, T extends object, TVariables exten
|
|
|
252
286
|
withOperationName<F extends SelectionImpl<string, object, object>>(operationName?: string): F;
|
|
253
287
|
get fieldMap(): ReadonlyMap<string, FieldSelection>;
|
|
254
288
|
get directiveMap(): ReadonlyMap<string, DirectiveArgs>;
|
|
255
|
-
get variableTypeMap(): ReadonlyMap<string,
|
|
289
|
+
get variableTypeMap(): ReadonlyMap<string, VariableTypeRegistration>;
|
|
256
290
|
findField(fieldKey: string): FieldSelection | undefined;
|
|
257
291
|
findFieldsByName(fieldName: string): readonly FieldSelection[];
|
|
258
292
|
findFieldByName(fieldName: string): FieldSelection | undefined;
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/runtime/schema.ts","../src/runtime/parameter.ts","../src/runtime/field-options.ts","../src/runtime/types.ts","../src/runtime/enum-metadata.ts","../src/runtime/selection.ts","../src/runtime/proxy.ts","../src/runtime/text-builder.ts","../src/runtime/cyrb53.ts"],"mappings":";;AAYA;;;;;AAcA;;;;KAdY,kBAAA;AAqBZ;;;;;;;;;;;;AAAA,KAPY,mBAAA;;;;UAOK,UAAA;EAMN;EAAA,SAJA,IAAA,EAAM,CAAA;EAMN;EAAA,SAJA,QAAA,EAAU,kBAAA;EAIqB;EAAA,SAF/B,UAAA,WAAqB,UAAA;EAIb;EAAA,SAFR,SAAA,EAAW,WAAA,SAAoB,WAAA;EAEQ;EAAA,SAAvC,MAAA,EAAQ,WAAA,SAAoB,WAAA;AAAA;;;;UAMtB,WAAA;EAIN;EAAA,SAFA,IAAA;EAIA;EAAA,SAFA,QAAA,EAAU,mBAAA;EAIV;EAAA,SAFA,iBAAA,EAAmB,WAAA;EAMnB;EAAA,SAJA,cAAA;EAQA;EAAA,SANA,QAAA;EAMa;EAAA,SAJb,aAAA;EAsCV;EAAA,SApCU,UAAA;EAUT;EAAA,SARS,aAAA;AAAA;AAAA,cAOE,2BAAA,GACX,QAAA,aACC,UAAA;AAAA,cA2BU,yBAAA,GACX,QAAA,UACA,OAAA,QAAe,UAAA;AAAA,KASZ,eAAA;EAAA,SAGU,IAAA;EAAA,SACA,QAAA,EAAU,mBAAA;EAAA,SACV,WAAA;EAAA,SACA,iBAAA;IAAA,UAAgC,GAAA;EAAA;EAAA,SAChC,cAAA;AAAA;AAAA,cAKF,gBAAA,qBACX,IAAA,EAAM,CAAA,EACN,QAAA,EAAU,kBAAA,EACV,UAAA,WAAqB,UAAA,IACrB,cAAA,WAAyB,eAAA,OACxB,UAAA,CAAW,CAAA;;;;AArHd;;;;;cCNa,QAAA;AAAA,cAEA,YAAA
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/runtime/schema.ts","../src/runtime/parameter.ts","../src/runtime/field-options.ts","../src/runtime/types.ts","../src/runtime/enum-metadata.ts","../src/runtime/selection.ts","../src/runtime/proxy.ts","../src/runtime/text-builder.ts","../src/runtime/cyrb53.ts"],"mappings":";;AAYA;;;;;AAcA;;;;KAdY,kBAAA;AAqBZ;;;;;;;;;;;;AAAA,KAPY,mBAAA;;;;UAOK,UAAA;EAMN;EAAA,SAJA,IAAA,EAAM,CAAA;EAMN;EAAA,SAJA,QAAA,EAAU,kBAAA;EAIqB;EAAA,SAF/B,UAAA,WAAqB,UAAA;EAIb;EAAA,SAFR,SAAA,EAAW,WAAA,SAAoB,WAAA;EAEQ;EAAA,SAAvC,MAAA,EAAQ,WAAA,SAAoB,WAAA;AAAA;;;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,QAcA,UAAA;AAAA;AAAA,cAKG,iBAAA,aAA+B,SAAA,0BAC1C,SAAA,EAAW,CAAA,EACX,aAAA,cACC,CAAA;;;cCrTU,eAAA,+BAED,SAAA,CAAU,CAAA,mBAEpB,UAAA,EAAY,UAAA,CAAW,CAAA,GACvB,iBAAA,EAAmB,iBAAA,EACnB,gBAAA,2BACC,CAAA;;;KC9BS,SAAA;AAAA,UAEK,YAAA;EAAA,SACN,IAAA,EAAM,SAAA;EAAA,SACN,UAAA;EAAA,SACA,SAAA;EAAA,SACA,MAAA;EAAA,SACA,MAAA;AAAA;AAAA,cAqBE,WAAA;EAAA,iBAKkB,MAAA;EAAA,QAJrB,MAAA;EAAA,QACA,SAAA;EAAA,iBACS,MAAA;cAEY,MAAA;EAE7B,IAAA,CAAK,KAAA;EAsBL,KAAA,CAAM,OAAA,EAAS,YAAA,EAAc,MAAA;EA0B7B,SAAA,CAAU,KAAA;EAWV,QAAA,CAAA;EAAA,QAIQ,WAAA;EAAA,QAOA,SAAA;AAAA;;;cCzGG,MAAA,GAAU,GAAA,UAAa,IAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -102,21 +102,43 @@ const registerSchemaType = (type) => {
|
|
|
102
102
|
//#endregion
|
|
103
103
|
//#region src/runtime/parameter.ts
|
|
104
104
|
/**
|
|
105
|
-
*
|
|
105
|
+
* Runtime marker for `ParameterRef`.
|
|
106
106
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
107
|
+
* We use a unique symbol instead of string keys to avoid accidental collision
|
|
108
|
+
* with user objects passed as argument literals.
|
|
109
109
|
*/
|
|
110
110
|
const __marker = Symbol("__parameter_ref_marker");
|
|
111
111
|
var ParameterRef = class ParameterRef {
|
|
112
112
|
[__marker] = true;
|
|
113
|
-
constructor(name,
|
|
113
|
+
constructor(name, explicitType) {
|
|
114
114
|
this.name = name;
|
|
115
|
-
this.
|
|
115
|
+
this.explicitType = explicitType;
|
|
116
116
|
if (name.startsWith("$")) throw new Error("parameter name cannot start with '$'");
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Represents a GraphQL variable reference used in DSL argument objects.
|
|
120
|
+
*
|
|
121
|
+
* Example:
|
|
122
|
+
* - `id: ParameterRef.of("postId")` -> `id: $postId`
|
|
123
|
+
*
|
|
124
|
+
* Main use cases:
|
|
125
|
+
* 1. Rename/bind a field argument to a different variable name.
|
|
126
|
+
* 2. Explicitly annotate variable type when runtime cannot infer it from a
|
|
127
|
+
* field argument position (for example directive args or nested literals).
|
|
128
|
+
*
|
|
129
|
+
* When `explicitType` is NOT needed:
|
|
130
|
+
* - Field arg slot with schema type:
|
|
131
|
+
* `q.user({ id: ParameterRef.of("userId") }, (u) => u.id)`
|
|
132
|
+
* `id` type is inferred from schema (`ID!`).
|
|
133
|
+
*
|
|
134
|
+
* When `explicitType` IS needed:
|
|
135
|
+
* - Directive arg slot:
|
|
136
|
+
* `node.$directive("include", { if: ParameterRef.of("withEmail", "Boolean!") })`
|
|
137
|
+
* - Nested input slot without direct arg type context:
|
|
138
|
+
* `q.search({ filter: { keyword: ParameterRef.of("kw", "String!") } }, ...)`
|
|
139
|
+
*/
|
|
140
|
+
static of(name, explicitType) {
|
|
141
|
+
return new ParameterRef(name, explicitType);
|
|
120
142
|
}
|
|
121
143
|
};
|
|
122
144
|
|
|
@@ -412,7 +434,7 @@ var SerializeContext = class SerializeContext {
|
|
|
412
434
|
t(name);
|
|
413
435
|
if (field.argGraphQLTypes) {
|
|
414
436
|
const meta = sel._enumInputMetadata;
|
|
415
|
-
this.acceptArgs(field.args, field.argGraphQLTypes, meta);
|
|
437
|
+
this.acceptArgs(field.args, field.argGraphQLTypes, meta, `field '${runtime.schemaType.name}.${name}'`);
|
|
416
438
|
}
|
|
417
439
|
this.acceptDirectives(field.fieldOptionsValue?.directives);
|
|
418
440
|
}
|
|
@@ -454,10 +476,10 @@ var SerializeContext = class SerializeContext {
|
|
|
454
476
|
if (!directives) return;
|
|
455
477
|
for (const [directive, args] of directives) {
|
|
456
478
|
this.writer.text(`\n@${directive}`);
|
|
457
|
-
this.acceptArgs(args);
|
|
479
|
+
this.acceptArgs(args, void 0, void 0, `directive '@${directive}'`);
|
|
458
480
|
}
|
|
459
481
|
}
|
|
460
|
-
acceptArgs(args, argGraphQLTypeMap, enumInputMetadata) {
|
|
482
|
+
acceptArgs(args, argGraphQLTypeMap, enumInputMetadata, argContext = "argument") {
|
|
461
483
|
if (!args) return;
|
|
462
484
|
const t = this.writer.text.bind(this.writer);
|
|
463
485
|
let hasField;
|
|
@@ -479,7 +501,7 @@ var SerializeContext = class SerializeContext {
|
|
|
479
501
|
const typeName = argGraphQLTypeMap.get(argName);
|
|
480
502
|
if (typeName !== void 0) if (arg?.[__marker]) {
|
|
481
503
|
const ref = arg;
|
|
482
|
-
this.registerVariableType(ref, typeName, false,
|
|
504
|
+
this.registerVariableType(ref, typeName, false, `${argContext}.${argName}`);
|
|
483
505
|
t(`${argName}: $${ref.name}`);
|
|
484
506
|
} else {
|
|
485
507
|
t(`${argName}: `);
|
|
@@ -488,8 +510,8 @@ var SerializeContext = class SerializeContext {
|
|
|
488
510
|
else throw new Error(`Unknown argument '${argName}'`);
|
|
489
511
|
} else if (arg?.[__marker]) {
|
|
490
512
|
const ref = arg;
|
|
491
|
-
if (!ref.
|
|
492
|
-
this.registerVariableType(ref, ref.
|
|
513
|
+
if (!ref.explicitType) throw new Error(`Cannot infer the type of directive argument '${ref.name}'; an explicit type annotation is required.`);
|
|
514
|
+
this.registerVariableType(ref, ref.explicitType, false, `${argContext}.${argName}`);
|
|
493
515
|
t(`${argName}: $${ref.name}`);
|
|
494
516
|
} else {
|
|
495
517
|
t(`${argName}: `);
|
|
@@ -498,7 +520,7 @@ var SerializeContext = class SerializeContext {
|
|
|
498
520
|
}
|
|
499
521
|
});
|
|
500
522
|
}
|
|
501
|
-
acceptLiteral(value, metaType,
|
|
523
|
+
acceptLiteral(value, metaType, explicitType) {
|
|
502
524
|
const t = this.writer.text.bind(this.writer);
|
|
503
525
|
if (value == null) {
|
|
504
526
|
t("null");
|
|
@@ -518,8 +540,8 @@ var SerializeContext = class SerializeContext {
|
|
|
518
540
|
}
|
|
519
541
|
if (value?.[__marker]) {
|
|
520
542
|
const ref = value;
|
|
521
|
-
if (!
|
|
522
|
-
this.registerVariableType(ref,
|
|
543
|
+
if (!explicitType && !ref.explicitType) throw new Error(`Cannot infer the nested type of argument '${ref.name}'; an explicit type annotation is required.`);
|
|
544
|
+
this.registerVariableType(ref, explicitType, true, "nested argument");
|
|
523
545
|
t(`$${ref.name}`);
|
|
524
546
|
return;
|
|
525
547
|
}
|
|
@@ -528,7 +550,7 @@ var SerializeContext = class SerializeContext {
|
|
|
528
550
|
return;
|
|
529
551
|
}
|
|
530
552
|
if (Array.isArray(value) || value instanceof Set) {
|
|
531
|
-
const elementGraphQLTypeName = SerializeContext.elementTypeName(
|
|
553
|
+
const elementGraphQLTypeName = SerializeContext.elementTypeName(explicitType);
|
|
532
554
|
this.writer.scope({ type: "array" }, () => {
|
|
533
555
|
for (const e of value) {
|
|
534
556
|
this.writer.separator(", ");
|
|
@@ -553,12 +575,15 @@ var SerializeContext = class SerializeContext {
|
|
|
553
575
|
});
|
|
554
576
|
}
|
|
555
577
|
registerVariableType(ref, expectedTypeName, allowImplicitFromRef = false, context = "argument") {
|
|
556
|
-
const typeName = expectedTypeName ?? (allowImplicitFromRef ? ref.
|
|
557
|
-
if (!typeName) throw new Error(`
|
|
558
|
-
if (ref.
|
|
578
|
+
const typeName = expectedTypeName ?? (allowImplicitFromRef ? ref.explicitType : void 0);
|
|
579
|
+
if (!typeName) throw new Error(`Cannot infer the type of directive argument '${ref.name}'; an explicit type annotation is required.`);
|
|
580
|
+
if (ref.explicitType && ref.explicitType !== typeName) throw new Error(`Variable '$${ref.name}' has conflicting GraphQL types at ${context}: inferred '${typeName}', but ParameterRef declares '${ref.explicitType}'`);
|
|
559
581
|
const existing = this.variableTypeMap.get(ref.name);
|
|
560
|
-
if (existing && existing !== typeName) throw new Error(`
|
|
561
|
-
this.variableTypeMap.set(ref.name,
|
|
582
|
+
if (existing && existing.typeName !== typeName) throw new Error(`Variable '$${ref.name}' has conflicting GraphQL types: first '${existing.typeName}' at ${existing.source}, then '${typeName}' at ${context}`);
|
|
583
|
+
this.variableTypeMap.set(ref.name, {
|
|
584
|
+
typeName,
|
|
585
|
+
source: context
|
|
586
|
+
});
|
|
562
587
|
}
|
|
563
588
|
static enumMetaType(meta, typeName) {
|
|
564
589
|
if (!meta || !typeName) return void 0;
|
|
@@ -718,13 +743,15 @@ const createChildSelectionProxy = (schemaType, enumInputMetadata) => {
|
|
|
718
743
|
void 0
|
|
719
744
|
], false, ""), proxyHandler(schemaType));
|
|
720
745
|
};
|
|
721
|
-
const
|
|
722
|
-
if (!
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
746
|
+
const resolveAutoPropagatedArgs = (declaredArgTypeMap, providedArgs) => {
|
|
747
|
+
if (!declaredArgTypeMap?.size) return providedArgs;
|
|
748
|
+
const autoArgs = {};
|
|
749
|
+
for (const argName of declaredArgTypeMap.keys()) autoArgs[argName] = ParameterRef.of(argName);
|
|
750
|
+
if (!providedArgs) return autoArgs;
|
|
751
|
+
return {
|
|
752
|
+
...autoArgs,
|
|
753
|
+
...providedArgs
|
|
754
|
+
};
|
|
728
755
|
};
|
|
729
756
|
const resolveAssociationTarget = (fieldName, fieldTargetTypeName, ownerTypeName) => {
|
|
730
757
|
if (!fieldTargetTypeName) throw new Error(`Field "${fieldName}" has no target type`);
|
|
@@ -791,8 +818,8 @@ const proxyHandler = (schemaType) => {
|
|
|
791
818
|
let { args, childSelectionFactory, childSelection } = parseAssociationArgs(argArray);
|
|
792
819
|
if (childSelectionFactory) childSelection = childSelectionFactory(createChildSelectionProxy(targetSchemaType, target._enumInputMetadata));
|
|
793
820
|
if (!childSelection) throw new Error(`Field "${p}" requires a child selection`);
|
|
794
|
-
|
|
795
|
-
return new Proxy(target.addField(p,
|
|
821
|
+
const resolvedArgs = resolveAutoPropagatedArgs(field.argGraphQLTypeMap, args);
|
|
822
|
+
return new Proxy(target.addField(p, resolvedArgs, childSelection), handler);
|
|
796
823
|
};
|
|
797
824
|
if (field.isFunction) return new Proxy(DUMMY, methodHandler(target, handler, p));
|
|
798
825
|
return new Proxy(target.addField(p), handler);
|
|
@@ -860,11 +887,9 @@ const methodHandler = (targetSelection, handler, field) => {
|
|
|
860
887
|
return new Proxy(current, handler);
|
|
861
888
|
}
|
|
862
889
|
let { args, child, optionsValue } = parseMethodArgs(argArray);
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
}
|
|
867
|
-
return new Proxy(targetSelection.addField(field, args, child, optionsValue), handler);
|
|
890
|
+
const declaredArgTypeMap = targetSelection.schemaType.fields.get(field)?.argGraphQLTypeMap;
|
|
891
|
+
const resolvedArgs = resolveAutoPropagatedArgs(declaredArgTypeMap, args);
|
|
892
|
+
return new Proxy(targetSelection.addField(field, resolvedArgs, child, optionsValue), handler);
|
|
868
893
|
} };
|
|
869
894
|
};
|
|
870
895
|
const DUMMY = () => {};
|