@gqloom/core 0.2.2 → 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.
package/dist/index.js CHANGED
@@ -6,30 +6,164 @@ 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
14
22
  var symbols_exports = {};
15
23
  __export(symbols_exports, {
16
24
  CONTEXT_MEMORY_MAP_KEY: () => CONTEXT_MEMORY_MAP_KEY,
25
+ FIELD_HIDDEN: () => FIELD_HIDDEN,
17
26
  GET_GRAPHQL_TYPE: () => GET_GRAPHQL_TYPE,
18
- PARSE: () => PARSE,
19
27
  RESOLVER_OPTIONS_KEY: () => RESOLVER_OPTIONS_KEY,
20
28
  WEAVER_CONFIG: () => WEAVER_CONFIG
21
29
  });
22
30
  var GET_GRAPHQL_TYPE = Symbol.for("gqloom.get_graphql_type");
23
- var PARSE = Symbol.for("gqloom.parse");
24
31
  var WEAVER_CONFIG = Symbol.for("gqloom.weaver_config");
25
32
  var RESOLVER_OPTIONS_KEY = Symbol.for("gqloom.resolver-options");
26
33
  var CONTEXT_MEMORY_MAP_KEY = Symbol.for("gqloom.context-memory");
34
+ var FIELD_HIDDEN = Symbol.for("gqloom.field-hidden");
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
+ }
27
157
 
28
158
  // src/resolver/silk.ts
29
- function silk(type, parse) {
159
+ function silk(type, validate = (value) => ({ value: value ?? void 0 })) {
30
160
  return {
31
161
  [GET_GRAPHQL_TYPE]: typeof type === "function" ? type : () => type,
32
- [PARSE]: parse
162
+ "~standard": {
163
+ version: 1,
164
+ vendor: "gqloom.silk",
165
+ validate
166
+ }
33
167
  };
34
168
  }
35
169
  silk.parse = parseSilk;
@@ -39,6 +173,7 @@ silk.list = listSilk;
39
173
  silk.nullable = nullableSilk;
40
174
  function nonNullSilk(origin) {
41
175
  return {
176
+ ...origin,
42
177
  [GET_GRAPHQL_TYPE]: () => {
43
178
  const originType = getGraphQLType(origin);
44
179
  if (originType instanceof GraphQLNonNull) {
@@ -46,12 +181,12 @@ function nonNullSilk(origin) {
46
181
  } else {
47
182
  return new GraphQLNonNull(originType);
48
183
  }
49
- },
50
- [PARSE]: (input) => origin[PARSE]?.(input)
184
+ }
51
185
  };
52
186
  }
53
187
  function listSilk(origin) {
54
188
  return {
189
+ ...origin,
55
190
  [GET_GRAPHQL_TYPE]: () => {
56
191
  let originType = getGraphQLType(origin);
57
192
  if (originType instanceof GraphQLNonNull && originType.ofType instanceof GraphQLList) {
@@ -66,6 +201,7 @@ function listSilk(origin) {
66
201
  }
67
202
  function nullableSilk(origin) {
68
203
  return {
204
+ ...origin,
69
205
  [GET_GRAPHQL_TYPE]: () => {
70
206
  const originType = getGraphQLType(origin);
71
207
  if (originType instanceof GraphQLNonNull) {
@@ -73,21 +209,30 @@ function nullableSilk(origin) {
73
209
  } else {
74
210
  return originType;
75
211
  }
76
- },
77
- [PARSE]: (input) => origin[PARSE]?.(input)
212
+ }
78
213
  };
79
214
  }
80
215
  function getGraphQLType(silk2) {
81
- return silk2[GET_GRAPHQL_TYPE]();
216
+ if (GET_GRAPHQL_TYPE in silk2 && silk2[GET_GRAPHQL_TYPE] != null)
217
+ return silk2[GET_GRAPHQL_TYPE]();
218
+ const vendorWeavers = weaverContext.vendorWeavers;
219
+ if (vendorWeavers == null) throw new Error("Schema Weaver is not initialized");
220
+ const weaver = vendorWeavers.get(silk2["~standard"].vendor);
221
+ if (weaver == null)
222
+ throw new Error(
223
+ `Schema Weaver for ${silk2["~standard"].vendor} is not found`
224
+ );
225
+ return weaver.getGraphQLType(silk2);
82
226
  }
83
227
  function parseSilk(silk2, input) {
84
- if (silk2[PARSE] == null) return input;
85
- return silk2[PARSE](input);
228
+ return silk2["~standard"].validate(input);
86
229
  }
87
230
  function isSilk(target) {
88
231
  if (typeof target !== "object") return false;
89
232
  if (target == null) return false;
90
- return GET_GRAPHQL_TYPE in target;
233
+ if (GET_GRAPHQL_TYPE in target) return true;
234
+ if (!("~standard" in target)) return false;
235
+ return "vendor" in target["~standard"] && typeof target["~standard"].vendor === "string" && "version" in target["~standard"] && typeof target["~standard"].version === "number";
91
236
  }
92
237
 
93
238
  // src/utils/args.ts
@@ -304,6 +449,7 @@ function markLocation(message, ...locations) {
304
449
  }
305
450
 
306
451
  // src/resolver/input.ts
452
+ import { GraphQLError } from "graphql";
307
453
  function createInputParser(schema, value) {
308
454
  let result;
309
455
  const parse = async () => {
@@ -320,32 +466,43 @@ function createInputParser(schema, value) {
320
466
  }
321
467
  function parseInputValue(inputSchema, input) {
322
468
  if (inputSchema === void 0) {
323
- return input;
469
+ return { value: input };
324
470
  }
325
471
  if (isSilk(inputSchema)) {
326
- if (typeof inputSchema[symbols_exports.PARSE] === "function") {
327
- return inputSchema[symbols_exports.PARSE](input);
328
- }
329
- return input;
472
+ return inputSchema["~standard"].validate(input);
330
473
  }
331
474
  return parseInputEntries(inputSchema, input);
332
475
  }
333
476
  async function parseInputEntries(inputSchema, input = {}) {
334
477
  const result = {};
478
+ const issues = [];
335
479
  await Promise.all(
336
480
  Object.entries(inputSchema).map(async ([key, value]) => {
337
- if (typeof value[symbols_exports.PARSE] === "function") {
338
- result[key] = await value[symbols_exports.PARSE](input[key]);
339
- } else {
340
- result[key] = input[key];
481
+ const res = await value["~standard"].validate(input[key]);
482
+ if ("value" in res) {
483
+ result[key] = res.value;
484
+ }
485
+ if (res.issues) {
486
+ issues.push(...res.issues.slice());
341
487
  }
342
488
  })
343
489
  );
344
- return result;
490
+ return { value: result, ...issues.length > 0 ? { issues } : null };
491
+ }
492
+ function getStandardValue(result) {
493
+ if (result == null) return result;
494
+ const { issues } = result;
495
+ if (issues?.length) {
496
+ throw new GraphQLError(issues?.[0]?.message ?? "Invalid input", {
497
+ extensions: { issues }
498
+ });
499
+ }
500
+ if ("value" in result) return result.value;
501
+ else throw new GraphQLError("Invalid input");
345
502
  }
346
503
 
347
504
  // src/resolver/resolver.ts
348
- var silkQuery = (output, resolveOrOptions) => {
505
+ var query = (output, resolveOrOptions) => {
349
506
  const options = getOperationOptions(resolveOrOptions);
350
507
  const type = "query";
351
508
  return {
@@ -356,14 +513,14 @@ var silkQuery = (output, resolveOrOptions) => {
356
513
  const parseInput = createInputParser(options.input, inputValue);
357
514
  return applyMiddlewares(
358
515
  compose(extraOptions?.middlewares, options.middlewares),
359
- async () => options.resolve(await parseInput()),
516
+ async () => options.resolve(getStandardValue(await parseInput())),
360
517
  { parseInput, parent: void 0, outputSilk: output, type }
361
518
  );
362
519
  },
363
520
  type
364
521
  };
365
522
  };
366
- var silkMutation = (output, resolveOrOptions) => {
523
+ var mutation = (output, resolveOrOptions) => {
367
524
  const options = getOperationOptions(resolveOrOptions);
368
525
  const type = "mutation";
369
526
  return {
@@ -374,14 +531,14 @@ var silkMutation = (output, resolveOrOptions) => {
374
531
  const parseInput = createInputParser(options.input, inputValue);
375
532
  return applyMiddlewares(
376
533
  compose(extraOptions?.middlewares, options.middlewares),
377
- async () => options.resolve(await parseInput()),
534
+ async () => options.resolve(getStandardValue(await parseInput())),
378
535
  { parseInput, parent: void 0, outputSilk: output, type }
379
536
  );
380
537
  },
381
538
  type
382
539
  };
383
540
  };
384
- var silkField = (output, resolveOrOptions) => {
541
+ var baseSilkField = (output, resolveOrOptions) => {
385
542
  const options = getOperationOptions(resolveOrOptions);
386
543
  const type = "field";
387
544
  return {
@@ -392,15 +549,21 @@ var silkField = (output, resolveOrOptions) => {
392
549
  const parseInput = createInputParser(options.input, inputValue);
393
550
  return applyMiddlewares(
394
551
  compose(extraOptions?.middlewares, options.middlewares),
395
- async () => options.resolve(parent, await parseInput()),
552
+ async () => options.resolve(parent, getStandardValue(await parseInput())),
396
553
  { parseInput, parent, outputSilk: output, type }
397
554
  );
398
555
  },
399
556
  type
400
557
  };
401
558
  };
559
+ var field = Object.assign(
560
+ baseSilkField,
561
+ {
562
+ hidden: FIELD_HIDDEN
563
+ }
564
+ );
402
565
  var defaultSubscriptionResolve = (source) => source;
403
- var silkSubscription = (output, subscribeOrOptions) => {
566
+ var subscription = (output, subscribeOrOptions) => {
404
567
  const options = getSubscriptionOptions(subscribeOrOptions);
405
568
  const type = "subscription";
406
569
  return {
@@ -414,7 +577,7 @@ var silkSubscription = (output, subscribeOrOptions) => {
414
577
  extraOptions?.middlewares,
415
578
  options.middlewares
416
579
  ),
417
- async () => options.subscribe(await parseInput()),
580
+ async () => options.subscribe(getStandardValue(await parseInput())),
418
581
  { parseInput, parent: void 0, outputSilk: output, type }
419
582
  );
420
583
  },
@@ -433,6 +596,7 @@ function baseResolver(operations, options) {
433
596
  }
434
597
  function extraOperationOptions(operation, options) {
435
598
  const composeMiddlewares = (extraOptions) => compose(extraOptions?.middlewares, options?.middlewares);
599
+ if (typeof operation === "symbol") return operation;
436
600
  switch (operation.type) {
437
601
  case "field":
438
602
  return {
@@ -460,7 +624,7 @@ function extraOperationOptions(operation, options) {
460
624
  };
461
625
  }
462
626
  }
463
- var silkResolver = Object.assign(
627
+ var resolver = Object.assign(
464
628
  baseResolver,
465
629
  {
466
630
  of: (parent, operations, options) => baseResolver(
@@ -470,11 +634,11 @@ var silkResolver = Object.assign(
470
634
  }
471
635
  );
472
636
  var loom = {
473
- query: silkQuery,
474
- resolver: silkResolver,
475
- field: silkField,
476
- subscription: silkSubscription,
477
- mutation: silkMutation
637
+ query,
638
+ resolver,
639
+ field,
640
+ subscription,
641
+ mutation
478
642
  };
479
643
 
480
644
  // src/helper/create-loom.ts
@@ -491,7 +655,7 @@ function toSilkInput(schema, toSilk, isSchema) {
491
655
  }
492
656
  return record;
493
657
  }
494
- function createResolverBobbin(toSilk) {
658
+ function createResolverFactory(toSilk) {
495
659
  return Object.assign(baseResolver, {
496
660
  of: (parent, operations, options) => baseResolver(
497
661
  operations,
@@ -499,39 +663,42 @@ function createResolverBobbin(toSilk) {
499
663
  )
500
664
  });
501
665
  }
502
- function createFieldBobbin(toSilk, isSchema) {
503
- return (output, resolveOrOptions) => {
666
+ function createFieldFactory(toSilk, isSchema) {
667
+ const baseFieldFunc = (output, resolveOrOptions) => {
504
668
  const options = getOperationOptions(
505
669
  resolveOrOptions
506
670
  );
507
- return silkField(toSilk(output), {
671
+ return field(toSilk(output), {
508
672
  ...options,
509
673
  input: toSilkInput(options.input, toSilk, isSchema)
510
674
  });
511
675
  };
676
+ return Object.assign(baseFieldFunc, {
677
+ hidden: FIELD_HIDDEN
678
+ });
512
679
  }
513
- function createQueryBobbin(toSilk, isSchema) {
680
+ function createQueryFactory(toSilk, isSchema) {
514
681
  return (output, resolveOrOptions) => {
515
682
  const options = getOperationOptions(resolveOrOptions);
516
- return silkQuery(toSilk(output), {
683
+ return query(toSilk(output), {
517
684
  ...options,
518
685
  input: toSilkInput(options.input, toSilk, isSchema)
519
686
  });
520
687
  };
521
688
  }
522
- function createMutationBobbin(toSilk, isSchema) {
689
+ function createMutationFactory(toSilk, isSchema) {
523
690
  return (output, resolveOrOptions) => {
524
691
  const options = getOperationOptions(resolveOrOptions);
525
- return silkMutation(toSilk(output), {
692
+ return mutation(toSilk(output), {
526
693
  ...options,
527
694
  input: toSilkInput(options.input, toSilk, isSchema)
528
695
  });
529
696
  };
530
697
  }
531
- function createSubscriptionBobbin(toSilk, isSchema) {
698
+ function createSubscriptionFactory(toSilk, isSchema) {
532
699
  return (output, resolveOrOptions) => {
533
700
  const options = getSubscriptionOptions(resolveOrOptions);
534
- return silkSubscription(toSilk(output), {
701
+ return subscription(toSilk(output), {
535
702
  ...options,
536
703
  input: toSilkInput(options.input, toSilk, isSchema)
537
704
  });
@@ -539,149 +706,39 @@ function createSubscriptionBobbin(toSilk, isSchema) {
539
706
  }
540
707
  function createLoom(toSilk, isSchema) {
541
708
  return {
542
- query: createQueryBobbin(toSilk, isSchema),
543
- mutation: createMutationBobbin(toSilk, isSchema),
544
- field: createFieldBobbin(toSilk, isSchema),
545
- resolver: createResolverBobbin(toSilk),
546
- subscription: createSubscriptionBobbin(toSilk, isSchema)
709
+ query: createQueryFactory(toSilk, isSchema),
710
+ mutation: createMutationFactory(toSilk, isSchema),
711
+ field: createFieldFactory(toSilk, isSchema),
712
+ resolver: createResolverFactory(toSilk),
713
+ subscription: createSubscriptionFactory(toSilk, isSchema)
547
714
  };
548
715
  }
549
716
 
550
717
  // src/schema/object.ts
551
718
  import {
719
+ GraphQLList as GraphQLList3,
720
+ GraphQLNonNull as GraphQLNonNull3,
552
721
  GraphQLObjectType,
722
+ GraphQLUnionType,
553
723
  assertName,
554
- isObjectType as isObjectType3,
555
- resolveObjMapThunk,
556
724
  isListType as isListType2,
557
- GraphQLList as GraphQLList3,
558
- GraphQLNonNull as GraphQLNonNull3,
559
725
  isNonNullType as isNonNullType2,
726
+ isObjectType as isObjectType3,
560
727
  isUnionType as isUnionType3,
561
- GraphQLUnionType
728
+ resolveObjMapThunk
562
729
  } from "graphql";
563
730
 
564
- // src/schema/weaver-context.ts
565
- import {
566
- isEnumType,
567
- isObjectType,
568
- isUnionType
569
- } from "graphql";
570
- var ref;
571
- var names = /* @__PURE__ */ new WeakMap();
572
- function initWeaverContext() {
573
- return {
574
- loomObjectMap: /* @__PURE__ */ new Map(),
575
- loomUnionMap: /* @__PURE__ */ new Map(),
576
- inputMap: /* @__PURE__ */ new Map(),
577
- interfaceMap: /* @__PURE__ */ new Map(),
578
- configs: /* @__PURE__ */ new Map(),
579
- getConfig(key) {
580
- return this.configs.get(key);
581
- },
582
- setConfig(config) {
583
- const key = config[WEAVER_CONFIG];
584
- this.configs.set(key, config);
585
- },
586
- deleteConfig(key) {
587
- this.configs.delete(key);
588
- },
589
- names,
590
- namedTypes: /* @__PURE__ */ new Map(),
591
- memoNamedType(gqlTypeValue) {
592
- const gqlType = gqlTypeValue;
593
- if (isObjectType(gqlType) || isUnionType(gqlType) || isEnumType(gqlType)) {
594
- this.namedTypes.set(gqlType.name, gqlType);
595
- }
596
- return gqlTypeValue;
597
- },
598
- getNamedType(name) {
599
- return this.namedTypes.get(name);
600
- }
601
- };
602
- }
603
- var weaverContext = {
604
- get loomObjectMap() {
605
- return ref?.loomObjectMap;
606
- },
607
- get loomUnionMap() {
608
- return ref?.loomUnionMap;
609
- },
610
- get inputMap() {
611
- return ref?.inputMap;
612
- },
613
- get interfaceMap() {
614
- return ref?.interfaceMap;
615
- },
616
- get configs() {
617
- return ref?.configs;
618
- },
619
- getConfig(key) {
620
- return ref?.getConfig(key);
621
- },
622
- setConfig(config) {
623
- ref?.setConfig(config);
624
- },
625
- deleteConfig(key) {
626
- ref?.deleteConfig(key);
627
- },
628
- get value() {
629
- return ref;
630
- },
631
- useConfig(config, callback) {
632
- const context = weaverContext.value ?? initWeaverContext();
633
- context.setConfig(config);
634
- const result = provideWeaverContext(callback, context);
635
- context.deleteConfig(config[WEAVER_CONFIG]);
636
- return result;
637
- },
638
- names,
639
- getNamedType(name) {
640
- return ref?.getNamedType(name);
641
- },
642
- memoNamedType(gqlType) {
643
- return ref?.memoNamedType(gqlType) ?? gqlType;
644
- },
645
- GraphQLTypes: /* @__PURE__ */ new WeakMap(),
646
- getGraphQLType(origin) {
647
- return this.GraphQLTypes.get(origin);
648
- },
649
- memoGraphQLType(origin, gqlType) {
650
- this.GraphQLTypes.set(origin, gqlType);
651
- return gqlType;
652
- }
653
- };
654
- function provideWeaverContext(func, value) {
655
- const lastRef = ref;
656
- ref = value;
657
- try {
658
- return func();
659
- } finally {
660
- ref = lastRef;
661
- }
662
- }
663
- function collectNames(...namesList) {
664
- const namesRecord = {};
665
- for (const namesItem of namesList) {
666
- for (const [name, schema] of Object.entries(namesItem)) {
667
- names.set(schema, name);
668
- namesRecord[name] = schema;
669
- }
670
- }
671
- return namesRecord;
672
- }
673
-
674
731
  // src/schema/input.ts
675
732
  import {
676
733
  GraphQLInputObjectType,
677
734
  GraphQLList as GraphQLList2,
678
735
  GraphQLNonNull as GraphQLNonNull2,
736
+ isInputObjectType,
679
737
  isInterfaceType,
680
738
  isListType,
681
739
  isNonNullType,
682
740
  isObjectType as isObjectType2,
683
- isUnionType as isUnionType2,
684
- isInputObjectType
741
+ isUnionType as isUnionType2
685
742
  } from "graphql";
686
743
  function inputToArgs(input) {
687
744
  if (input === void 0) return void 0;
@@ -697,11 +754,11 @@ function inputToArgs(input) {
697
754
  throw new Error(`Cannot convert ${inputType.toString()} to input type`);
698
755
  }
699
756
  const args = {};
700
- Object.entries(input).forEach(([name, field]) => {
757
+ Object.entries(input).forEach(([name, field2]) => {
701
758
  tryIn(() => {
702
759
  args[name] = {
703
- ...field,
704
- type: ensureInputType(field)
760
+ ...field2,
761
+ type: ensureInputType(field2)
705
762
  };
706
763
  }, name);
707
764
  });
@@ -740,7 +797,9 @@ function ensureInputObjectType(object) {
740
797
  const input = new GraphQLInputObjectType({
741
798
  ...config,
742
799
  name: getInputObjectName(object.name),
743
- fields: mapValue(fields, (it) => toInputFieldConfig(it))
800
+ fields: provideWeaverContext.inherit(
801
+ () => mapValue(fields, (it) => toInputFieldConfig(it))
802
+ )
744
803
  });
745
804
  weaverContext.inputMap?.set(object, input);
746
805
  return input;
@@ -756,6 +815,7 @@ function toInputFieldConfig({
756
815
  // src/schema/object.ts
757
816
  var LoomObjectType = class extends GraphQLObjectType {
758
817
  extraFields = /* @__PURE__ */ new Map();
818
+ hiddenFields = /* @__PURE__ */ new Set();
759
819
  weaverContext;
760
820
  resolverOptions;
761
821
  constructor(objectOrGetter, options = {}) {
@@ -773,77 +833,84 @@ var LoomObjectType = class extends GraphQLObjectType {
773
833
  this.resolverOptions = options.resolverOptions;
774
834
  this.weaverContext = options.weaverContext ?? initWeaverContext();
775
835
  }
776
- addField(name, resolver) {
836
+ hideField(name) {
837
+ this.hiddenFields.add(name);
838
+ }
839
+ addField(name, resolver2) {
777
840
  const existing = this.extraFields.get(name);
778
- if (existing && existing !== resolver) {
841
+ if (existing && existing !== resolver2) {
779
842
  throw new Error(`Field ${name} already exists in ${this.name}`);
780
843
  }
781
- this.extraFields.set(name, resolver);
844
+ this.extraFields.set(name, resolver2);
782
845
  }
783
846
  mergeExtensions(extensions) {
784
847
  this.extensions = deepMerge(this.extensions, extensions);
785
848
  }
786
- extraField;
849
+ extraFieldMap;
787
850
  getFields() {
788
- const fields = super.getFields();
789
- Object.values(fields).forEach(
790
- (field) => field.type = this.getCacheType(field.type)
851
+ const fieldsBySuper = super.getFields();
852
+ Object.values(fieldsBySuper).forEach(
853
+ (field2) => field2.type = this.getCacheType(field2.type)
791
854
  );
792
- const extraField = provideWeaverContext(
855
+ const extraFields = provideWeaverContext(
793
856
  () => defineFieldMap(this.mapToFieldConfig(this.extraFields)),
794
857
  this.weaverContext
795
858
  );
796
- if (Object.keys(this.extraField ?? {}).join() !== Object.keys(extraField).join()) {
797
- this.extraField = extraField;
859
+ if (Object.keys(this.extraFieldMap ?? {}).join() !== Object.keys(extraFields).join()) {
860
+ this.extraFieldMap = extraFields;
798
861
  }
799
- return {
800
- ...fields,
801
- ...this.extraField
862
+ const answer = {
863
+ ...fieldsBySuper,
864
+ ...this.extraFieldMap
802
865
  };
866
+ for (const fieldName of this.hiddenFields) {
867
+ delete answer[fieldName];
868
+ }
869
+ return answer;
803
870
  }
804
871
  mapToFieldConfig(map) {
805
872
  const record = {};
806
- for (const [name, field] of map.entries()) {
807
- record[name] = this.toFieldConfig(field);
873
+ for (const [name, field2] of map.entries()) {
874
+ record[name] = this.toFieldConfig(field2);
808
875
  }
809
876
  return record;
810
877
  }
811
- toFieldConfig(field) {
878
+ toFieldConfig(field2) {
812
879
  try {
813
- const outputType = this.getCacheType(getGraphQLType(field.output));
880
+ const outputType = this.getCacheType(getGraphQLType(field2.output));
814
881
  return {
815
- ...extract(field),
882
+ ...extract(field2),
816
883
  type: outputType,
817
- args: inputToArgs(field.input),
818
- ...this.provideForResolve(field),
819
- ...this.provideForSubscribe(field)
884
+ args: inputToArgs(field2.input),
885
+ ...this.provideForResolve(field2),
886
+ ...this.provideForSubscribe(field2)
820
887
  };
821
888
  } catch (error) {
822
889
  throw markErrorLocation(error);
823
890
  }
824
891
  }
825
- provideForResolve(field) {
826
- if (field?.resolve == null) return;
827
- if (field.resolve === defaultSubscriptionResolve)
892
+ provideForResolve(field2) {
893
+ if (field2?.resolve == null) return;
894
+ if (field2.resolve === defaultSubscriptionResolve)
828
895
  return { resolve: defaultSubscriptionResolve };
829
- const resolve = field.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
830
- { root, args, context, info, field },
831
- () => field.resolve(root, args, this.resolverOptions)
832
- ) : field.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
833
- { root, args, context, info, field },
834
- () => field.resolve(root, args)
896
+ const resolve = field2.type === "field" ? (root, args, context, info) => resolverPayloadStorage.run(
897
+ { root, args, context, info, field: field2 },
898
+ () => field2.resolve(root, args, this.resolverOptions)
899
+ ) : field2.type === "subscription" ? (root, args, context, info) => resolverPayloadStorage.run(
900
+ { root, args, context, info, field: field2 },
901
+ () => field2.resolve(root, args)
835
902
  ) : (root, args, context, info) => resolverPayloadStorage.run(
836
- { root, args, context, info, field },
837
- () => field.resolve(args, this.resolverOptions)
903
+ { root, args, context, info, field: field2 },
904
+ () => field2.resolve(args, this.resolverOptions)
838
905
  );
839
906
  return { resolve };
840
907
  }
841
- provideForSubscribe(field) {
842
- if (field?.subscribe == null) return;
908
+ provideForSubscribe(field2) {
909
+ if (field2?.subscribe == null) return;
843
910
  return {
844
911
  subscribe: (root, args, context, info) => resolverPayloadStorage.run(
845
- { root, args, context, info, field },
846
- () => field.subscribe?.(args, this.resolverOptions)
912
+ { root, args, context, info, field: field2 },
913
+ () => field2.subscribe?.(args, this.resolverOptions)
847
914
  )
848
915
  };
849
916
  }
@@ -923,12 +990,21 @@ function getCacheType(gqlType, options = {}) {
923
990
  return gqlType;
924
991
  }
925
992
 
993
+ // src/schema/schema-vendor-weaver.ts
994
+ function isSchemaVendorWeaver(some) {
995
+ if (typeof some !== "object" && typeof some !== "function") return false;
996
+ if (!("getGraphQLType" in some) || typeof some.getGraphQLType !== "function")
997
+ return false;
998
+ if (!("vendor" in some) || typeof some.vendor !== "string") return false;
999
+ return true;
1000
+ }
1001
+
926
1002
  // src/schema/schema-weaver.ts
927
1003
  import {
928
1004
  GraphQLSchema,
929
- isObjectType as isObjectType4,
930
- isNonNullType as isNonNullType3,
931
1005
  isEnumType as isEnumType2,
1006
+ isNonNullType as isNonNullType3,
1007
+ isObjectType as isObjectType4,
932
1008
  isUnionType as isUnionType4
933
1009
  } from "graphql";
934
1010
  var SchemaWeaver = class _SchemaWeaver {
@@ -949,10 +1025,10 @@ var SchemaWeaver = class _SchemaWeaver {
949
1025
  [WEAVER_CONFIG]: "gqloom.core.schema"
950
1026
  };
951
1027
  }
952
- constructor({ query, mutation, subscription, types } = {}, context) {
953
- if (query != null) this.query = query;
954
- if (mutation != null) this.mutation = mutation;
955
- if (subscription != null) this.subscription = subscription;
1028
+ constructor({ query: query2, mutation: mutation2, subscription: subscription2, types } = {}, context) {
1029
+ if (query2 != null) this.query = query2;
1030
+ if (mutation2 != null) this.mutation = mutation2;
1031
+ if (subscription2 != null) this.subscription = subscription2;
956
1032
  if (types != null) this.types = types.slice();
957
1033
  this.context = context ?? initWeaverContext();
958
1034
  }
@@ -962,8 +1038,12 @@ var SchemaWeaver = class _SchemaWeaver {
962
1038
  this.resolverOptions.middlewares.push(...middlewares);
963
1039
  return this;
964
1040
  }
965
- add(resolver) {
966
- provideWeaverContext(() => this.addResolver(resolver), this.context);
1041
+ add(resolver2) {
1042
+ provideWeaverContext(() => this.addResolver(resolver2), this.context);
1043
+ return this;
1044
+ }
1045
+ addVendor(weaver) {
1046
+ this.context.vendorWeavers.set(weaver.vendor, weaver);
967
1047
  return this;
968
1048
  }
969
1049
  addType(silk2) {
@@ -992,19 +1072,19 @@ var SchemaWeaver = class _SchemaWeaver {
992
1072
  return this;
993
1073
  }
994
1074
  weaveGraphQLSchema() {
995
- const { query, mutation, subscription, types } = this;
1075
+ const { query: query2, mutation: mutation2, subscription: subscription2, types } = this;
996
1076
  const config = this.context.getConfig("gqloom.core.schema");
997
1077
  const schema = new GraphQLSchema({
998
- query,
999
- mutation,
1000
- subscription,
1078
+ query: query2,
1079
+ mutation: mutation2,
1080
+ subscription: subscription2,
1001
1081
  types: [...types ?? [], ...config?.types ?? []],
1002
1082
  ...config
1003
1083
  });
1004
1084
  return schema;
1005
1085
  }
1006
- addResolver(resolver) {
1007
- const resolverOptions = ResolverOptionsMap.get(resolver);
1086
+ addResolver(resolver2) {
1087
+ const resolverOptions = ResolverOptionsMap.get(resolver2);
1008
1088
  const parent = resolverOptions?.parent;
1009
1089
  const parentObject = (() => {
1010
1090
  if (parent == null) return void 0;
@@ -1023,8 +1103,11 @@ var SchemaWeaver = class _SchemaWeaver {
1023
1103
  })();
1024
1104
  if (resolverOptions?.extensions && parentObject)
1025
1105
  parentObject.mergeExtensions(resolverOptions.extensions);
1026
- Object.entries(resolver).forEach(([name, operation]) => {
1027
- if (operation.type === "field") {
1106
+ Object.entries(resolver2).forEach(([name, operation]) => {
1107
+ if (operation === FIELD_HIDDEN) {
1108
+ if (parentObject == null) return;
1109
+ parentObject.hideField(name);
1110
+ } else if (operation.type === "field") {
1028
1111
  if (parentObject == null) return;
1029
1112
  parentObject.addField(name, operation);
1030
1113
  } else {
@@ -1068,12 +1151,16 @@ var SchemaWeaver = class _SchemaWeaver {
1068
1151
  const middlewares = /* @__PURE__ */ new Set();
1069
1152
  const resolvers = /* @__PURE__ */ new Set();
1070
1153
  const silks = /* @__PURE__ */ new Set();
1154
+ const weavers = /* @__PURE__ */ new Set();
1071
1155
  let context;
1072
1156
  for (const item of inputs) {
1073
- if (typeof item === "function") {
1157
+ if (isSchemaVendorWeaver(item)) {
1158
+ weavers.add(item);
1159
+ } else if (typeof item === "function") {
1074
1160
  middlewares.add(item);
1075
1161
  } else if (WEAVER_CONFIG in item) {
1076
1162
  configs.add(item);
1163
+ if (item.vendorWeaver) weavers.add(item.vendorWeaver);
1077
1164
  if (item[WEAVER_CONFIG] === "gqloom.core.schema") {
1078
1165
  context = item.weaverContext;
1079
1166
  }
@@ -1083,7 +1170,7 @@ var SchemaWeaver = class _SchemaWeaver {
1083
1170
  resolvers.add(item);
1084
1171
  }
1085
1172
  }
1086
- return { context, configs, middlewares, resolvers, silks };
1173
+ return { context, configs, middlewares, resolvers, silks, weavers };
1087
1174
  }
1088
1175
  /**
1089
1176
  * Weave a GraphQL Schema from resolvers
@@ -1091,9 +1178,10 @@ var SchemaWeaver = class _SchemaWeaver {
1091
1178
  * @returns GraphQ LSchema
1092
1179
  */
1093
1180
  static weave(...inputs) {
1094
- const { context, configs, middlewares, resolvers, silks } = _SchemaWeaver.optionsFrom(...inputs);
1181
+ const { context, configs, middlewares, resolvers, silks, weavers } = _SchemaWeaver.optionsFrom(...inputs);
1095
1182
  const weaver = new _SchemaWeaver({}, context);
1096
1183
  configs.forEach((it) => weaver.setConfig(it));
1184
+ weavers.forEach((it) => weaver.addVendor(it));
1097
1185
  middlewares.forEach((it) => weaver.use(it));
1098
1186
  resolvers.forEach((it) => weaver.add(it));
1099
1187
  silks.forEach((it) => weaver.addType(it));
@@ -1124,18 +1212,13 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
1124
1212
  const interfaceType = new GraphQLInterfaceType({
1125
1213
  ...config,
1126
1214
  ...interfaceConfig,
1127
- fields: mapValue(fields, (field) => {
1128
- return { ...field, type: getCacheType(field.type) };
1215
+ fields: mapValue(fields, (field2) => {
1216
+ return { ...field2, type: getCacheType(field2.type) };
1129
1217
  })
1130
1218
  });
1131
1219
  weaverContext.interfaceMap?.set(key, interfaceType);
1132
1220
  return interfaceType;
1133
1221
  }
1134
-
1135
- // src/schema/extensions.ts
1136
- function mergeExtensions(...extensionsList) {
1137
- return deepMerge(...extensionsList);
1138
- }
1139
1222
  export {
1140
1223
  ContextMemoization,
1141
1224
  LoomObjectType,
@@ -1144,36 +1227,40 @@ export {
1144
1227
  SchemaWeaver,
1145
1228
  applyMiddlewares,
1146
1229
  baseResolver,
1230
+ collectName,
1147
1231
  collectNames,
1148
1232
  compose,
1149
- createFieldBobbin,
1233
+ createFieldFactory,
1150
1234
  createInputParser,
1151
1235
  createLoom,
1152
1236
  createMemoization,
1153
- createMutationBobbin,
1154
- createQueryBobbin,
1155
- createResolverBobbin,
1156
- createSubscriptionBobbin,
1237
+ createMutationFactory,
1238
+ createQueryFactory,
1239
+ createResolverFactory,
1240
+ createSubscriptionFactory,
1157
1241
  deepMerge,
1158
1242
  defaultSubscriptionResolve,
1159
1243
  ensureInputObjectType,
1160
1244
  ensureInputType,
1161
1245
  ensureInterfaceType,
1246
+ field,
1162
1247
  getCacheType,
1163
1248
  getFieldOptions,
1164
1249
  getGraphQLType,
1165
1250
  getOperationOptions,
1251
+ getStandardValue,
1166
1252
  getSubscriptionOptions,
1167
1253
  initWeaverContext,
1168
1254
  inputToArgs,
1169
1255
  isOnlyMemoryPayload,
1256
+ isSchemaVendorWeaver,
1170
1257
  isSilk,
1171
1258
  listSilk,
1172
1259
  loom,
1173
1260
  mapValue,
1174
1261
  markErrorLocation,
1175
1262
  markLocation,
1176
- mergeExtensions,
1263
+ mutation,
1177
1264
  nonNullSilk,
1178
1265
  notNullish,
1179
1266
  nullableSilk,
@@ -1181,13 +1268,11 @@ export {
1181
1268
  parseInputValue,
1182
1269
  parseSilk,
1183
1270
  provideWeaverContext,
1271
+ query,
1272
+ resolver,
1184
1273
  resolverPayloadStorage,
1185
1274
  silk,
1186
- silkField,
1187
- silkMutation,
1188
- silkQuery,
1189
- silkResolver,
1190
- silkSubscription,
1275
+ subscription,
1191
1276
  toObjMap,
1192
1277
  tryIn,
1193
1278
  useContext,