@gqloom/core 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -13
- package/dist/index.cjs +287 -12
- package/dist/index.d.cts +111 -8
- package/dist/index.d.ts +111 -8
- package/dist/index.js +281 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,18 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
# GQLoom
|
|
4
4
|
|
|
5
|
-
GQLoom is a
|
|
5
|
+
GQLoom is a **Code First** GraphQL Schema Loom used to weave **runtime types** in the **TypeScript/JavaScript** ecosystem into a GraphQL Schema.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Runtime validation libraries such as [Zod](https://zod.dev/), [Valibot](https://valibot.dev/), and [Yup](https://github.com/jquense/yup) have been widely used in backend application development. Meanwhile, when using ORM libraries like [Prisma](https://www.prisma.io/), [MikroORM](https://mikro-orm.io/), and [Drizzle](https://orm.drizzle.team/), we also pre - define database table structures or entity models that contain runtime types.
|
|
8
|
+
The responsibility of GQLoom is to weave these runtime types into a GraphQL Schema.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* 🚀 GraphQL: flexible and efficient, reducing redundant data transfers;
|
|
12
|
-
* 🔒 Robust type safety: enjoy intelligent hints at development time to detect potential problems at compile time;
|
|
13
|
-
* 🔋 Ready to go: middleware, contexts, subscriptions, federated graphs are ready to go;
|
|
14
|
-
* 🔮 No extra magic: no decorators, no metadata and reflection, no code generation, you just need JavaScript/TypeScript;
|
|
15
|
-
* 🧩 Familiar schema libraries: use the schema libraries you already know (Zod, Yup, Valibot) to build GraphQL Schema and validate inputs;
|
|
16
|
-
* 🧑💻 Develop happily: highly readable and semantic APIs designed to keep your code tidy;
|
|
10
|
+
When developing backend applications with GQLoom, you only need to write types using the Schema libraries you're familiar with. Modern Schema libraries will infer TypeScript types for you, and GQLoom will weave GraphQL types for you.
|
|
11
|
+
In addition, the **resolver factory** of GQLoom can create CRUD interfaces for `Prisma`, `MikroORM`, and `Drizzle`, and supports custom input and adding middleware.
|
|
17
12
|
|
|
18
13
|
## Hello World
|
|
19
14
|
|
|
@@ -22,14 +17,23 @@ import { resolver, query, ValibotWeaver } from "@gqloom/valibot"
|
|
|
22
17
|
import * as v from "valibot"
|
|
23
18
|
|
|
24
19
|
const helloResolver = resolver({
|
|
25
|
-
hello: query(v.string()
|
|
20
|
+
hello: query(v.string())
|
|
21
|
+
.input({ name: v.nullish(v.string(), "World") })
|
|
22
|
+
.resolve(({ name }) => `Hello, ${name}!`),
|
|
26
23
|
})
|
|
27
24
|
|
|
28
25
|
export const schema = ValibotWeaver.weave(helloResolver)
|
|
29
26
|
```
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
## Highlights you should not miss
|
|
29
|
+
|
|
30
|
+
- 🧑💻 **Development Experience**: Fewer boilerplate codes, semantic API design, and extensive ecosystem integration make development enjoyable.
|
|
31
|
+
- 🔒 **Type Safety**: Automatically infer types from the Schema, enjoy intelligent code completion during development, and detect potential problems during compilation.
|
|
32
|
+
- 🎯 **Interface Factory**: Ordinary CRUD interfaces are too simple yet too cumbersome. Let the resolver factory create them quickly.
|
|
33
|
+
- 🔋 **Fully Prepared**: Middleware, context, subscriptions, and federated graphs are ready.
|
|
34
|
+
- 🔮 **No Magic**: Without decorators, metadata, reflection, or code generation, it can run anywhere with just JavaScript/TypeScript.
|
|
35
|
+
- 🧩 **Rich Integration**: Use your most familiar validation libraries and ORMs to build your next GraphQL application.
|
|
32
36
|
|
|
33
37
|
## Getting Started
|
|
34
38
|
|
|
35
|
-
See [Getting Started](https://gqloom.dev/guide/getting-started.html) to learn how to use GQLoom.
|
|
39
|
+
See [Getting Started](https://gqloom.dev/guide/getting-started.html) to learn how to use GQLoom.
|
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
ContextMemoization: () => ContextMemoization,
|
|
24
|
+
EasyDataLoader: () => EasyDataLoader,
|
|
24
25
|
GraphQLSchemaLoom: () => GraphQLSchemaLoom,
|
|
25
26
|
LoomObjectType: () => LoomObjectType,
|
|
26
27
|
OPERATION_OBJECT_NAMES: () => OPERATION_OBJECT_NAMES,
|
|
@@ -28,16 +29,21 @@ __export(src_exports, {
|
|
|
28
29
|
SYMBOLS: () => symbols_exports,
|
|
29
30
|
applyMiddlewares: () => applyMiddlewares,
|
|
30
31
|
baseResolver: () => baseResolver,
|
|
32
|
+
capitalize: () => capitalize,
|
|
31
33
|
collectName: () => collectName,
|
|
32
34
|
collectNames: () => collectNames,
|
|
33
35
|
compose: () => compose,
|
|
36
|
+
createField: () => createField,
|
|
34
37
|
createFieldFactory: () => createFieldFactory,
|
|
35
38
|
createInputParser: () => createInputParser,
|
|
36
39
|
createLoom: () => createLoom,
|
|
37
40
|
createMemoization: () => createMemoization,
|
|
41
|
+
createMutation: () => createMutation,
|
|
38
42
|
createMutationFactory: () => createMutationFactory,
|
|
43
|
+
createQuery: () => createQuery,
|
|
39
44
|
createQueryFactory: () => createQueryFactory,
|
|
40
45
|
createResolverFactory: () => createResolverFactory,
|
|
46
|
+
createSubscription: () => createSubscription,
|
|
41
47
|
createSubscriptionFactory: () => createSubscriptionFactory,
|
|
42
48
|
deepMerge: () => deepMerge,
|
|
43
49
|
defaultSubscriptionResolve: () => defaultSubscriptionResolve,
|
|
@@ -265,7 +271,7 @@ function listSilk(origin) {
|
|
|
265
271
|
[GET_GRAPHQL_TYPE]: () => {
|
|
266
272
|
let originType = getGraphQLType(origin);
|
|
267
273
|
if (originType instanceof import_graphql2.GraphQLNonNull && originType.ofType instanceof import_graphql2.GraphQLList) {
|
|
268
|
-
originType = originType.ofType;
|
|
274
|
+
originType = originType.ofType.ofType;
|
|
269
275
|
}
|
|
270
276
|
if (originType instanceof import_graphql2.GraphQLList) {
|
|
271
277
|
originType = originType.ofType;
|
|
@@ -505,6 +511,9 @@ function pascalCase(str) {
|
|
|
505
511
|
(word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
|
|
506
512
|
).join("");
|
|
507
513
|
}
|
|
514
|
+
function capitalize(str) {
|
|
515
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
516
|
+
}
|
|
508
517
|
|
|
509
518
|
// src/utils/error.ts
|
|
510
519
|
function markErrorLocation(error, ...locations) {
|
|
@@ -534,6 +543,72 @@ function markLocation(message, ...locations) {
|
|
|
534
543
|
return `[${combinedLocation}] ${newMessage}`;
|
|
535
544
|
}
|
|
536
545
|
|
|
546
|
+
// src/utils/loader.ts
|
|
547
|
+
var EasyDataLoader = class _EasyDataLoader {
|
|
548
|
+
constructor(batchLoadFn) {
|
|
549
|
+
this.batchLoadFn = batchLoadFn;
|
|
550
|
+
this.queue = [];
|
|
551
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
552
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
553
|
+
}
|
|
554
|
+
queue;
|
|
555
|
+
cache;
|
|
556
|
+
resolvers;
|
|
557
|
+
load(key) {
|
|
558
|
+
const existing = this.cache.get(key);
|
|
559
|
+
if (existing) return existing;
|
|
560
|
+
const promise = new Promise((resolve, reject) => {
|
|
561
|
+
this.queue.push(key);
|
|
562
|
+
this.resolvers.set(key, [resolve, reject]);
|
|
563
|
+
this.nextTickBatchLoad();
|
|
564
|
+
});
|
|
565
|
+
this.cache.set(key, promise);
|
|
566
|
+
return promise;
|
|
567
|
+
}
|
|
568
|
+
clear() {
|
|
569
|
+
this.queue = [];
|
|
570
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
571
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
572
|
+
}
|
|
573
|
+
clearByKey(key) {
|
|
574
|
+
this.queue = this.queue.filter((k) => k !== key);
|
|
575
|
+
this.cache.delete(key);
|
|
576
|
+
this.resolvers.delete(key);
|
|
577
|
+
}
|
|
578
|
+
async executeBatchLoad() {
|
|
579
|
+
if (this.queue.length === 0) return;
|
|
580
|
+
const [keys, resolvers] = [this.queue, this.resolvers];
|
|
581
|
+
this.queue = [];
|
|
582
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
583
|
+
try {
|
|
584
|
+
const list = await this.batchLoadFn(keys);
|
|
585
|
+
for (let i = 0; i < list.length; i++) {
|
|
586
|
+
const data = list[i];
|
|
587
|
+
const resolve = resolvers.get(keys[i])?.[0];
|
|
588
|
+
const reject = resolvers.get(keys[i])?.[1];
|
|
589
|
+
if (data instanceof Error) {
|
|
590
|
+
reject?.(data);
|
|
591
|
+
} else {
|
|
592
|
+
resolve?.(data);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
} catch (error) {
|
|
596
|
+
for (const key of keys) {
|
|
597
|
+
const reject = resolvers.get(key)?.[1];
|
|
598
|
+
reject?.(error);
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
nextTickPromise;
|
|
603
|
+
nextTickBatchLoad() {
|
|
604
|
+
this.nextTickPromise ??= _EasyDataLoader.nextTick().then(() => this.executeBatchLoad()).finally(() => this.nextTickPromise = void 0);
|
|
605
|
+
return this.nextTickPromise;
|
|
606
|
+
}
|
|
607
|
+
static nextTick() {
|
|
608
|
+
return new Promise((resolve) => setTimeout(resolve));
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
|
|
537
612
|
// src/resolver/input.ts
|
|
538
613
|
var import_graphql3 = require("graphql");
|
|
539
614
|
function createInputParser(schema, value) {
|
|
@@ -587,8 +662,168 @@ function getStandardValue(result) {
|
|
|
587
662
|
else throw new import_graphql3.GraphQLError("Invalid input");
|
|
588
663
|
}
|
|
589
664
|
|
|
665
|
+
// src/resolver/resolver-chain-factory.ts
|
|
666
|
+
var BaseChainFactory = class _BaseChainFactory {
|
|
667
|
+
constructor(options) {
|
|
668
|
+
this.options = options;
|
|
669
|
+
}
|
|
670
|
+
static methods() {
|
|
671
|
+
return {
|
|
672
|
+
description: _BaseChainFactory.prototype.description,
|
|
673
|
+
deprecationReason: _BaseChainFactory.prototype.deprecationReason,
|
|
674
|
+
extensions: _BaseChainFactory.prototype.extensions
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
description(description) {
|
|
678
|
+
return this.clone({ description });
|
|
679
|
+
}
|
|
680
|
+
deprecationReason(deprecationReason) {
|
|
681
|
+
return this.clone({ deprecationReason });
|
|
682
|
+
}
|
|
683
|
+
extensions(extensions) {
|
|
684
|
+
return this.clone({ extensions });
|
|
685
|
+
}
|
|
686
|
+
use(...middlewares) {
|
|
687
|
+
return this.clone({
|
|
688
|
+
middlewares: [...this.options?.middlewares ?? [], ...middlewares]
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
|
|
693
|
+
static methods() {
|
|
694
|
+
return {
|
|
695
|
+
...BaseChainFactory.methods(),
|
|
696
|
+
output: _FieldChainFactory.prototype.output,
|
|
697
|
+
input: _FieldChainFactory.prototype.input,
|
|
698
|
+
resolve: _FieldChainFactory.prototype.resolve,
|
|
699
|
+
clone: _FieldChainFactory.prototype.clone
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
clone(options) {
|
|
703
|
+
return new _FieldChainFactory({ ...this.options, ...options });
|
|
704
|
+
}
|
|
705
|
+
use(...middlewares) {
|
|
706
|
+
return super.use(...middlewares);
|
|
707
|
+
}
|
|
708
|
+
output(output) {
|
|
709
|
+
return new _FieldChainFactory({ ...this.options, output });
|
|
710
|
+
}
|
|
711
|
+
input(input) {
|
|
712
|
+
return new _FieldChainFactory({ ...this.options, input });
|
|
713
|
+
}
|
|
714
|
+
resolve(resolve) {
|
|
715
|
+
return createField(this.options?.output, {
|
|
716
|
+
...this.options,
|
|
717
|
+
resolve
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
var QueryChainFactory = class _QueryChainFactory extends BaseChainFactory {
|
|
722
|
+
static methods() {
|
|
723
|
+
return {
|
|
724
|
+
...BaseChainFactory.methods(),
|
|
725
|
+
output: _QueryChainFactory.prototype.output,
|
|
726
|
+
input: _QueryChainFactory.prototype.input,
|
|
727
|
+
resolve: _QueryChainFactory.prototype.resolve,
|
|
728
|
+
clone: _QueryChainFactory.prototype.clone
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
clone(options) {
|
|
732
|
+
return new _QueryChainFactory({ ...this.options, ...options });
|
|
733
|
+
}
|
|
734
|
+
use(...middlewares) {
|
|
735
|
+
return super.use(...middlewares);
|
|
736
|
+
}
|
|
737
|
+
output(output) {
|
|
738
|
+
return new _QueryChainFactory({ ...this.options, output });
|
|
739
|
+
}
|
|
740
|
+
input(input) {
|
|
741
|
+
return new _QueryChainFactory({ ...this.options, input });
|
|
742
|
+
}
|
|
743
|
+
resolve(resolve) {
|
|
744
|
+
return createQuery(this.options?.output, {
|
|
745
|
+
...this.options,
|
|
746
|
+
resolve
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
var MutationChainFactory = class _MutationChainFactory extends BaseChainFactory {
|
|
751
|
+
static methods() {
|
|
752
|
+
return {
|
|
753
|
+
...BaseChainFactory.methods(),
|
|
754
|
+
output: _MutationChainFactory.prototype.output,
|
|
755
|
+
input: _MutationChainFactory.prototype.input,
|
|
756
|
+
resolve: _MutationChainFactory.prototype.resolve,
|
|
757
|
+
clone: _MutationChainFactory.prototype.clone
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
clone(options) {
|
|
761
|
+
return new _MutationChainFactory({ ...this.options, ...options });
|
|
762
|
+
}
|
|
763
|
+
use(...middlewares) {
|
|
764
|
+
return super.use(...middlewares);
|
|
765
|
+
}
|
|
766
|
+
output(output) {
|
|
767
|
+
return new _MutationChainFactory({ ...this.options, output });
|
|
768
|
+
}
|
|
769
|
+
input(input) {
|
|
770
|
+
return new _MutationChainFactory({ ...this.options, input });
|
|
771
|
+
}
|
|
772
|
+
resolve(resolve) {
|
|
773
|
+
return createMutation(this.options?.output, {
|
|
774
|
+
...this.options,
|
|
775
|
+
resolve
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
var SubscriptionChainFactory = class _SubscriptionChainFactory extends BaseChainFactory {
|
|
780
|
+
static methods() {
|
|
781
|
+
return {
|
|
782
|
+
...BaseChainFactory.methods(),
|
|
783
|
+
output: _SubscriptionChainFactory.prototype.output,
|
|
784
|
+
input: _SubscriptionChainFactory.prototype.input,
|
|
785
|
+
subscribe: _SubscriptionChainFactory.prototype.subscribe,
|
|
786
|
+
clone: _SubscriptionChainFactory.prototype.clone
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
clone(options) {
|
|
790
|
+
return new _SubscriptionChainFactory({ ...this.options, ...options });
|
|
791
|
+
}
|
|
792
|
+
use(...middlewares) {
|
|
793
|
+
return super.use(...middlewares);
|
|
794
|
+
}
|
|
795
|
+
output(output) {
|
|
796
|
+
return new _SubscriptionChainFactory({ ...this.options, output });
|
|
797
|
+
}
|
|
798
|
+
input(input) {
|
|
799
|
+
return new _SubscriptionChainFactory({ ...this.options, input });
|
|
800
|
+
}
|
|
801
|
+
subscribe(subscribe) {
|
|
802
|
+
const options = this.options;
|
|
803
|
+
const subscription2 = createSubscription(options?.output, {
|
|
804
|
+
...options,
|
|
805
|
+
subscribe
|
|
806
|
+
});
|
|
807
|
+
const subscriptionResolve = subscription2.resolve;
|
|
808
|
+
const resolve = (...args) => {
|
|
809
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
810
|
+
return createSubscription(options?.output, {
|
|
811
|
+
...options,
|
|
812
|
+
resolve: args[0],
|
|
813
|
+
subscribe
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
return subscriptionResolve(...args);
|
|
817
|
+
};
|
|
818
|
+
return Object.assign(subscription2, { resolve });
|
|
819
|
+
}
|
|
820
|
+
};
|
|
821
|
+
|
|
590
822
|
// src/resolver/resolver.ts
|
|
591
|
-
var
|
|
823
|
+
var createQuery = (output, resolveOrOptions) => {
|
|
824
|
+
if (resolveOrOptions == null) {
|
|
825
|
+
return new QueryChainFactory({ output });
|
|
826
|
+
}
|
|
592
827
|
const options = getOperationOptions(resolveOrOptions);
|
|
593
828
|
const type = "query";
|
|
594
829
|
return {
|
|
@@ -606,7 +841,14 @@ var query = (output, resolveOrOptions) => {
|
|
|
606
841
|
type
|
|
607
842
|
};
|
|
608
843
|
};
|
|
609
|
-
var
|
|
844
|
+
var query = Object.assign(
|
|
845
|
+
createQuery,
|
|
846
|
+
QueryChainFactory.methods()
|
|
847
|
+
);
|
|
848
|
+
var createMutation = (output, resolveOrOptions) => {
|
|
849
|
+
if (resolveOrOptions == null) {
|
|
850
|
+
return new MutationChainFactory({ output });
|
|
851
|
+
}
|
|
610
852
|
const options = getOperationOptions(resolveOrOptions);
|
|
611
853
|
const type = "mutation";
|
|
612
854
|
return {
|
|
@@ -624,7 +866,14 @@ var mutation = (output, resolveOrOptions) => {
|
|
|
624
866
|
type
|
|
625
867
|
};
|
|
626
868
|
};
|
|
627
|
-
var
|
|
869
|
+
var mutation = Object.assign(
|
|
870
|
+
createMutation,
|
|
871
|
+
MutationChainFactory.methods()
|
|
872
|
+
);
|
|
873
|
+
var createField = (output, resolveOrOptions) => {
|
|
874
|
+
if (resolveOrOptions == null) {
|
|
875
|
+
return new FieldChainFactory({ output });
|
|
876
|
+
}
|
|
628
877
|
const options = getOperationOptions(resolveOrOptions);
|
|
629
878
|
const type = "field";
|
|
630
879
|
return {
|
|
@@ -643,13 +892,15 @@ var baseSilkField = (output, resolveOrOptions) => {
|
|
|
643
892
|
};
|
|
644
893
|
};
|
|
645
894
|
var field = Object.assign(
|
|
646
|
-
|
|
647
|
-
{
|
|
648
|
-
|
|
649
|
-
}
|
|
895
|
+
createField,
|
|
896
|
+
{ hidden: FIELD_HIDDEN },
|
|
897
|
+
FieldChainFactory.methods()
|
|
650
898
|
);
|
|
651
899
|
var defaultSubscriptionResolve = (source) => source;
|
|
652
|
-
var
|
|
900
|
+
var createSubscription = (output, subscribeOrOptions) => {
|
|
901
|
+
if (subscribeOrOptions == null) {
|
|
902
|
+
return new SubscriptionChainFactory({ output });
|
|
903
|
+
}
|
|
653
904
|
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
654
905
|
const type = "subscription";
|
|
655
906
|
return {
|
|
@@ -671,6 +922,10 @@ var subscription = (output, subscribeOrOptions) => {
|
|
|
671
922
|
type
|
|
672
923
|
};
|
|
673
924
|
};
|
|
925
|
+
var subscription = Object.assign(
|
|
926
|
+
createSubscription,
|
|
927
|
+
SubscriptionChainFactory.methods()
|
|
928
|
+
);
|
|
674
929
|
var ResolverOptionsMap = /* @__PURE__ */ new WeakMap();
|
|
675
930
|
function baseResolver(operations, options) {
|
|
676
931
|
const record = {};
|
|
@@ -751,6 +1006,9 @@ function createResolverFactory(toSilk) {
|
|
|
751
1006
|
}
|
|
752
1007
|
function createFieldFactory(toSilk, isSchema) {
|
|
753
1008
|
const baseFieldFunc = (output, resolveOrOptions) => {
|
|
1009
|
+
if (resolveOrOptions == null) {
|
|
1010
|
+
return new FieldChainFactory({ output: toSilk(output) });
|
|
1011
|
+
}
|
|
754
1012
|
const options = getOperationOptions(
|
|
755
1013
|
resolveOrOptions
|
|
756
1014
|
);
|
|
@@ -759,12 +1017,17 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
759
1017
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
760
1018
|
});
|
|
761
1019
|
};
|
|
762
|
-
return Object.assign(
|
|
763
|
-
|
|
764
|
-
|
|
1020
|
+
return Object.assign(
|
|
1021
|
+
baseFieldFunc,
|
|
1022
|
+
{ hidden: FIELD_HIDDEN },
|
|
1023
|
+
FieldChainFactory.methods()
|
|
1024
|
+
);
|
|
765
1025
|
}
|
|
766
1026
|
function createQueryFactory(toSilk, isSchema) {
|
|
767
1027
|
return (output, resolveOrOptions) => {
|
|
1028
|
+
if (resolveOrOptions == null) {
|
|
1029
|
+
return new QueryChainFactory({ output: toSilk(output) });
|
|
1030
|
+
}
|
|
768
1031
|
const options = getOperationOptions(resolveOrOptions);
|
|
769
1032
|
return query(toSilk(output), {
|
|
770
1033
|
...options,
|
|
@@ -774,6 +1037,9 @@ function createQueryFactory(toSilk, isSchema) {
|
|
|
774
1037
|
}
|
|
775
1038
|
function createMutationFactory(toSilk, isSchema) {
|
|
776
1039
|
return (output, resolveOrOptions) => {
|
|
1040
|
+
if (resolveOrOptions == null) {
|
|
1041
|
+
return new MutationChainFactory({ output: toSilk(output) });
|
|
1042
|
+
}
|
|
777
1043
|
const options = getOperationOptions(resolveOrOptions);
|
|
778
1044
|
return mutation(toSilk(output), {
|
|
779
1045
|
...options,
|
|
@@ -783,6 +1049,9 @@ function createMutationFactory(toSilk, isSchema) {
|
|
|
783
1049
|
}
|
|
784
1050
|
function createSubscriptionFactory(toSilk, isSchema) {
|
|
785
1051
|
return (output, resolveOrOptions) => {
|
|
1052
|
+
if (resolveOrOptions == null) {
|
|
1053
|
+
return new SubscriptionChainFactory({ output: toSilk(output) });
|
|
1054
|
+
}
|
|
786
1055
|
const options = getSubscriptionOptions(resolveOrOptions);
|
|
787
1056
|
return subscription(toSilk(output), {
|
|
788
1057
|
...options,
|
|
@@ -1333,6 +1602,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1333
1602
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1334
1603
|
0 && (module.exports = {
|
|
1335
1604
|
ContextMemoization,
|
|
1605
|
+
EasyDataLoader,
|
|
1336
1606
|
GraphQLSchemaLoom,
|
|
1337
1607
|
LoomObjectType,
|
|
1338
1608
|
OPERATION_OBJECT_NAMES,
|
|
@@ -1340,16 +1610,21 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1340
1610
|
SYMBOLS,
|
|
1341
1611
|
applyMiddlewares,
|
|
1342
1612
|
baseResolver,
|
|
1613
|
+
capitalize,
|
|
1343
1614
|
collectName,
|
|
1344
1615
|
collectNames,
|
|
1345
1616
|
compose,
|
|
1617
|
+
createField,
|
|
1346
1618
|
createFieldFactory,
|
|
1347
1619
|
createInputParser,
|
|
1348
1620
|
createLoom,
|
|
1349
1621
|
createMemoization,
|
|
1622
|
+
createMutation,
|
|
1350
1623
|
createMutationFactory,
|
|
1624
|
+
createQuery,
|
|
1351
1625
|
createQueryFactory,
|
|
1352
1626
|
createResolverFactory,
|
|
1627
|
+
createSubscription,
|
|
1353
1628
|
createSubscriptionFactory,
|
|
1354
1629
|
deepMerge,
|
|
1355
1630
|
defaultSubscriptionResolve,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as graphql from 'graphql';
|
|
1
2
|
import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
|
|
3
|
+
import * as graphql_jsutils_Maybe from 'graphql/jsutils/Maybe';
|
|
2
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -195,6 +197,70 @@ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T>): T;
|
|
|
195
197
|
declare function getStandardValue<T>(result?: StandardSchemaV1.Result<T>): T | undefined;
|
|
196
198
|
declare function getStandardValue<T>(result: StandardSchemaV1.Result<T> | null): T | null;
|
|
197
199
|
|
|
200
|
+
interface IChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined> {
|
|
201
|
+
description(description: GraphQLFieldOptions["description"]): this;
|
|
202
|
+
deprecationReason(deprecationReason: GraphQLFieldOptions["deprecationReason"]): this;
|
|
203
|
+
extensions(extensions: GraphQLFieldOptions["extensions"]): this;
|
|
204
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): IChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
205
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): IChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
206
|
+
}
|
|
207
|
+
declare abstract class BaseChainFactory {
|
|
208
|
+
protected readonly options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
209
|
+
middlewares: Middleware[];
|
|
210
|
+
}> | undefined;
|
|
211
|
+
static methods(): {
|
|
212
|
+
description: (description: graphql_jsutils_Maybe.Maybe<string>) => BaseChainFactory;
|
|
213
|
+
deprecationReason: (deprecationReason: graphql_jsutils_Maybe.Maybe<string>) => BaseChainFactory;
|
|
214
|
+
extensions: (extensions: graphql_jsutils_Maybe.Maybe<Readonly<graphql.GraphQLFieldExtensions<any, any, any>>>) => BaseChainFactory;
|
|
215
|
+
};
|
|
216
|
+
constructor(options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
217
|
+
middlewares: Middleware[];
|
|
218
|
+
}> | undefined);
|
|
219
|
+
protected abstract clone(options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
220
|
+
middlewares: Middleware[];
|
|
221
|
+
}>): this;
|
|
222
|
+
description(description: GraphQLFieldOptions["description"]): this;
|
|
223
|
+
deprecationReason(deprecationReason: GraphQLFieldOptions["deprecationReason"]): this;
|
|
224
|
+
extensions(extensions: GraphQLFieldOptions["extensions"]): this;
|
|
225
|
+
use(...middlewares: Middleware[]): this;
|
|
226
|
+
}
|
|
227
|
+
declare class FieldChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
228
|
+
static methods(): FieldChainFactory<any, never, undefined>;
|
|
229
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
230
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">>[]): this;
|
|
231
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): FieldChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
232
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): FieldChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
233
|
+
resolve<TParent extends TSchemaIO[0]>(resolve: (parent: InferSchemaO<TParent, TSchemaIO>, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">;
|
|
234
|
+
}
|
|
235
|
+
declare class QueryChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
236
|
+
static methods(): QueryChainFactory<any, never, undefined>;
|
|
237
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
238
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query">>[]): this;
|
|
239
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): QueryChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
240
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): QueryChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
241
|
+
resolve(resolve: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): any;
|
|
242
|
+
}
|
|
243
|
+
declare class MutationChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
244
|
+
static methods(): MutationChainFactory<any, never, undefined>;
|
|
245
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
246
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "mutation">>[]): this;
|
|
247
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): MutationChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
248
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): MutationChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
249
|
+
resolve(resolve: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): any;
|
|
250
|
+
}
|
|
251
|
+
declare class SubscriptionChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
252
|
+
static methods(): SubscriptionChainFactory<any, never, undefined>;
|
|
253
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
254
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "subscription">>[]): this;
|
|
255
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): SubscriptionChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
256
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): SubscriptionChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
257
|
+
subscribe<TValue = InferSchemaO<TOutput, TSchemaIO>>(subscribe: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<AsyncIterator<TValue>>): ResolvableSubscription<TSchemaIO, TOutput, TInput, TValue>;
|
|
258
|
+
}
|
|
259
|
+
interface ResolvableSubscription<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined, TValue = InferSchemaO<TOutput, TSchemaIO>> extends Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue> {
|
|
260
|
+
resolve(resolve: (value: TValue, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue>;
|
|
261
|
+
resolve(value: TValue, input: any): MayPromise<any>;
|
|
262
|
+
}
|
|
263
|
+
|
|
198
264
|
interface GraphQLSilk<TOutput = any, TInput = any> extends StandardSchemaV1<TInput, TOutput> {
|
|
199
265
|
/**
|
|
200
266
|
* GraphQL type for schema
|
|
@@ -254,12 +320,21 @@ interface QueryMutationOptions<TSchemaIO extends AbstractSchemaIO, TOutput exten
|
|
|
254
320
|
*/
|
|
255
321
|
interface QueryFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
256
322
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query">;
|
|
323
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): QueryChainFactory<TSchemaIO, TOutput, undefined>;
|
|
324
|
+
}
|
|
325
|
+
interface QueryFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends QueryFactory<TSchemaIO>, QueryChainFactory<TSchemaIO, never, undefined> {
|
|
257
326
|
}
|
|
258
327
|
/**
|
|
259
328
|
* Function to create a GraphQL mutation.
|
|
260
329
|
*/
|
|
261
330
|
interface MutationFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
262
331
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "mutation">;
|
|
332
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): MutationChainFactory<TSchemaIO, TOutput, undefined>;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Function to create a GraphQL mutation.
|
|
336
|
+
*/
|
|
337
|
+
interface MutationFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends MutationFactory<TSchemaIO>, MutationChainFactory<TSchemaIO, never, undefined> {
|
|
263
338
|
}
|
|
264
339
|
/**
|
|
265
340
|
* Options for External Filed of existing GraphQL Object.
|
|
@@ -273,8 +348,9 @@ interface FieldOptions<TSchemaIO extends AbstractSchemaIO, TParent extends TSche
|
|
|
273
348
|
*/
|
|
274
349
|
interface FieldFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
275
350
|
<TParent extends TSchemaIO[0], TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: ((parent: InferSchemaO<TParent, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | FieldOptions<TSchemaIO, TParent, TOutput, TInput>): FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">;
|
|
351
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): FieldChainFactory<TSchemaIO, TOutput, undefined>;
|
|
276
352
|
}
|
|
277
|
-
interface FieldFactoryWithUtils<TSchemaIO extends AbstractSchemaIO> extends FieldFactory<TSchemaIO> {
|
|
353
|
+
interface FieldFactoryWithUtils<TSchemaIO extends AbstractSchemaIO> extends FieldFactory<TSchemaIO>, FieldChainFactory<TSchemaIO, never, undefined> {
|
|
278
354
|
/** Set fields to be hidden in GraphQL Schema */
|
|
279
355
|
hidden: typeof FIELD_HIDDEN;
|
|
280
356
|
}
|
|
@@ -295,6 +371,9 @@ interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<G
|
|
|
295
371
|
*/
|
|
296
372
|
interface SubscriptionFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
297
373
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined, TValue = InferSchemaO<TOutput, TSchemaIO>>(output: TOutput, subscribeOrOptions: (() => MayPromise<AsyncIterator<InferSchemaO<TOutput, TSchemaIO>>>) | SubscriptionOptions<TSchemaIO, TOutput, TInput, TValue>): Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue>;
|
|
374
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): SubscriptionChainFactory<TSchemaIO, TOutput, undefined>;
|
|
375
|
+
}
|
|
376
|
+
interface SubscriptionFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends SubscriptionFactory<TSchemaIO>, SubscriptionChainFactory<TSchemaIO, never, undefined> {
|
|
298
377
|
}
|
|
299
378
|
interface ResolverFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
300
379
|
of<TParent extends TSchemaIO[0], TOperations extends Record<string, FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, any, any> | FieldOrOperation<undefined, any, any, OperationType> | typeof FIELD_HIDDEN>>(parent: TParent, operationOrFields: TOperations, options?: ResolverOptionsWithExtensions<OmitInUnion<ValueOf<TOperations>, typeof FIELD_HIDDEN>>): TOperations;
|
|
@@ -451,6 +530,7 @@ interface ReadOnlyObjMap<T> {
|
|
|
451
530
|
}
|
|
452
531
|
|
|
453
532
|
declare function pascalCase(str: string): string;
|
|
533
|
+
declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
454
534
|
|
|
455
535
|
declare function markErrorLocation<TError>(error: TError, ...locations: string[]): TError;
|
|
456
536
|
declare function tryIn<T>(func: () => T, ...locations: string[]): T;
|
|
@@ -466,6 +546,25 @@ declare function tryIn<T>(func: () => T, ...locations: string[]): T;
|
|
|
466
546
|
*/
|
|
467
547
|
declare function markLocation(message: string, ...locations: string[]): string;
|
|
468
548
|
|
|
549
|
+
type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
|
|
550
|
+
declare class EasyDataLoader<TKey, TData> {
|
|
551
|
+
protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
|
|
552
|
+
protected queue: TKey[];
|
|
553
|
+
protected cache: Map<TKey, Promise<TData>>;
|
|
554
|
+
protected resolvers: Map<TKey, [
|
|
555
|
+
resolve: (value: TData | PromiseLike<TData>) => void,
|
|
556
|
+
reject: (reason?: any) => void
|
|
557
|
+
]>;
|
|
558
|
+
constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
|
|
559
|
+
load(key: TKey): Promise<TData>;
|
|
560
|
+
clear(): void;
|
|
561
|
+
clearByKey(key: TKey): void;
|
|
562
|
+
protected executeBatchLoad(): Promise<void>;
|
|
563
|
+
protected nextTickPromise?: Promise<void>;
|
|
564
|
+
protected nextTickBatchLoad(): Promise<void>;
|
|
565
|
+
static nextTick(): Promise<void>;
|
|
566
|
+
}
|
|
567
|
+
|
|
469
568
|
/**
|
|
470
569
|
* Create a Silk from Scalar.
|
|
471
570
|
*/
|
|
@@ -514,20 +613,24 @@ type InferScalarInternal<T extends GraphQLScalarType> = T extends GraphQLScalarT
|
|
|
514
613
|
type InferScalarExternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<any, infer TExternal> ? TExternal : never;
|
|
515
614
|
type EnsureArray<T> = T extends Array<infer U> ? U[] : T[];
|
|
516
615
|
|
|
517
|
-
declare const
|
|
518
|
-
declare const
|
|
616
|
+
declare const createQuery: (output: GraphQLSilk<any, any>, resolveOrOptions?: (() => MayPromise<unknown>) | QueryMutationOptions<GraphQLSilkIO, any, any>) => QueryChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "query">;
|
|
617
|
+
declare const query: QueryFactoryWithChain<GraphQLSilkIO>;
|
|
618
|
+
declare const createMutation: (output: GraphQLSilk<any, any>, resolveOrOptions?: (() => MayPromise<unknown>) | QueryMutationOptions<GraphQLSilkIO, any, any>) => MutationChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "mutation">;
|
|
619
|
+
declare const mutation: MutationFactoryWithChain<GraphQLSilkIO>;
|
|
620
|
+
declare const createField: (output: GraphQLSilk<any, any>, resolveOrOptions?: FieldOptions<GraphQLSilkIO, any, any, any> | ((parent: unknown) => unknown) | undefined) => FieldChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "field">;
|
|
519
621
|
declare const field: FieldFactoryWithUtils<GraphQLSilkIO>;
|
|
520
622
|
declare const defaultSubscriptionResolve: (source: any) => any;
|
|
521
|
-
declare const
|
|
623
|
+
declare const createSubscription: (output: GraphQLSilk<any, any>, subscribeOrOptions?: (() => MayPromise<AsyncIterator<unknown>>) | SubscriptionOptions<GraphQLSilkIO, any, any, any>) => Subscription<any, any, any> | SubscriptionChainFactory<AbstractSchemaIO, never, undefined>;
|
|
624
|
+
declare const subscription: SubscriptionFactoryWithChain<GraphQLSilkIO>;
|
|
522
625
|
declare const ResolverOptionsMap: WeakMap<object, ResolverOptionsWithParent<GenericFieldOrOperation>>;
|
|
523
626
|
declare function baseResolver(operations: Record<string, FieldOrOperation<any, any, any>>, options: ResolverOptionsWithParent | undefined): Record<string, FieldOrOperation<any, any, any, FieldOrOperationType>>;
|
|
524
627
|
declare const resolver: ResolverFactory<GraphQLSilkIO>;
|
|
525
628
|
declare const loom: {
|
|
526
|
-
query:
|
|
629
|
+
query: QueryFactoryWithChain<GraphQLSilkIO>;
|
|
527
630
|
resolver: ResolverFactory<GraphQLSilkIO>;
|
|
528
631
|
field: FieldFactoryWithUtils<GraphQLSilkIO>;
|
|
529
|
-
subscription:
|
|
530
|
-
mutation:
|
|
632
|
+
subscription: SubscriptionFactoryWithChain<GraphQLSilkIO>;
|
|
633
|
+
mutation: MutationFactoryWithChain<GraphQLSilkIO>;
|
|
531
634
|
};
|
|
532
635
|
|
|
533
636
|
declare function createResolverFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk): ResolverFactory<TSchemaIO>;
|
|
@@ -725,4 +828,4 @@ interface GQLoomExtensionAttribute {
|
|
|
725
828
|
directives?: string[];
|
|
726
829
|
}
|
|
727
830
|
|
|
728
|
-
export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
|
|
831
|
+
export { type AbstractSchemaIO, type BatchLoadFn, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type MutationFactoryWithChain, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryFactoryWithChain, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionFactoryWithChain, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, capitalize, collectName, collectNames, compose, createField, createFieldFactory, createInputParser, createLoom, createMemoization, createMutation, createMutationFactory, createQuery, createQueryFactory, createResolverFactory, createSubscription, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import * as graphql from 'graphql';
|
|
1
2
|
import { GraphQLOutputType, GraphQLObjectTypeConfig, GraphQLFieldConfig, GraphQLResolveInfo, GraphQLScalarType, GraphQLObjectType, GraphQLUnionType, GraphQLInterfaceType, GraphQLInputObjectType, GraphQLSchemaConfig, GraphQLFieldMap, GraphQLNamedType, GraphQLSchema, GraphQLFieldConfigArgumentMap, GraphQLType, GraphQLInputType, GraphQLInterfaceTypeConfig } from 'graphql';
|
|
3
|
+
import * as graphql_jsutils_Maybe from 'graphql/jsutils/Maybe';
|
|
2
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -195,6 +197,70 @@ declare function getStandardValue<T>(result: StandardSchemaV1.Result<T>): T;
|
|
|
195
197
|
declare function getStandardValue<T>(result?: StandardSchemaV1.Result<T>): T | undefined;
|
|
196
198
|
declare function getStandardValue<T>(result: StandardSchemaV1.Result<T> | null): T | null;
|
|
197
199
|
|
|
200
|
+
interface IChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined> {
|
|
201
|
+
description(description: GraphQLFieldOptions["description"]): this;
|
|
202
|
+
deprecationReason(deprecationReason: GraphQLFieldOptions["deprecationReason"]): this;
|
|
203
|
+
extensions(extensions: GraphQLFieldOptions["extensions"]): this;
|
|
204
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): IChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
205
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): IChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
206
|
+
}
|
|
207
|
+
declare abstract class BaseChainFactory {
|
|
208
|
+
protected readonly options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
209
|
+
middlewares: Middleware[];
|
|
210
|
+
}> | undefined;
|
|
211
|
+
static methods(): {
|
|
212
|
+
description: (description: graphql_jsutils_Maybe.Maybe<string>) => BaseChainFactory;
|
|
213
|
+
deprecationReason: (deprecationReason: graphql_jsutils_Maybe.Maybe<string>) => BaseChainFactory;
|
|
214
|
+
extensions: (extensions: graphql_jsutils_Maybe.Maybe<Readonly<graphql.GraphQLFieldExtensions<any, any, any>>>) => BaseChainFactory;
|
|
215
|
+
};
|
|
216
|
+
constructor(options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
217
|
+
middlewares: Middleware[];
|
|
218
|
+
}> | undefined);
|
|
219
|
+
protected abstract clone(options?: Partial<FieldOrOperation<any, any, any, any> & {
|
|
220
|
+
middlewares: Middleware[];
|
|
221
|
+
}>): this;
|
|
222
|
+
description(description: GraphQLFieldOptions["description"]): this;
|
|
223
|
+
deprecationReason(deprecationReason: GraphQLFieldOptions["deprecationReason"]): this;
|
|
224
|
+
extensions(extensions: GraphQLFieldOptions["extensions"]): this;
|
|
225
|
+
use(...middlewares: Middleware[]): this;
|
|
226
|
+
}
|
|
227
|
+
declare class FieldChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
228
|
+
static methods(): FieldChainFactory<any, never, undefined>;
|
|
229
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
230
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">>[]): this;
|
|
231
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): FieldChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
232
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): FieldChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
233
|
+
resolve<TParent extends TSchemaIO[0]>(resolve: (parent: InferSchemaO<TParent, TSchemaIO>, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">;
|
|
234
|
+
}
|
|
235
|
+
declare class QueryChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
236
|
+
static methods(): QueryChainFactory<any, never, undefined>;
|
|
237
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
238
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query">>[]): this;
|
|
239
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): QueryChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
240
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): QueryChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
241
|
+
resolve(resolve: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): any;
|
|
242
|
+
}
|
|
243
|
+
declare class MutationChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
244
|
+
static methods(): MutationChainFactory<any, never, undefined>;
|
|
245
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
246
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "mutation">>[]): this;
|
|
247
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): MutationChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
248
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): MutationChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
249
|
+
resolve(resolve: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): any;
|
|
250
|
+
}
|
|
251
|
+
declare class SubscriptionChainFactory<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0] = never, TInput extends InputSchema<TSchemaIO[0]> = undefined> extends BaseChainFactory implements IChainFactory<TSchemaIO, TOutput, TInput> {
|
|
252
|
+
static methods(): SubscriptionChainFactory<any, never, undefined>;
|
|
253
|
+
protected clone(options?: Partial<FieldOrOperation<any, any, any, any>>): this;
|
|
254
|
+
use(...middlewares: Middleware<FieldOrOperation<any, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "subscription">>[]): this;
|
|
255
|
+
output<TOutputNew extends TSchemaIO[0]>(output: TOutputNew): SubscriptionChainFactory<TSchemaIO, TOutputNew, TInput>;
|
|
256
|
+
input<TInputNew extends InputSchema<TSchemaIO[0]>>(input: TInputNew): SubscriptionChainFactory<TSchemaIO, TOutput, TInputNew>;
|
|
257
|
+
subscribe<TValue = InferSchemaO<TOutput, TSchemaIO>>(subscribe: (input: InferInputO<TInput, TSchemaIO>) => MayPromise<AsyncIterator<TValue>>): ResolvableSubscription<TSchemaIO, TOutput, TInput, TValue>;
|
|
258
|
+
}
|
|
259
|
+
interface ResolvableSubscription<TSchemaIO extends AbstractSchemaIO, TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined, TValue = InferSchemaO<TOutput, TSchemaIO>> extends Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue> {
|
|
260
|
+
resolve(resolve: (value: TValue, input: InferInputO<TInput, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>): Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue>;
|
|
261
|
+
resolve(value: TValue, input: any): MayPromise<any>;
|
|
262
|
+
}
|
|
263
|
+
|
|
198
264
|
interface GraphQLSilk<TOutput = any, TInput = any> extends StandardSchemaV1<TInput, TOutput> {
|
|
199
265
|
/**
|
|
200
266
|
* GraphQL type for schema
|
|
@@ -254,12 +320,21 @@ interface QueryMutationOptions<TSchemaIO extends AbstractSchemaIO, TOutput exten
|
|
|
254
320
|
*/
|
|
255
321
|
interface QueryFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
256
322
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "query">;
|
|
323
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): QueryChainFactory<TSchemaIO, TOutput, undefined>;
|
|
324
|
+
}
|
|
325
|
+
interface QueryFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends QueryFactory<TSchemaIO>, QueryChainFactory<TSchemaIO, never, undefined> {
|
|
257
326
|
}
|
|
258
327
|
/**
|
|
259
328
|
* Function to create a GraphQL mutation.
|
|
260
329
|
*/
|
|
261
330
|
interface MutationFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
262
331
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: (() => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | QueryMutationOptions<TSchemaIO, TOutput, TInput>): FieldOrOperation<undefined, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "mutation">;
|
|
332
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): MutationChainFactory<TSchemaIO, TOutput, undefined>;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Function to create a GraphQL mutation.
|
|
336
|
+
*/
|
|
337
|
+
interface MutationFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends MutationFactory<TSchemaIO>, MutationChainFactory<TSchemaIO, never, undefined> {
|
|
263
338
|
}
|
|
264
339
|
/**
|
|
265
340
|
* Options for External Filed of existing GraphQL Object.
|
|
@@ -273,8 +348,9 @@ interface FieldOptions<TSchemaIO extends AbstractSchemaIO, TParent extends TSche
|
|
|
273
348
|
*/
|
|
274
349
|
interface FieldFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
275
350
|
<TParent extends TSchemaIO[0], TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined>(output: TOutput, resolveOrOptions: ((parent: InferSchemaO<TParent, TSchemaIO>) => MayPromise<InferSchemaO<TOutput, TSchemaIO>>) | FieldOptions<TSchemaIO, TParent, TOutput, TInput>): FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, "field">;
|
|
351
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): FieldChainFactory<TSchemaIO, TOutput, undefined>;
|
|
276
352
|
}
|
|
277
|
-
interface FieldFactoryWithUtils<TSchemaIO extends AbstractSchemaIO> extends FieldFactory<TSchemaIO> {
|
|
353
|
+
interface FieldFactoryWithUtils<TSchemaIO extends AbstractSchemaIO> extends FieldFactory<TSchemaIO>, FieldChainFactory<TSchemaIO, never, undefined> {
|
|
278
354
|
/** Set fields to be hidden in GraphQL Schema */
|
|
279
355
|
hidden: typeof FIELD_HIDDEN;
|
|
280
356
|
}
|
|
@@ -295,6 +371,9 @@ interface Subscription<TOutput extends GraphQLSilk, TInput extends InputSchema<G
|
|
|
295
371
|
*/
|
|
296
372
|
interface SubscriptionFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
297
373
|
<TOutput extends TSchemaIO[0], TInput extends InputSchema<TSchemaIO[0]> = undefined, TValue = InferSchemaO<TOutput, TSchemaIO>>(output: TOutput, subscribeOrOptions: (() => MayPromise<AsyncIterator<InferSchemaO<TOutput, TSchemaIO>>>) | SubscriptionOptions<TSchemaIO, TOutput, TInput, TValue>): Subscription<SchemaToSilk<TSchemaIO, TOutput>, InputSchemaToSilk<TSchemaIO, TInput>, TValue>;
|
|
374
|
+
<TOutput extends TSchemaIO[0]>(output: TOutput): SubscriptionChainFactory<TSchemaIO, TOutput, undefined>;
|
|
375
|
+
}
|
|
376
|
+
interface SubscriptionFactoryWithChain<TSchemaIO extends AbstractSchemaIO> extends SubscriptionFactory<TSchemaIO>, SubscriptionChainFactory<TSchemaIO, never, undefined> {
|
|
298
377
|
}
|
|
299
378
|
interface ResolverFactory<TSchemaIO extends AbstractSchemaIO> {
|
|
300
379
|
of<TParent extends TSchemaIO[0], TOperations extends Record<string, FieldOrOperation<SchemaToSilk<TSchemaIO, TParent>, any, any> | FieldOrOperation<undefined, any, any, OperationType> | typeof FIELD_HIDDEN>>(parent: TParent, operationOrFields: TOperations, options?: ResolverOptionsWithExtensions<OmitInUnion<ValueOf<TOperations>, typeof FIELD_HIDDEN>>): TOperations;
|
|
@@ -451,6 +530,7 @@ interface ReadOnlyObjMap<T> {
|
|
|
451
530
|
}
|
|
452
531
|
|
|
453
532
|
declare function pascalCase(str: string): string;
|
|
533
|
+
declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
454
534
|
|
|
455
535
|
declare function markErrorLocation<TError>(error: TError, ...locations: string[]): TError;
|
|
456
536
|
declare function tryIn<T>(func: () => T, ...locations: string[]): T;
|
|
@@ -466,6 +546,25 @@ declare function tryIn<T>(func: () => T, ...locations: string[]): T;
|
|
|
466
546
|
*/
|
|
467
547
|
declare function markLocation(message: string, ...locations: string[]): string;
|
|
468
548
|
|
|
549
|
+
type BatchLoadFn<TKey, TData> = (keys: TKey[]) => Promise<(TData | Error)[]>;
|
|
550
|
+
declare class EasyDataLoader<TKey, TData> {
|
|
551
|
+
protected readonly batchLoadFn: BatchLoadFn<TKey, TData>;
|
|
552
|
+
protected queue: TKey[];
|
|
553
|
+
protected cache: Map<TKey, Promise<TData>>;
|
|
554
|
+
protected resolvers: Map<TKey, [
|
|
555
|
+
resolve: (value: TData | PromiseLike<TData>) => void,
|
|
556
|
+
reject: (reason?: any) => void
|
|
557
|
+
]>;
|
|
558
|
+
constructor(batchLoadFn: BatchLoadFn<TKey, TData>);
|
|
559
|
+
load(key: TKey): Promise<TData>;
|
|
560
|
+
clear(): void;
|
|
561
|
+
clearByKey(key: TKey): void;
|
|
562
|
+
protected executeBatchLoad(): Promise<void>;
|
|
563
|
+
protected nextTickPromise?: Promise<void>;
|
|
564
|
+
protected nextTickBatchLoad(): Promise<void>;
|
|
565
|
+
static nextTick(): Promise<void>;
|
|
566
|
+
}
|
|
567
|
+
|
|
469
568
|
/**
|
|
470
569
|
* Create a Silk from Scalar.
|
|
471
570
|
*/
|
|
@@ -514,20 +613,24 @@ type InferScalarInternal<T extends GraphQLScalarType> = T extends GraphQLScalarT
|
|
|
514
613
|
type InferScalarExternal<T extends GraphQLScalarType> = T extends GraphQLScalarType<any, infer TExternal> ? TExternal : never;
|
|
515
614
|
type EnsureArray<T> = T extends Array<infer U> ? U[] : T[];
|
|
516
615
|
|
|
517
|
-
declare const
|
|
518
|
-
declare const
|
|
616
|
+
declare const createQuery: (output: GraphQLSilk<any, any>, resolveOrOptions?: (() => MayPromise<unknown>) | QueryMutationOptions<GraphQLSilkIO, any, any>) => QueryChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "query">;
|
|
617
|
+
declare const query: QueryFactoryWithChain<GraphQLSilkIO>;
|
|
618
|
+
declare const createMutation: (output: GraphQLSilk<any, any>, resolveOrOptions?: (() => MayPromise<unknown>) | QueryMutationOptions<GraphQLSilkIO, any, any>) => MutationChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "mutation">;
|
|
619
|
+
declare const mutation: MutationFactoryWithChain<GraphQLSilkIO>;
|
|
620
|
+
declare const createField: (output: GraphQLSilk<any, any>, resolveOrOptions?: FieldOptions<GraphQLSilkIO, any, any, any> | ((parent: unknown) => unknown) | undefined) => FieldChainFactory<AbstractSchemaIO, never, undefined> | FieldOrOperation<any, any, any, "field">;
|
|
519
621
|
declare const field: FieldFactoryWithUtils<GraphQLSilkIO>;
|
|
520
622
|
declare const defaultSubscriptionResolve: (source: any) => any;
|
|
521
|
-
declare const
|
|
623
|
+
declare const createSubscription: (output: GraphQLSilk<any, any>, subscribeOrOptions?: (() => MayPromise<AsyncIterator<unknown>>) | SubscriptionOptions<GraphQLSilkIO, any, any, any>) => Subscription<any, any, any> | SubscriptionChainFactory<AbstractSchemaIO, never, undefined>;
|
|
624
|
+
declare const subscription: SubscriptionFactoryWithChain<GraphQLSilkIO>;
|
|
522
625
|
declare const ResolverOptionsMap: WeakMap<object, ResolverOptionsWithParent<GenericFieldOrOperation>>;
|
|
523
626
|
declare function baseResolver(operations: Record<string, FieldOrOperation<any, any, any>>, options: ResolverOptionsWithParent | undefined): Record<string, FieldOrOperation<any, any, any, FieldOrOperationType>>;
|
|
524
627
|
declare const resolver: ResolverFactory<GraphQLSilkIO>;
|
|
525
628
|
declare const loom: {
|
|
526
|
-
query:
|
|
629
|
+
query: QueryFactoryWithChain<GraphQLSilkIO>;
|
|
527
630
|
resolver: ResolverFactory<GraphQLSilkIO>;
|
|
528
631
|
field: FieldFactoryWithUtils<GraphQLSilkIO>;
|
|
529
|
-
subscription:
|
|
530
|
-
mutation:
|
|
632
|
+
subscription: SubscriptionFactoryWithChain<GraphQLSilkIO>;
|
|
633
|
+
mutation: MutationFactoryWithChain<GraphQLSilkIO>;
|
|
531
634
|
};
|
|
532
635
|
|
|
533
636
|
declare function createResolverFactory<TSchemaIO extends AbstractSchemaIO>(toSilk: (schema: TSchemaIO[0]) => GraphQLSilk): ResolverFactory<TSchemaIO>;
|
|
@@ -725,4 +828,4 @@ interface GQLoomExtensionAttribute {
|
|
|
725
828
|
directives?: string[];
|
|
726
829
|
}
|
|
727
830
|
|
|
728
|
-
export { type AbstractSchemaIO, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, collectName, collectNames, compose, createFieldFactory, createInputParser, createLoom, createMemoization, createMutationFactory, createQueryFactory, createResolverFactory, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
|
|
831
|
+
export { type AbstractSchemaIO, type BatchLoadFn, type CallableContextMemoization, type CallableInputParser, type CallableMiddlewareOptions, ContextMemoization, type CoreSchemaWeaverConfig, type CoreSchemaWeaverConfigOptions, type DirectiveItem, type DirectiveRecord, EasyDataLoader, type FieldConvertOptions, type FieldFactory, type FieldFactoryWithUtils, type FieldOptions, type FieldOrOperation, type FieldOrOperationType, type GQLoomExtensionAttribute, type GQLoomExtensions, type GenericFieldOrOperation, type GlobalWeaverContext, type GraphQLFieldOptions, GraphQLSchemaLoom, type GraphQLSilk, type GraphQLSilkIO, type InferFieldInput, type InferFieldOutput, type InferFieldParent, type InferInputI, type InferInputO, type InferPropertyType, type InferSchemaI, type InferSchemaO, type InputSchema, type InputSchemaToSilk, type IsAny, type ListSilk, LoomObjectType, type MayPromise, type Middleware, type MiddlewareOptions, type MutationFactory, type MutationFactoryWithChain, type NonNullSilk, type NullableSilk, OPERATION_OBJECT_NAMES, type ObjectOrNever, type OnlyMemoizationPayload, type OperationType, type QueryFactory, type QueryFactoryWithChain, type QueryMutationOptions, type ResolverFactory, type ResolverOptions, ResolverOptionsMap, type ResolverOptionsWithExtensions, type ResolverOptionsWithParent, type ResolverPayload, type ResolvingOptions, symbols as SYMBOLS, type SchemaToSilk, type SchemaWeaver, type SilkFieldOrOperation, type SilkResolver, StandardSchemaV1, type Subscription, type SubscriptionFactory, type SubscriptionFactoryWithChain, type SubscriptionOptions, type ValueOf, type WeaverConfig, type WeaverContext, type WrapPropertyType, applyMiddlewares, baseResolver, capitalize, collectName, collectNames, compose, createField, createFieldFactory, createInputParser, createLoom, createMemoization, createMutation, createMutationFactory, createQuery, createQueryFactory, createResolverFactory, createSubscription, createSubscriptionFactory, deepMerge, defaultSubscriptionResolve, ensureInputObjectType, ensureInputType, ensureInterfaceType, field, getCacheType, getFieldOptions, getGraphQLType, getOperationOptions, getStandardValue, getSubscriptionOptions, initWeaverContext, inputToArgs, isOnlyMemoryPayload, isSchemaVendorWeaver, isSilk, listSilk, loom, mapValue, markErrorLocation, markLocation, mutation, nonNullSilk, notNullish, nullableSilk, onlyMemoization, parseInputValue, parseSilk, pascalCase, provideWeaverContext, query, resolver, resolverPayloadStorage, silk, subscription, toObjMap, tryIn, useContext, useMemoizationMap, useResolverPayload, weave, weaverContext };
|
package/dist/index.js
CHANGED
|
@@ -192,7 +192,7 @@ function listSilk(origin) {
|
|
|
192
192
|
[GET_GRAPHQL_TYPE]: () => {
|
|
193
193
|
let originType = getGraphQLType(origin);
|
|
194
194
|
if (originType instanceof GraphQLNonNull && originType.ofType instanceof GraphQLList) {
|
|
195
|
-
originType = originType.ofType;
|
|
195
|
+
originType = originType.ofType.ofType;
|
|
196
196
|
}
|
|
197
197
|
if (originType instanceof GraphQLList) {
|
|
198
198
|
originType = originType.ofType;
|
|
@@ -432,6 +432,9 @@ function pascalCase(str) {
|
|
|
432
432
|
(word, index) => index === 0 ? word.charAt(0).toUpperCase() + word.slice(1) : word.charAt(0).toUpperCase() + word.slice(1)
|
|
433
433
|
).join("");
|
|
434
434
|
}
|
|
435
|
+
function capitalize(str) {
|
|
436
|
+
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
437
|
+
}
|
|
435
438
|
|
|
436
439
|
// src/utils/error.ts
|
|
437
440
|
function markErrorLocation(error, ...locations) {
|
|
@@ -461,6 +464,72 @@ function markLocation(message, ...locations) {
|
|
|
461
464
|
return `[${combinedLocation}] ${newMessage}`;
|
|
462
465
|
}
|
|
463
466
|
|
|
467
|
+
// src/utils/loader.ts
|
|
468
|
+
var EasyDataLoader = class _EasyDataLoader {
|
|
469
|
+
constructor(batchLoadFn) {
|
|
470
|
+
this.batchLoadFn = batchLoadFn;
|
|
471
|
+
this.queue = [];
|
|
472
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
473
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
474
|
+
}
|
|
475
|
+
queue;
|
|
476
|
+
cache;
|
|
477
|
+
resolvers;
|
|
478
|
+
load(key) {
|
|
479
|
+
const existing = this.cache.get(key);
|
|
480
|
+
if (existing) return existing;
|
|
481
|
+
const promise = new Promise((resolve, reject) => {
|
|
482
|
+
this.queue.push(key);
|
|
483
|
+
this.resolvers.set(key, [resolve, reject]);
|
|
484
|
+
this.nextTickBatchLoad();
|
|
485
|
+
});
|
|
486
|
+
this.cache.set(key, promise);
|
|
487
|
+
return promise;
|
|
488
|
+
}
|
|
489
|
+
clear() {
|
|
490
|
+
this.queue = [];
|
|
491
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
492
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
493
|
+
}
|
|
494
|
+
clearByKey(key) {
|
|
495
|
+
this.queue = this.queue.filter((k) => k !== key);
|
|
496
|
+
this.cache.delete(key);
|
|
497
|
+
this.resolvers.delete(key);
|
|
498
|
+
}
|
|
499
|
+
async executeBatchLoad() {
|
|
500
|
+
if (this.queue.length === 0) return;
|
|
501
|
+
const [keys, resolvers] = [this.queue, this.resolvers];
|
|
502
|
+
this.queue = [];
|
|
503
|
+
this.resolvers = /* @__PURE__ */ new Map();
|
|
504
|
+
try {
|
|
505
|
+
const list = await this.batchLoadFn(keys);
|
|
506
|
+
for (let i = 0; i < list.length; i++) {
|
|
507
|
+
const data = list[i];
|
|
508
|
+
const resolve = resolvers.get(keys[i])?.[0];
|
|
509
|
+
const reject = resolvers.get(keys[i])?.[1];
|
|
510
|
+
if (data instanceof Error) {
|
|
511
|
+
reject?.(data);
|
|
512
|
+
} else {
|
|
513
|
+
resolve?.(data);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
} catch (error) {
|
|
517
|
+
for (const key of keys) {
|
|
518
|
+
const reject = resolvers.get(key)?.[1];
|
|
519
|
+
reject?.(error);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
nextTickPromise;
|
|
524
|
+
nextTickBatchLoad() {
|
|
525
|
+
this.nextTickPromise ??= _EasyDataLoader.nextTick().then(() => this.executeBatchLoad()).finally(() => this.nextTickPromise = void 0);
|
|
526
|
+
return this.nextTickPromise;
|
|
527
|
+
}
|
|
528
|
+
static nextTick() {
|
|
529
|
+
return new Promise((resolve) => setTimeout(resolve));
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
|
|
464
533
|
// src/resolver/input.ts
|
|
465
534
|
import { GraphQLError } from "graphql";
|
|
466
535
|
function createInputParser(schema, value) {
|
|
@@ -514,8 +583,168 @@ function getStandardValue(result) {
|
|
|
514
583
|
else throw new GraphQLError("Invalid input");
|
|
515
584
|
}
|
|
516
585
|
|
|
586
|
+
// src/resolver/resolver-chain-factory.ts
|
|
587
|
+
var BaseChainFactory = class _BaseChainFactory {
|
|
588
|
+
constructor(options) {
|
|
589
|
+
this.options = options;
|
|
590
|
+
}
|
|
591
|
+
static methods() {
|
|
592
|
+
return {
|
|
593
|
+
description: _BaseChainFactory.prototype.description,
|
|
594
|
+
deprecationReason: _BaseChainFactory.prototype.deprecationReason,
|
|
595
|
+
extensions: _BaseChainFactory.prototype.extensions
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
description(description) {
|
|
599
|
+
return this.clone({ description });
|
|
600
|
+
}
|
|
601
|
+
deprecationReason(deprecationReason) {
|
|
602
|
+
return this.clone({ deprecationReason });
|
|
603
|
+
}
|
|
604
|
+
extensions(extensions) {
|
|
605
|
+
return this.clone({ extensions });
|
|
606
|
+
}
|
|
607
|
+
use(...middlewares) {
|
|
608
|
+
return this.clone({
|
|
609
|
+
middlewares: [...this.options?.middlewares ?? [], ...middlewares]
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
var FieldChainFactory = class _FieldChainFactory extends BaseChainFactory {
|
|
614
|
+
static methods() {
|
|
615
|
+
return {
|
|
616
|
+
...BaseChainFactory.methods(),
|
|
617
|
+
output: _FieldChainFactory.prototype.output,
|
|
618
|
+
input: _FieldChainFactory.prototype.input,
|
|
619
|
+
resolve: _FieldChainFactory.prototype.resolve,
|
|
620
|
+
clone: _FieldChainFactory.prototype.clone
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
clone(options) {
|
|
624
|
+
return new _FieldChainFactory({ ...this.options, ...options });
|
|
625
|
+
}
|
|
626
|
+
use(...middlewares) {
|
|
627
|
+
return super.use(...middlewares);
|
|
628
|
+
}
|
|
629
|
+
output(output) {
|
|
630
|
+
return new _FieldChainFactory({ ...this.options, output });
|
|
631
|
+
}
|
|
632
|
+
input(input) {
|
|
633
|
+
return new _FieldChainFactory({ ...this.options, input });
|
|
634
|
+
}
|
|
635
|
+
resolve(resolve) {
|
|
636
|
+
return createField(this.options?.output, {
|
|
637
|
+
...this.options,
|
|
638
|
+
resolve
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
var QueryChainFactory = class _QueryChainFactory extends BaseChainFactory {
|
|
643
|
+
static methods() {
|
|
644
|
+
return {
|
|
645
|
+
...BaseChainFactory.methods(),
|
|
646
|
+
output: _QueryChainFactory.prototype.output,
|
|
647
|
+
input: _QueryChainFactory.prototype.input,
|
|
648
|
+
resolve: _QueryChainFactory.prototype.resolve,
|
|
649
|
+
clone: _QueryChainFactory.prototype.clone
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
clone(options) {
|
|
653
|
+
return new _QueryChainFactory({ ...this.options, ...options });
|
|
654
|
+
}
|
|
655
|
+
use(...middlewares) {
|
|
656
|
+
return super.use(...middlewares);
|
|
657
|
+
}
|
|
658
|
+
output(output) {
|
|
659
|
+
return new _QueryChainFactory({ ...this.options, output });
|
|
660
|
+
}
|
|
661
|
+
input(input) {
|
|
662
|
+
return new _QueryChainFactory({ ...this.options, input });
|
|
663
|
+
}
|
|
664
|
+
resolve(resolve) {
|
|
665
|
+
return createQuery(this.options?.output, {
|
|
666
|
+
...this.options,
|
|
667
|
+
resolve
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
var MutationChainFactory = class _MutationChainFactory extends BaseChainFactory {
|
|
672
|
+
static methods() {
|
|
673
|
+
return {
|
|
674
|
+
...BaseChainFactory.methods(),
|
|
675
|
+
output: _MutationChainFactory.prototype.output,
|
|
676
|
+
input: _MutationChainFactory.prototype.input,
|
|
677
|
+
resolve: _MutationChainFactory.prototype.resolve,
|
|
678
|
+
clone: _MutationChainFactory.prototype.clone
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
clone(options) {
|
|
682
|
+
return new _MutationChainFactory({ ...this.options, ...options });
|
|
683
|
+
}
|
|
684
|
+
use(...middlewares) {
|
|
685
|
+
return super.use(...middlewares);
|
|
686
|
+
}
|
|
687
|
+
output(output) {
|
|
688
|
+
return new _MutationChainFactory({ ...this.options, output });
|
|
689
|
+
}
|
|
690
|
+
input(input) {
|
|
691
|
+
return new _MutationChainFactory({ ...this.options, input });
|
|
692
|
+
}
|
|
693
|
+
resolve(resolve) {
|
|
694
|
+
return createMutation(this.options?.output, {
|
|
695
|
+
...this.options,
|
|
696
|
+
resolve
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
var SubscriptionChainFactory = class _SubscriptionChainFactory extends BaseChainFactory {
|
|
701
|
+
static methods() {
|
|
702
|
+
return {
|
|
703
|
+
...BaseChainFactory.methods(),
|
|
704
|
+
output: _SubscriptionChainFactory.prototype.output,
|
|
705
|
+
input: _SubscriptionChainFactory.prototype.input,
|
|
706
|
+
subscribe: _SubscriptionChainFactory.prototype.subscribe,
|
|
707
|
+
clone: _SubscriptionChainFactory.prototype.clone
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
clone(options) {
|
|
711
|
+
return new _SubscriptionChainFactory({ ...this.options, ...options });
|
|
712
|
+
}
|
|
713
|
+
use(...middlewares) {
|
|
714
|
+
return super.use(...middlewares);
|
|
715
|
+
}
|
|
716
|
+
output(output) {
|
|
717
|
+
return new _SubscriptionChainFactory({ ...this.options, output });
|
|
718
|
+
}
|
|
719
|
+
input(input) {
|
|
720
|
+
return new _SubscriptionChainFactory({ ...this.options, input });
|
|
721
|
+
}
|
|
722
|
+
subscribe(subscribe) {
|
|
723
|
+
const options = this.options;
|
|
724
|
+
const subscription2 = createSubscription(options?.output, {
|
|
725
|
+
...options,
|
|
726
|
+
subscribe
|
|
727
|
+
});
|
|
728
|
+
const subscriptionResolve = subscription2.resolve;
|
|
729
|
+
const resolve = (...args) => {
|
|
730
|
+
if (args.length === 1 && typeof args[0] === "function") {
|
|
731
|
+
return createSubscription(options?.output, {
|
|
732
|
+
...options,
|
|
733
|
+
resolve: args[0],
|
|
734
|
+
subscribe
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
return subscriptionResolve(...args);
|
|
738
|
+
};
|
|
739
|
+
return Object.assign(subscription2, { resolve });
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
|
|
517
743
|
// src/resolver/resolver.ts
|
|
518
|
-
var
|
|
744
|
+
var createQuery = (output, resolveOrOptions) => {
|
|
745
|
+
if (resolveOrOptions == null) {
|
|
746
|
+
return new QueryChainFactory({ output });
|
|
747
|
+
}
|
|
519
748
|
const options = getOperationOptions(resolveOrOptions);
|
|
520
749
|
const type = "query";
|
|
521
750
|
return {
|
|
@@ -533,7 +762,14 @@ var query = (output, resolveOrOptions) => {
|
|
|
533
762
|
type
|
|
534
763
|
};
|
|
535
764
|
};
|
|
536
|
-
var
|
|
765
|
+
var query = Object.assign(
|
|
766
|
+
createQuery,
|
|
767
|
+
QueryChainFactory.methods()
|
|
768
|
+
);
|
|
769
|
+
var createMutation = (output, resolveOrOptions) => {
|
|
770
|
+
if (resolveOrOptions == null) {
|
|
771
|
+
return new MutationChainFactory({ output });
|
|
772
|
+
}
|
|
537
773
|
const options = getOperationOptions(resolveOrOptions);
|
|
538
774
|
const type = "mutation";
|
|
539
775
|
return {
|
|
@@ -551,7 +787,14 @@ var mutation = (output, resolveOrOptions) => {
|
|
|
551
787
|
type
|
|
552
788
|
};
|
|
553
789
|
};
|
|
554
|
-
var
|
|
790
|
+
var mutation = Object.assign(
|
|
791
|
+
createMutation,
|
|
792
|
+
MutationChainFactory.methods()
|
|
793
|
+
);
|
|
794
|
+
var createField = (output, resolveOrOptions) => {
|
|
795
|
+
if (resolveOrOptions == null) {
|
|
796
|
+
return new FieldChainFactory({ output });
|
|
797
|
+
}
|
|
555
798
|
const options = getOperationOptions(resolveOrOptions);
|
|
556
799
|
const type = "field";
|
|
557
800
|
return {
|
|
@@ -570,13 +813,15 @@ var baseSilkField = (output, resolveOrOptions) => {
|
|
|
570
813
|
};
|
|
571
814
|
};
|
|
572
815
|
var field = Object.assign(
|
|
573
|
-
|
|
574
|
-
{
|
|
575
|
-
|
|
576
|
-
}
|
|
816
|
+
createField,
|
|
817
|
+
{ hidden: FIELD_HIDDEN },
|
|
818
|
+
FieldChainFactory.methods()
|
|
577
819
|
);
|
|
578
820
|
var defaultSubscriptionResolve = (source) => source;
|
|
579
|
-
var
|
|
821
|
+
var createSubscription = (output, subscribeOrOptions) => {
|
|
822
|
+
if (subscribeOrOptions == null) {
|
|
823
|
+
return new SubscriptionChainFactory({ output });
|
|
824
|
+
}
|
|
580
825
|
const options = getSubscriptionOptions(subscribeOrOptions);
|
|
581
826
|
const type = "subscription";
|
|
582
827
|
return {
|
|
@@ -598,6 +843,10 @@ var subscription = (output, subscribeOrOptions) => {
|
|
|
598
843
|
type
|
|
599
844
|
};
|
|
600
845
|
};
|
|
846
|
+
var subscription = Object.assign(
|
|
847
|
+
createSubscription,
|
|
848
|
+
SubscriptionChainFactory.methods()
|
|
849
|
+
);
|
|
601
850
|
var ResolverOptionsMap = /* @__PURE__ */ new WeakMap();
|
|
602
851
|
function baseResolver(operations, options) {
|
|
603
852
|
const record = {};
|
|
@@ -678,6 +927,9 @@ function createResolverFactory(toSilk) {
|
|
|
678
927
|
}
|
|
679
928
|
function createFieldFactory(toSilk, isSchema) {
|
|
680
929
|
const baseFieldFunc = (output, resolveOrOptions) => {
|
|
930
|
+
if (resolveOrOptions == null) {
|
|
931
|
+
return new FieldChainFactory({ output: toSilk(output) });
|
|
932
|
+
}
|
|
681
933
|
const options = getOperationOptions(
|
|
682
934
|
resolveOrOptions
|
|
683
935
|
);
|
|
@@ -686,12 +938,17 @@ function createFieldFactory(toSilk, isSchema) {
|
|
|
686
938
|
input: toSilkInput(options.input, toSilk, isSchema)
|
|
687
939
|
});
|
|
688
940
|
};
|
|
689
|
-
return Object.assign(
|
|
690
|
-
|
|
691
|
-
|
|
941
|
+
return Object.assign(
|
|
942
|
+
baseFieldFunc,
|
|
943
|
+
{ hidden: FIELD_HIDDEN },
|
|
944
|
+
FieldChainFactory.methods()
|
|
945
|
+
);
|
|
692
946
|
}
|
|
693
947
|
function createQueryFactory(toSilk, isSchema) {
|
|
694
948
|
return (output, resolveOrOptions) => {
|
|
949
|
+
if (resolveOrOptions == null) {
|
|
950
|
+
return new QueryChainFactory({ output: toSilk(output) });
|
|
951
|
+
}
|
|
695
952
|
const options = getOperationOptions(resolveOrOptions);
|
|
696
953
|
return query(toSilk(output), {
|
|
697
954
|
...options,
|
|
@@ -701,6 +958,9 @@ function createQueryFactory(toSilk, isSchema) {
|
|
|
701
958
|
}
|
|
702
959
|
function createMutationFactory(toSilk, isSchema) {
|
|
703
960
|
return (output, resolveOrOptions) => {
|
|
961
|
+
if (resolveOrOptions == null) {
|
|
962
|
+
return new MutationChainFactory({ output: toSilk(output) });
|
|
963
|
+
}
|
|
704
964
|
const options = getOperationOptions(resolveOrOptions);
|
|
705
965
|
return mutation(toSilk(output), {
|
|
706
966
|
...options,
|
|
@@ -710,6 +970,9 @@ function createMutationFactory(toSilk, isSchema) {
|
|
|
710
970
|
}
|
|
711
971
|
function createSubscriptionFactory(toSilk, isSchema) {
|
|
712
972
|
return (output, resolveOrOptions) => {
|
|
973
|
+
if (resolveOrOptions == null) {
|
|
974
|
+
return new SubscriptionChainFactory({ output: toSilk(output) });
|
|
975
|
+
}
|
|
713
976
|
const options = getSubscriptionOptions(resolveOrOptions);
|
|
714
977
|
return subscription(toSilk(output), {
|
|
715
978
|
...options,
|
|
@@ -1290,6 +1553,7 @@ function ensureInterfaceType(gqlType, interfaceConfig) {
|
|
|
1290
1553
|
}
|
|
1291
1554
|
export {
|
|
1292
1555
|
ContextMemoization,
|
|
1556
|
+
EasyDataLoader,
|
|
1293
1557
|
GraphQLSchemaLoom,
|
|
1294
1558
|
LoomObjectType,
|
|
1295
1559
|
OPERATION_OBJECT_NAMES,
|
|
@@ -1297,16 +1561,21 @@ export {
|
|
|
1297
1561
|
symbols_exports as SYMBOLS,
|
|
1298
1562
|
applyMiddlewares,
|
|
1299
1563
|
baseResolver,
|
|
1564
|
+
capitalize,
|
|
1300
1565
|
collectName,
|
|
1301
1566
|
collectNames,
|
|
1302
1567
|
compose,
|
|
1568
|
+
createField,
|
|
1303
1569
|
createFieldFactory,
|
|
1304
1570
|
createInputParser,
|
|
1305
1571
|
createLoom,
|
|
1306
1572
|
createMemoization,
|
|
1573
|
+
createMutation,
|
|
1307
1574
|
createMutationFactory,
|
|
1575
|
+
createQuery,
|
|
1308
1576
|
createQueryFactory,
|
|
1309
1577
|
createResolverFactory,
|
|
1578
|
+
createSubscription,
|
|
1310
1579
|
createSubscriptionFactory,
|
|
1311
1580
|
deepMerge,
|
|
1312
1581
|
defaultSubscriptionResolve,
|