@gqloom/core 0.3.0 → 0.5.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/dist/index.js CHANGED
@@ -6,8 +6,16 @@ var __export = (target, all) => {
6
6
 
7
7
  // src/resolver/silk.ts
8
8
  import {
9
- GraphQLNonNull,
10
- GraphQLList
9
+ GraphQLList,
10
+ GraphQLNonNull
11
+ } from "graphql";
12
+
13
+ // src/schema/weaver-context.ts
14
+ import {
15
+ isEnumType,
16
+ isObjectType,
17
+ isScalarType,
18
+ isUnionType
11
19
  } from "graphql";
12
20
 
13
21
  // src/utils/symbols.ts
@@ -16,22 +24,148 @@ __export(symbols_exports, {
16
24
  CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
17
25
  FIELD_HIDDEN: () => FIELD_HIDDEN,
18
26
  GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
19
- PARSE: () => PARSE,
20
27
  RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
21
28
  WEAVER_CONFIG: () => WEAVER_CONFIG
22
29
  });
23
30
  var GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
24
- var PARSE = Symbol.for("gqloom.parse");
25
31
  var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
26
32
  var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
27
33
  var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
28
34
  var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
29
35
 
36
+ // src/schema/weaver-context.ts
37
+ var ref;
38
+ var names = /* @__PURE__ */ new WeakMap();
39
+ function initWeaverContext() {
40
+ return {
41
+ id: initWeaverContext.increasingID++,
42
+ loomObjectMap: /* @__PURE__ */ new Map(),
43
+ loomUnionMap: /* @__PURE__ */ new Map(),
44
+ inputMap: /* @__PURE__ */ new Map(),
45
+ interfaceMap: /* @__PURE__ */ new Map(),
46
+ configs: /* @__PURE__ */ new Map(),
47
+ getConfig(key) {
48
+ return this.configs.get(key);
49
+ },
50
+ setConfig(config) {
51
+ const key = config[WEAVER_CONFIG];
52
+ this.configs.set(key, config);
53
+ },
54
+ deleteConfig(key) {
55
+ this.configs.delete(key);
56
+ },
57
+ names,
58
+ namedTypes: /* @__PURE__ */ new Map(),
59
+ memoNamedType(gqlTypeValue) {
60
+ const gqlType = gqlTypeValue;
61
+ if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) {
62
+ this.namedTypes.set(gqlType.name, gqlType);
63
+ }
64
+ return gqlTypeValue;
65
+ },
66
+ getNamedType(name) {
67
+ return this.namedTypes.get(name);
68
+ },
69
+ vendorWeavers: /* @__PURE__ */ new Map()
70
+ };
71
+ }
72
+ initWeaverContext.increasingID = 1;
73
+ var weaverContext = {
74
+ get id() {
75
+ return ref?.id;
76
+ },
77
+ get loomObjectMap() {
78
+ return ref?.loomObjectMap;
79
+ },
80
+ get loomUnionMap() {
81
+ return ref?.loomUnionMap;
82
+ },
83
+ get inputMap() {
84
+ return ref?.inputMap;
85
+ },
86
+ get interfaceMap() {
87
+ return ref?.interfaceMap;
88
+ },
89
+ get configs() {
90
+ return ref?.configs;
91
+ },
92
+ get vendorWeavers() {
93
+ return ref?.vendorWeavers;
94
+ },
95
+ getConfig(key) {
96
+ return ref?.getConfig(key);
97
+ },
98
+ setConfig(config) {
99
+ ref?.setConfig(config);
100
+ },
101
+ deleteConfig(key) {
102
+ ref?.deleteConfig(key);
103
+ },
104
+ get value() {
105
+ return ref;
106
+ },
107
+ useConfig(config, callback) {
108
+ const context = weaverContext.value ?? initWeaverContext();
109
+ context.setConfig(config);
110
+ const result = provideWeaverContext(callback, context);
111
+ context.deleteConfig(config[WEAVER_CONFIG]);
112
+ return result;
113
+ },
114
+ names,
115
+ getNamedType(name) {
116
+ return ref?.getNamedType(name);
117
+ },
118
+ memoNamedType(gqlType) {
119
+ return ref?.memoNamedType(gqlType) ?? gqlType;
120
+ },
121
+ GraphQLTypes: /* @__PURE__ */ new WeakMap(),
122
+ getGraphQLType(origin) {
123
+ return this.GraphQLTypes.get(origin);
124
+ },
125
+ memoGraphQLType(origin, gqlType) {
126
+ this.GraphQLTypes.set(origin, gqlType);
127
+ return gqlType;
128
+ }
129
+ };
130
+ function provideWeaverContext(func, value) {
131
+ const lastRef = ref;
132
+ ref = value;
133
+ try {
134
+ return func();
135
+ } finally {
136
+ ref = lastRef;
137
+ }
138
+ }
139
+ provideWeaverContext.inherit = (func) => {
140
+ const weaverContextRef = weaverContext.value;
141
+ return () => provideWeaverContext(func, weaverContextRef);
142
+ };
143
+ function collectNames(...namesList) {
144
+ const namesRecord = {};
145
+ for (const namesItem of namesList) {
146
+ for (const [name, schema] of Object.entries(namesItem)) {
147
+ names.set(schema, name);
148
+ namesRecord[name] = schema;
149
+ }
150
+ }
151
+ return namesRecord;
152
+ }
153
+ function collectName(name, schema) {
154
+ names.set(schema, name);
155
+ return schema;
156
+ }
157
+
30
158
  // src/resolver/silk.ts
31
- function silk(type, parse) {
159
+ function silk(type, validate = (value) => ({
160
+ value: value ?? void 0
161
+ })) {
32
162
  return {
33
163
  [GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
34
- [PARSE]: parse
164
+ "~standard": {
165
+ version: 1,
166
+ vendor: "gqloom.silk",
167
+ validate
168
+ }
35
169
  };
36
170
  }
37
171
  silk.parse = parseSilk;
@@ -41,6 +175,7 @@ silk.list = listSilk;
41
175
  silk.nullable = nullableSilk;
42
176
  function nonNullSilk(origin) {
43
177
  return {
178
+ ...origin,
44
179
  [GET_GRAPHQL_TYPE]: () => {
45
180
  const originType = getGraphQLType(origin);
46
181
  if (originType instanceof GraphQLNonNull) {
@@ -48,12 +183,12 @@ function nonNullSilk(origin) {
48
183
  } else {
49
184
  return new GraphQLNonNull(originType);
50
185
  }
51
- },
52
- [PARSE]: (input) => origin[PARSE]?.(input)
186
+ }
53
187
  };
54
188
  }
55
189
  function listSilk(origin) {
56
190
  return {
191
+ ...origin,
57
192
  [GET_GRAPHQL_TYPE]: () => {
58
193
  let originType = getGraphQLType(origin);
59
194
  if (originType instanceof GraphQLNonNull && originType.ofType instanceof GraphQLList) {
@@ -68,6 +203,7 @@ function listSilk(origin) {
68
203
  }
69
204
  function nullableSilk(origin) {
70
205
  return {
206
+ ...origin,
71
207
  [GET_GRAPHQL_TYPE]: () => {
72
208
  const originType = getGraphQLType(origin);
73
209
  if (originType instanceof GraphQLNonNull) {
@@ -75,21 +211,30 @@ function nullableSilk(origin) {
75
211
  } else {
76
212
  return originType;
77
213
  }
78
- },
79
- [PARSE]: (input) => origin[PARSE]?.(input)
214
+ }
80
215
  };
81
216
  }
82
217
  function getGraphQLType(silk2) {
83
- return silk2[GET_GRAPHQL_TYPE]();
218
+ if (GET_GRAPHQL_TYPE in silk2 && silk2[GET_GRAPHQL_TYPE] != null)
219
+ return silk2[GET_GRAPHQL_TYPE]();
220
+ const vendorWeavers = weaverContext.vendorWeavers;
221
+ if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
222
+ const weaver = vendorWeavers.get(silk2["~standard"].vendor);
223
+ if (weaver == null)
224
+ throw new Error(
225
+ `Schema Weaver for ${silk2["~standard"].vendor} is not found`
226
+ );
227
+ return weaver.getGraphQLType(silk2);
84
228
  }
85
229
  function parseSilk(silk2, input) {
86
- if (silk2[PARSE] == null) return input;
87
- return silk2[PARSE](input);
230
+ return silk2["~standard"].validate(input);
88
231
  }
89
232
  function isSilk(target) {
90
233
  if (typeof target !== "object") return false;
91
234
  if (target == null) return false;
92
- return GET_GRAPHQL_TYPE in target;
235
+ if (GET_GRAPHQL_TYPE in target) return true;
236
+ if (!("~standard" in target)) return false;
237
+ return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
93
238
  }
94
239
 
95
240
  // src/utils/args.ts
@@ -118,13 +263,17 @@ function getFieldOptions({
118
263
  }
119
264
 
120
265
  // src/utils/middleware.ts
121
- function applyMiddlewares(middlewares, resolveFunction, payload) {
266
+ function applyMiddlewares(middlewares, resolveFunction, options) {
122
267
  const next = (index) => {
123
268
  if (index >= middlewares.length) {
124
269
  return resolveFunction();
125
270
  }
126
271
  const middleware = middlewares[index];
127
- return middleware(() => next(index + 1), payload);
272
+ const callableOptions = Object.assign(() => next(index + 1), {
273
+ ...options,
274
+ next: () => next(index + 1)
275
+ });
276
+ return middleware(callableOptions);
128
277
  };
129
278
  return next(0);
130
279
  }
@@ -306,6 +455,7 @@ function markLocation(message, ...locations) {
306
455
  }
307
456
 
308
457
  // src/resolver/input.ts
458
+ import { GraphQLError } from "graphql";
309
459
  function createInputParser(schema, value) {
310
460
  let result;
311
461
  const parse = async () => {
@@ -322,32 +472,43 @@ function createInputParser(schema, value) {
322
472
  }
323
473
  function parseInputValue(inputSchema, input) {
324
474
  if (inputSchema === void 0) {
325
- return input;
475
+ return { value: input };
326
476
  }
327
477
  if (isSilk(inputSchema)) {
328
- if (typeof inputSchema[symbols_exports.PARSE] === "function") {
329
- return inputSchema[symbols_exports.PARSE](input);
330
- }
331
- return input;
478
+ return inputSchema["~standard"].validate(input);
332
479
  }
333
480
  return parseInputEntries(inputSchema, input);
334
481
  }
335
482
  async function parseInputEntries(inputSchema, input = {}) {
336
483
  const result = {};
484
+ const issues = [];
337
485
  await Promise.all(
338
486
  Object.entries(inputSchema).map(async ([key, value]) => {
339
- if (typeof value[symbols_exports.PARSE] === "function") {
340
- result[key] = await value[symbols_exports.PARSE](input[key]);
341
- } else {
342
- result[key] = input[key];
487
+ const res = await value["~standard"].validate(input[key]);
488
+ if ("value" in res) {
489
+ result[key] = res.value;
490
+ }
491
+ if (res.issues) {
492
+ issues.push(...res.issues.slice());
343
493
  }
344
494
  })
345
495
  );
346
- return result;
496
+ return { value: result, ...issues.length > 0 ? { issues } : null };
497
+ }
498
+ function getStandardValue(result) {
499
+ if (result == null) return result;
500
+ const { issues } = result;
501
+ if (issues?.length) {
502
+ throw new GraphQLError(issues?.[0]?.message ?? "Invalid input", {
503
+ extensions: { issues }
504
+ });
505
+ }
506
+ if ("value" in result) return result.value;
507
+ else throw new GraphQLError("Invalid input");
347
508
  }
348
509
 
349
510
  // src/resolver/resolver.ts
350
- var silkQuery = (output, resolveOrOptions) => {
511
+ var query = (output, resolveOrOptions) => {
351
512
  const options = getOperationOptions(resolveOrOptions);
352
513
  const type = "query";
353
514
  return {
@@ -358,14 +519,14 @@ var silkQuery = (output, resolveOrOptions) => {
358
519
  const parseInput = createInputParser(options.input, inputValue);
359
520
  return applyMiddlewares(
360
521
  compose(extraOptions?.middlewares, options.middlewares),
361
- async () => options.resolve(await parseInput()),
522
+ async () => options.resolve(getStandardValue(await parseInput())),
362
523
  { parseInput, parent: void 0, outputSilk: output, type }
363
524
  );
364
525
  },
365
526
  type
366
527
  };
367
528
  };
368
- var silkMutation = (output, resolveOrOptions) => {
529
+ var mutation = (output, resolveOrOptions) => {
369
530
  const options = getOperationOptions(resolveOrOptions);
370
531
  const type = "mutation";
371
532
  return {
@@ -376,7 +537,7 @@ var silkMutation = (output, resolveOrOptions) => {
376
537
  const parseInput = createInputParser(options.input, inputValue);
377
538
  return applyMiddlewares(
378
539
  compose(extraOptions?.middlewares, options.middlewares),
379
- async () => options.resolve(await parseInput()),
540
+ async () => options.resolve(getStandardValue(await parseInput())),
380
541
  { parseInput, parent: void 0, outputSilk: output, type }
381
542
  );
382
543
  },
@@ -394,21 +555,21 @@ var baseSilkField = (output, resolveOrOptions) => {
394
555
  const parseInput = createInputParser(options.input, inputValue);
395
556
  return applyMiddlewares(
396
557
  compose(extraOptions?.middlewares, options.middlewares),
397
- async () => options.resolve(parent, await parseInput()),
558
+ async () => options.resolve(parent, getStandardValue(await parseInput())),
398
559
  { parseInput, parent, outputSilk: output, type }
399
560
  );
400
561
  },
401
562
  type
402
563
  };
403
564
  };
404
- var silkField = Object.assign(
565
+ var field = Object.assign(
405
566
  baseSilkField,
406
567
  {
407
568
  hidden: FIELD_HIDDEN
408
569
  }
409
570
  );
410
571
  var defaultSubscriptionResolve = (source) => source;
411
- var silkSubscription = (output, subscribeOrOptions) => {
572
+ var subscription = (output, subscribeOrOptions) => {
412
573
  const options = getSubscriptionOptions(subscribeOrOptions);
413
574
  const type = "subscription";
414
575
  return {
@@ -422,7 +583,7 @@ var silkSubscription = (output, subscribeOrOptions) => {
422
583
  extraOptions?.middlewares,
423
584
  options.middlewares
424
585
  ),
425
- async () => options.subscribe(await parseInput()),
586
+ async () => options.subscribe(getStandardValue(await parseInput())),
426
587
  { parseInput, parent: void 0, outputSilk: output, type }
427
588
  );
428
589
  },
@@ -469,7 +630,7 @@ function extraOperationOptions(operation, options) {
469
630
  };
470
631
  }
471
632
  }
472
- var silkResolver = Object.assign(
633
+ var resolver = Object.assign(
473
634
  baseResolver,
474
635
  {
475
636
  of: (parent, operations, options) => baseResolver(
@@ -479,11 +640,11 @@ var silkResolver = Object.assign(
479
640
  }
480
641
  );
481
642
  var loom = {
482
- query: silkQuery,
483
- resolver: silkResolver,
484
- field: silkField,
485
- subscription: silkSubscription,
486
- mutation: silkMutation
643
+ query,
644
+ resolver,
645
+ field,
646
+ subscription,
647
+ mutation
487
648
  };
488
649
 
489
650
  // src/helper/create-loom.ts
@@ -513,7 +674,7 @@ function createFieldFactory(toSilk, isSchema) {
513
674
  const options = getOperationOptions(
514
675
  resolveOrOptions
515
676
  );
516
- return silkField(toSilk(output), {
677
+ return field(toSilk(output), {
517
678
  ...options,
518
679
  input: toSilkInput(options.input, toSilk, isSchema)
519
680
  });
@@ -525,7 +686,7 @@ function createFieldFactory(toSilk, isSchema) {
525
686
  function createQueryFactory(toSilk, isSchema) {
526
687
  return (output, resolveOrOptions) => {
527
688
  const options = getOperationOptions(resolveOrOptions);
528
- return silkQuery(toSilk(output), {
689
+ return query(toSilk(output), {
529
690
  ...options,
530
691
  input: toSilkInput(options.input, toSilk, isSchema)
531
692
  });
@@ -534,7 +695,7 @@ function createQueryFactory(toSilk, isSchema) {
534
695
  function createMutationFactory(toSilk, isSchema) {
535
696
  return (output, resolveOrOptions) => {
536
697
  const options = getOperationOptions(resolveOrOptions);
537
- return silkMutation(toSilk(output), {
698
+ return mutation(toSilk(output), {
538
699
  ...options,
539
700
  input: toSilkInput(options.input, toSilk, isSchema)
540
701
  });
@@ -543,7 +704,7 @@ function createMutationFactory(toSilk, isSchema) {
543
704
  function createSubscriptionFactory(toSilk, isSchema) {
544
705
  return (output, resolveOrOptions) => {
545
706
  const options = getSubscriptionOptions(resolveOrOptions);
546
- return silkSubscription(toSilk(output), {
707
+ return subscription(toSilk(output), {
547
708
  ...options,
548
709
  input: toSilkInput(options.input, toSilk, isSchema)
549
710
  });
@@ -561,153 +722,29 @@ function createLoom(toSilk, isSchema) {
561
722
 
562
723
  // src/schema/object.ts
563
724
  import {
725
+ GraphQLList as GraphQLList3,
726
+ GraphQLNonNull as GraphQLNonNull3,
564
727
  GraphQLObjectType,
728
+ GraphQLUnionType,
565
729
  assertName,
566
- isObjectType as isObjectType3,
567
- resolveObjMapThunk,
568
730
  isListType as isListType2,
569
- GraphQLList as GraphQLList3,
570
- GraphQLNonNull as GraphQLNonNull3,
571
731
  isNonNullType as isNonNullType2,
732
+ isObjectType as isObjectType3,
572
733
  isUnionType as isUnionType3,
573
- GraphQLUnionType
574
- } from "graphql";
575
-
576
- // src/schema/weaver-context.ts
577
- import {
578
- isEnumType,
579
- isObjectType,
580
- isUnionType,
581
- isScalarType
734
+ resolveObjMapThunk
582
735
  } from "graphql";
583
- var ref;
584
- var names = /* @__PURE__ */ new WeakMap();
585
- function initWeaverContext() {
586
- return {
587
- id: initWeaverContext.increasingID++,
588
- loomObjectMap: /* @__PURE__ */ new Map(),
589
- loomUnionMap: /* @__PURE__ */ new Map(),
590
- inputMap: /* @__PURE__ */ new Map(),
591
- interfaceMap: /* @__PURE__ */ new Map(),
592
- configs: /* @__PURE__ */ new Map(),
593
- getConfig(key) {
594
- return this.configs.get(key);
595
- },
596
- setConfig(config) {
597
- const key = config[WEAVER_CONFIG];
598
- this.configs.set(key, config);
599
- },
600
- deleteConfig(key) {
601
- this.configs.delete(key);
602
- },
603
- names,
604
- namedTypes: /* @__PURE__ */ new Map(),
605
- memoNamedType(gqlTypeValue) {
606
- const gqlType = gqlTypeValue;
607
- if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType) || isScalarType(gqlType)) {
608
- this.namedTypes.set(gqlType.name, gqlType);
609
- }
610
- return gqlTypeValue;
611
- },
612
- getNamedType(name) {
613
- return this.namedTypes.get(name);
614
- }
615
- };
616
- }
617
- initWeaverContext.increasingID = 1;
618
- var weaverContext = {
619
- get id() {
620
- return ref?.id;
621
- },
622
- get loomObjectMap() {
623
- return ref?.loomObjectMap;
624
- },
625
- get loomUnionMap() {
626
- return ref?.loomUnionMap;
627
- },
628
- get inputMap() {
629
- return ref?.inputMap;
630
- },
631
- get interfaceMap() {
632
- return ref?.interfaceMap;
633
- },
634
- get configs() {
635
- return ref?.configs;
636
- },
637
- getConfig(key) {
638
- return ref?.getConfig(key);
639
- },
640
- setConfig(config) {
641
- ref?.setConfig(config);
642
- },
643
- deleteConfig(key) {
644
- ref?.deleteConfig(key);
645
- },
646
- get value() {
647
- return ref;
648
- },
649
- useConfig(config, callback) {
650
- const context = weaverContext.value ?? initWeaverContext();
651
- context.setConfig(config);
652
- const result = provideWeaverContext(callback, context);
653
- context.deleteConfig(config[WEAVER_CONFIG]);
654
- return result;
655
- },
656
- names,
657
- getNamedType(name) {
658
- return ref?.getNamedType(name);
659
- },
660
- memoNamedType(gqlType) {
661
- return ref?.memoNamedType(gqlType) ?? gqlType;
662
- },
663
- GraphQLTypes: /* @__PURE__ */ new WeakMap(),
664
- getGraphQLType(origin) {
665
- return this.GraphQLTypes.get(origin);
666
- },
667
- memoGraphQLType(origin, gqlType) {
668
- this.GraphQLTypes.set(origin, gqlType);
669
- return gqlType;
670
- }
671
- };
672
- function provideWeaverContext(func, value) {
673
- const lastRef = ref;
674
- ref = value;
675
- try {
676
- return func();
677
- } finally {
678
- ref = lastRef;
679
- }
680
- }
681
- provideWeaverContext.inherit = (func) => {
682
- const weaverContextRef = weaverContext.value;
683
- return () => provideWeaverContext(func, weaverContextRef);
684
- };
685
- function collectNames(...namesList) {
686
- const namesRecord = {};
687
- for (const namesItem of namesList) {
688
- for (const [name, schema] of Object.entries(namesItem)) {
689
- names.set(schema, name);
690
- namesRecord[name] = schema;
691
- }
692
- }
693
- return namesRecord;
694
- }
695
- function collectName(name, schema) {
696
- names.set(schema, name);
697
- return schema;
698
- }
699
736
 
700
737
  // src/schema/input.ts
701
738
  import {
702
739
  GraphQLInputObjectType,
703
740
  GraphQLList as GraphQLList2,
704
741
  GraphQLNonNull as GraphQLNonNull2,
742
+ isInputObjectType,
705
743
  isInterfaceType,
706
744
  isListType,
707
745
  isNonNullType,
708
746
  isObjectType as isObjectType2,
709
- isUnionType as isUnionType2,
710
- isInputObjectType
747
+ isUnionType as isUnionType2
711
748
  } from "graphql";
712
749
  function inputToArgs(input) {
713
750
  if (input === void 0) return void 0;
@@ -723,11 +760,11 @@ function inputToArgs(input) {
723
760
  throw new Error(`Cannot convert ${inputType.toString()} to input type`);
724
761
  }
725
762
  const args = {};
726
- Object.entries(input).forEach(([name, field]) => {
763
+ Object.entries(input).forEach(([name, field2]) => {
727
764
  tryIn(() => {
728
765
  args[name] = {
729
- ...field,
730
- type: ensureInputType(field)
766
+ ...field2,
767
+ type: ensureInputType(field2)
731
768
  };
732
769
  }, name);
733
770
  });
@@ -805,12 +842,12 @@ var LoomObjectType = class extends GraphQLObjectType {
805
842
  hideField(name) {
806
843
  this.hiddenFields.add(name);
807
844
  }
808
- addField(name, resolver) {
845
+ addField(name, resolver2) {
809
846
  const existing = this.extraFields.get(name);
810
- if (existing && existing !== resolver) {
847
+ if (existing && existing !== resolver2) {
811
848
  throw new Error(`Field ${name} already exists in ${this.name}`);
812
849
  }
813
- this.extraFields.set(name, resolver);
850
+ this.extraFields.set(name, resolver2);
814
851
  }
815
852
  mergeExtensions(extensions) {
816
853
  this.extensions = deepMerge(this.extensions, extensions);
@@ -819,7 +856,7 @@ var LoomObjectType = class extends GraphQLObjectType {
819
856
  getFields() {
820
857
  const fieldsBySuper = super.getFields();
821
858
  Object.values(fieldsBySuper).forEach(
822
- (field) => field.type = this.getCacheType(field.type)
859
+ (field2) => field2.type = this.getCacheType(field2.type)
823
860
  );
824
861
  const extraFields = provideWeaverContext(
825
862
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
@@ -839,47 +876,47 @@ var LoomObjectType = class extends GraphQLObjectType {
839
876
  }
840
877
  mapToFieldConfig(map) {
841
878
  const record = {};
842
- for (const [name, field] of map.entries()) {
843
- record[name] = this.toFieldConfig(field);
879
+ for (const [name, field2] of map.entries()) {
880
+ record[name] = this.toFieldConfig(field2);
844
881
  }
845
882
  return record;
846
883
  }
847
- toFieldConfig(field) {
884
+ toFieldConfig(field2) {
848
885
  try {
849
- const outputType = this.getCacheType(getGraphQLType(field.output));
886
+ const outputType = this.getCacheType(getGraphQLType(field2.output));
850
887
  return {
851
- ...extract(field),
888
+ ...extract(field2),
852
889
  type: outputType,
853
- args: inputToArgs(field.input),
854
- ...this.provideForResolve(field),
855
- ...this.provideForSubscribe(field)
890
+ args: inputToArgs(field2.input),
891
+ ...this.provideForResolve(field2),
892
+ ...this.provideForSubscribe(field2)
856
893
  };
857
894
  } catch (error) {
858
895
  throw markErrorLocation(error);
859
896
  }
860
897
  }
861
- provideForResolve(field) {
862
- if (field?.resolve == null) return;
863
- if (field.resolve === defaultSubscriptionResolve)
898
+ provideForResolve(field2) {
899
+ if (field2?.resolve == null) return;
900
+ if (field2.resolve === defaultSubscriptionResolve)
864
901
  return { resolve: defaultSubscriptionResolve };
865
- const resolve = field.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
866
- { root, args, context, info, field },
867
- () => field.resolve(root, args, this.resolverOptions)
868
- ) : field.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
869
- { root, args, context, info, field },
870
- () => field.resolve(root, args)
902
+ const resolve = field2.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
903
+ { root, args, context, info, field: field2 },
904
+ () => field2.resolve(root, args, this.resolverOptions)
905
+ ) : field2.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
906
+ { root, args, context, info, field: field2 },
907
+ () => field2.resolve(root, args)
871
908
  ) : (root, args, context, info) => resolverPayloadStorage.run(
872
- { root, args, context, info, field },
873
- () => field.resolve(args, this.resolverOptions)
909
+ { root, args, context, info, field: field2 },
910
+ () => field2.resolve(args, this.resolverOptions)
874
911
  );
875
912
  return { resolve };
876
913
  }
877
- provideForSubscribe(field) {
878
- if (field?.subscribe == null) return;
914
+ provideForSubscribe(field2) {
915
+ if (field2?.subscribe == null) return;
879
916
  return {
880
917
  subscribe: (root, args, context, info) => resolverPayloadStorage.run(
881
- { root, args, context, info, field },
882
- () => field.subscribe?.(args, this.resolverOptions)
918
+ { root, args, context, info, field: field2 },
919
+ () => field2.subscribe?.(args, this.resolverOptions)
883
920
  )
884
921
  };
885
922
  }
@@ -959,12 +996,21 @@ function getCacheType(gqlType, options = {}) {
959
996
  return gqlType;
960
997
  }
961
998
 
999
+ // src/schema/schema-vendor-weaver.ts
1000
+ function isSchemaVendorWeaver(some) {
1001
+ if (typeof some !== "object" && typeof some !== "function") return false;
1002
+ if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
1003
+ return false;
1004
+ if (!("vendor" in some) || typeof some.vendor !== "string") return false;
1005
+ return true;
1006
+ }
1007
+
962
1008
  // src/schema/schema-weaver.ts
963
1009
  import {
964
1010
  GraphQLSchema,
965
- isObjectType as isObjectType4,
966
- isNonNullType as isNonNullType3,
967
1011
  isEnumType as isEnumType2,
1012
+ isNonNullType as isNonNullType3,
1013
+ isObjectType as isObjectType4,
968
1014
  isUnionType as isUnionType4
969
1015
  } from "graphql";
970
1016
  var SchemaWeaver = class _SchemaWeaver {
@@ -985,11 +1031,11 @@ var SchemaWeaver = class _SchemaWeaver {
985
1031
  [WEAVER_CONFIG]: "gqloom.core.schema"
986
1032
  };
987
1033
  }
988
- constructor({ query, mutation, subscription, types } = {}, context) {
989
- if (query != null) this.query = query;
990
- if (mutation != null) this.mutation = mutation;
991
- if (subscription != null) this.subscription = subscription;
992
- if (types != null) this.types = types.slice();
1034
+ constructor({ query: query2, mutation: mutation2, subscription: subscription2, types } = {}, context) {
1035
+ if (query2 != null) this.query = query2;
1036
+ if (mutation2 != null) this.mutation = mutation2;
1037
+ if (subscription2 != null) this.subscription = subscription2;
1038
+ this.types = new Set(types ?? []);
993
1039
  this.context = context ?? initWeaverContext();
994
1040
  }
995
1041
  use(...middlewares) {
@@ -998,8 +1044,12 @@ var SchemaWeaver = class _SchemaWeaver {
998
1044
  this.resolverOptions.middlewares.push(...middlewares);
999
1045
  return this;
1000
1046
  }
1001
- add(resolver) {
1002
- provideWeaverContext(() => this.addResolver(resolver), this.context);
1047
+ add(resolver2) {
1048
+ provideWeaverContext(() => this.addResolver(resolver2), this.context);
1049
+ return this;
1050
+ }
1051
+ addVendor(weaver) {
1052
+ this.context.vendorWeavers.set(weaver.vendor, weaver);
1003
1053
  return this;
1004
1054
  }
1005
1055
  addType(silk2) {
@@ -1019,8 +1069,7 @@ var SchemaWeaver = class _SchemaWeaver {
1019
1069
  `${gqlType2?.name ?? gqlType2.toString()} is not a named type`
1020
1070
  );
1021
1071
  }, this.context);
1022
- this.types ??= [];
1023
- this.types.push(gqlType);
1072
+ this.types.add(gqlType);
1024
1073
  return this;
1025
1074
  }
1026
1075
  setConfig(config) {
@@ -1028,38 +1077,39 @@ var SchemaWeaver = class _SchemaWeaver {
1028
1077
  return this;
1029
1078
  }
1030
1079
  weaveGraphQLSchema() {
1031
- const { query, mutation, subscription, types } = this;
1080
+ const { query: query2, mutation: mutation2, subscription: subscription2, types } = this;
1032
1081
  const config = this.context.getConfig("gqloom.core.schema");
1033
1082
  const schema = new GraphQLSchema({
1034
- query,
1035
- mutation,
1036
- subscription,
1083
+ query: query2,
1084
+ mutation: mutation2,
1085
+ subscription: subscription2,
1037
1086
  types: [...types ?? [], ...config?.types ?? []],
1038
1087
  ...config
1039
1088
  });
1040
1089
  return schema;
1041
1090
  }
1042
- addResolver(resolver) {
1043
- const resolverOptions = ResolverOptionsMap.get(resolver);
1091
+ addResolver(resolver2) {
1092
+ const resolverOptions = ResolverOptionsMap.get(resolver2);
1044
1093
  const parent = resolverOptions?.parent;
1045
1094
  const parentObject = (() => {
1046
1095
  if (parent == null) return void 0;
1047
1096
  let gqlType = getGraphQLType(parent);
1048
1097
  if (isNonNullType3(gqlType)) gqlType = gqlType.ofType;
1049
- if (isObjectType4(gqlType)) {
1050
- const existing = this.context.loomObjectMap.get(gqlType);
1051
- if (existing != null) return existing;
1052
- const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1053
- this.context.loomObjectMap.set(gqlType, extraObject);
1054
- return extraObject;
1098
+ if (!isObjectType4(gqlType)) {
1099
+ throw new Error(
1100
+ `${gqlType?.name ?? gqlType.toString()} is not an object type`
1101
+ );
1055
1102
  }
1056
- throw new Error(
1057
- `${gqlType?.name ?? gqlType.toString()} is not an object type`
1058
- );
1103
+ const existing = this.context.loomObjectMap.get(gqlType);
1104
+ if (existing != null) return existing;
1105
+ const extraObject = new LoomObjectType(gqlType, this.fieldOptions);
1106
+ this.context.loomObjectMap.set(gqlType, extraObject);
1107
+ this.types.add(extraObject);
1108
+ return extraObject;
1059
1109
  })();
1060
1110
  if (resolverOptions?.extensions && parentObject)
1061
1111
  parentObject.mergeExtensions(resolverOptions.extensions);
1062
- Object.entries(resolver).forEach(([name, operation]) => {
1112
+ Object.entries(resolver2).forEach(([name, operation]) => {
1063
1113
  if (operation === FIELD_HIDDEN) {
1064
1114
  if (parentObject == null) return;
1065
1115
  parentObject.hideField(name);
@@ -1107,12 +1157,16 @@ var SchemaWeaver = class _SchemaWeaver {
1107
1157
  const middlewares = /* @__PURE__ */ new Set();
1108
1158
  const resolvers = /* @__PURE__ */ new Set();
1109
1159
  const silks = /* @__PURE__ */ new Set();
1160
+ const weavers = /* @__PURE__ */ new Set();
1110
1161
  let context;
1111
1162
  for (const item of inputs) {
1112
- if (typeof item === "function") {
1163
+ if (isSchemaVendorWeaver(item)) {
1164
+ weavers.add(item);
1165
+ } else if (typeof item === "function") {
1113
1166
  middlewares.add(item);
1114
1167
  } else if (WEAVER_CONFIG in item) {
1115
1168
  configs.add(item);
1169
+ if (item.vendorWeaver) weavers.add(item.vendorWeaver);
1116
1170
  if (item[WEAVER_CONFIG] === "gqloom.core.schema") {
1117
1171
  context = item.weaverContext;
1118
1172
  }
@@ -1122,7 +1176,7 @@ var SchemaWeaver = class _SchemaWeaver {
1122
1176
  resolvers.add(item);
1123
1177
  }
1124
1178
  }
1125
- return { context, configs, middlewares, resolvers, silks };
1179
+ return { context, configs, middlewares, resolvers, silks, weavers };
1126
1180
  }
1127
1181
  /**
1128
1182
  * Weave a GraphQL Schema from resolvers
@@ -1130,9 +1184,10 @@ var SchemaWeaver = class _SchemaWeaver {
1130
1184
  * @returns GraphQ LSchema
1131
1185
  */
1132
1186
  static weave(...inputs) {
1133
- const { context, configs, middlewares, resolvers, silks } = _SchemaWeaver.optionsFrom(...inputs);
1187
+ const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
1134
1188
  const weaver = new _SchemaWeaver({}, context);
1135
1189
  configs.forEach((it) => weaver.setConfig(it));
1190
+ weavers.forEach((it) => weaver.addVendor(it));
1136
1191
  middlewares.forEach((it) => weaver.use(it));
1137
1192
  resolvers.forEach((it) => weaver.add(it));
1138
1193
  silks.forEach((it) => weaver.addType(it));
@@ -1163,8 +1218,8 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1163
1218
  const interfaceType = new GraphQLInterfaceType({
1164
1219
  ...config,
1165
1220
  ...interfaceConfig,
1166
- fields: mapValue(fields, (field) => {
1167
- return { ...field, type: getCacheType(field.type) };
1221
+ fields: mapValue(fields, (field2) => {
1222
+ return { ...field2, type: getCacheType(field2.type) };
1168
1223
  })
1169
1224
  });
1170
1225
  weaverContext.interfaceMap?.set(key, interfaceType);
@@ -1194,20 +1249,24 @@ export {
1194
1249
  ensureInputObjectType,
1195
1250
  ensureInputType,
1196
1251
  ensureInterfaceType,
1252
+ field,
1197
1253
  getCacheType,
1198
1254
  getFieldOptions,
1199
1255
  getGraphQLType,
1200
1256
  getOperationOptions,
1257
+ getStandardValue,
1201
1258
  getSubscriptionOptions,
1202
1259
  initWeaverContext,
1203
1260
  inputToArgs,
1204
1261
  isOnlyMemoryPayload,
1262
+ isSchemaVendorWeaver,
1205
1263
  isSilk,
1206
1264
  listSilk,
1207
1265
  loom,
1208
1266
  mapValue,
1209
1267
  markErrorLocation,
1210
1268
  markLocation,
1269
+ mutation,
1211
1270
  nonNullSilk,
1212
1271
  notNullish,
1213
1272
  nullableSilk,
@@ -1215,13 +1274,11 @@ export {
1215
1274
  parseInputValue,
1216
1275
  parseSilk,
1217
1276
  provideWeaverContext,
1277
+ query,
1278
+ resolver,
1218
1279
  resolverPayloadStorage,
1219
1280
  silk,
1220
- silkField,
1221
- silkMutation,
1222
- silkQuery,
1223
- silkResolver,
1224
- silkSubscription,
1281
+ subscription,
1225
1282
  toObjMap,
1226
1283
  tryIn,
1227
1284
  useContext,