@graphql-tools/delegate 10.0.1 → 10.0.2-alpha-20230802173210-ebef6bb6
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/cjs/delegateToSchema.js +10 -8
- package/cjs/mergeFields.js +33 -11
- package/cjs/resolveExternalValue.js +1 -1
- package/esm/delegateToSchema.js +11 -9
- package/esm/mergeFields.js +34 -12
- package/esm/resolveExternalValue.js +1 -1
- package/package.json +2 -3
- package/typings/mergeFields.d.cts +2 -2
- package/typings/mergeFields.d.ts +2 -2
package/cjs/delegateToSchema.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDefaultExecutor = exports.delegateRequest = exports.delegateToSchema = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const value_or_promise_1 = require("value-or-promise");
|
|
6
5
|
const batch_execute_1 = require("@graphql-tools/batch-execute");
|
|
7
6
|
const executor_1 = require("@graphql-tools/executor");
|
|
8
7
|
const utils_1 = require("@graphql-tools/utils");
|
|
@@ -51,16 +50,19 @@ function delegateRequest(options) {
|
|
|
51
50
|
validateRequest(delegationContext, processedRequest.document);
|
|
52
51
|
}
|
|
53
52
|
const executor = getExecutor(delegationContext);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if ((0, utils_1.isAsyncIterable)(
|
|
57
|
-
const iterator =
|
|
53
|
+
const result$ = executor(processedRequest);
|
|
54
|
+
function handleExecutorResult(executorResult) {
|
|
55
|
+
if ((0, utils_1.isAsyncIterable)(executorResult)) {
|
|
56
|
+
const iterator = executorResult[Symbol.asyncIterator]();
|
|
58
57
|
// "subscribe" to the subscription result and map the result through the transforms
|
|
59
58
|
return (0, utils_1.mapAsyncIterator)(iterator, result => transformer.transformResult(result));
|
|
60
59
|
}
|
|
61
|
-
return transformer.transformResult(
|
|
62
|
-
}
|
|
63
|
-
|
|
60
|
+
return transformer.transformResult(executorResult);
|
|
61
|
+
}
|
|
62
|
+
if ((0, utils_1.isPromise)(result$)) {
|
|
63
|
+
return result$.then(handleExecutorResult);
|
|
64
|
+
}
|
|
65
|
+
return handleExecutorResult(result$);
|
|
64
66
|
}
|
|
65
67
|
exports.delegateRequest = delegateRequest;
|
|
66
68
|
function getDelegationContext({ request, schema, fieldName, returnType, args, info, transforms = [], transformedSchema, skipTypeMerging = false, }) {
|
package/cjs/mergeFields.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeFields = exports.getActualFieldNodes = exports.getUnpathedErrors = exports.getSubschema = exports.annotateExternalObject = exports.isExternalObject = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
|
-
const value_or_promise_1 = require("value-or-promise");
|
|
6
5
|
const utils_1 = require("@graphql-tools/utils");
|
|
7
6
|
const symbols_js_1 = require("./symbols.js");
|
|
8
7
|
function isExternalObject(data) {
|
|
@@ -28,9 +27,6 @@ function getUnpathedErrors(object) {
|
|
|
28
27
|
exports.getUnpathedErrors = getUnpathedErrors;
|
|
29
28
|
const EMPTY_ARRAY = [];
|
|
30
29
|
const EMPTY_OBJECT = Object.create(null);
|
|
31
|
-
function asyncForEach(array, fn) {
|
|
32
|
-
return array.reduce((prev, curr) => prev.then(() => fn(curr)), new value_or_promise_1.ValueOrPromise(() => { }));
|
|
33
|
-
}
|
|
34
30
|
exports.getActualFieldNodes = (0, utils_1.memoize1)(function (fieldNode) {
|
|
35
31
|
return [fieldNode];
|
|
36
32
|
});
|
|
@@ -44,7 +40,19 @@ function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
|
44
40
|
? (0, exports.getActualFieldNodes)(info.fieldNodes[0])
|
|
45
41
|
: info.fieldNodes
|
|
46
42
|
: EMPTY_ARRAY);
|
|
47
|
-
|
|
43
|
+
const res$ = delegationMaps.reduce((prev, delegationMap) => {
|
|
44
|
+
function executeFn() {
|
|
45
|
+
return executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info);
|
|
46
|
+
}
|
|
47
|
+
if ((0, utils_1.isPromise)(prev)) {
|
|
48
|
+
return prev.then(executeFn);
|
|
49
|
+
}
|
|
50
|
+
return executeFn();
|
|
51
|
+
}, undefined);
|
|
52
|
+
if ((0, utils_1.isPromise)(res$)) {
|
|
53
|
+
return res$.then(() => object);
|
|
54
|
+
}
|
|
55
|
+
return object;
|
|
48
56
|
}
|
|
49
57
|
exports.mergeFields = mergeFields;
|
|
50
58
|
function executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info) {
|
|
@@ -87,14 +95,28 @@ function executeDelegationStage(mergedTypeInfo, delegationMap, object, context,
|
|
|
87
95
|
combinedFieldSubschemaMap[responseKey] = fieldSubschemaMap?.[responseKey] ?? objectSubschema;
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
|
-
return
|
|
98
|
+
return [...delegationMap.entries()].reduce((prev, [subschema, selectionSet]) => {
|
|
91
99
|
const schema = subschema.transformedSchema || info.schema;
|
|
92
100
|
const type = schema.getType(object.__typename);
|
|
93
101
|
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
function resolve() {
|
|
103
|
+
let source$;
|
|
104
|
+
if (resolver) {
|
|
105
|
+
try {
|
|
106
|
+
source$ = resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
return finallyFn(error, subschema, selectionSet);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if ((0, utils_1.isPromise)(source$)) {
|
|
113
|
+
return source$.then(source => finallyFn(source, subschema, selectionSet)).catch(error => finallyFn(error, subschema, selectionSet));
|
|
114
|
+
}
|
|
115
|
+
return finallyFn(source$, subschema, selectionSet);
|
|
116
|
+
}
|
|
117
|
+
if ((0, utils_1.isPromise)(prev)) {
|
|
118
|
+
return prev.then(resolve);
|
|
96
119
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
.catch(error => finallyFn(error, subschema, selectionSet)))).then(() => { });
|
|
120
|
+
return resolve();
|
|
121
|
+
}, undefined);
|
|
100
122
|
}
|
|
@@ -50,7 +50,7 @@ function resolveExternalObject(type, object, unpathedErrors, subschema, context,
|
|
|
50
50
|
if (!targetSubschemas || !targetSubschemas.length) {
|
|
51
51
|
return object;
|
|
52
52
|
}
|
|
53
|
-
return (0, mergeFields_js_1.mergeFields)(mergedTypeInfo, object, subschema, context, info)
|
|
53
|
+
return (0, mergeFields_js_1.mergeFields)(mergedTypeInfo, object, subschema, context, info);
|
|
54
54
|
}
|
|
55
55
|
function resolveExternalList(type, list, unpathedErrors, subschema, context, info, skipTypeMerging) {
|
|
56
56
|
return list.map(listMember => resolveExternalValue(listMember, unpathedErrors, subschema, context, info, type.ofType, skipTypeMerging));
|
package/esm/delegateToSchema.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { validate, } from 'graphql';
|
|
2
|
-
import { ValueOrPromise } from 'value-or-promise';
|
|
3
2
|
import { getBatchingExecutor } from '@graphql-tools/batch-execute';
|
|
4
3
|
import { normalizedExecutor } from '@graphql-tools/executor';
|
|
5
|
-
import { getDefinedRootType, getOperationASTFromRequest, isAsyncIterable, mapAsyncIterator, memoize1, } from '@graphql-tools/utils';
|
|
4
|
+
import { getDefinedRootType, getOperationASTFromRequest, isAsyncIterable, isPromise, mapAsyncIterator, memoize1, } from '@graphql-tools/utils';
|
|
6
5
|
import { applySchemaTransforms } from './applySchemaTransforms.js';
|
|
7
6
|
import { createRequest, getDelegatingOperation } from './createRequest.js';
|
|
8
7
|
import { Subschema } from './Subschema.js';
|
|
@@ -47,16 +46,19 @@ export function delegateRequest(options) {
|
|
|
47
46
|
validateRequest(delegationContext, processedRequest.document);
|
|
48
47
|
}
|
|
49
48
|
const executor = getExecutor(delegationContext);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (isAsyncIterable(
|
|
53
|
-
const iterator =
|
|
49
|
+
const result$ = executor(processedRequest);
|
|
50
|
+
function handleExecutorResult(executorResult) {
|
|
51
|
+
if (isAsyncIterable(executorResult)) {
|
|
52
|
+
const iterator = executorResult[Symbol.asyncIterator]();
|
|
54
53
|
// "subscribe" to the subscription result and map the result through the transforms
|
|
55
54
|
return mapAsyncIterator(iterator, result => transformer.transformResult(result));
|
|
56
55
|
}
|
|
57
|
-
return transformer.transformResult(
|
|
58
|
-
}
|
|
59
|
-
|
|
56
|
+
return transformer.transformResult(executorResult);
|
|
57
|
+
}
|
|
58
|
+
if (isPromise(result$)) {
|
|
59
|
+
return result$.then(handleExecutorResult);
|
|
60
|
+
}
|
|
61
|
+
return handleExecutorResult(result$);
|
|
60
62
|
}
|
|
61
63
|
function getDelegationContext({ request, schema, fieldName, returnType, args, info, transforms = [], transformedSchema, skipTypeMerging = false, }) {
|
|
62
64
|
const operationDefinition = getOperationASTFromRequest(request);
|
package/esm/mergeFields.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GraphQLError, locatedError, responsePathAsArray, } from 'graphql';
|
|
2
|
-
import {
|
|
3
|
-
import { collectFields, memoize1, relocatedError } from '@graphql-tools/utils';
|
|
2
|
+
import { collectFields, isPromise, memoize1, relocatedError, } from '@graphql-tools/utils';
|
|
4
3
|
import { FIELD_SUBSCHEMA_MAP_SYMBOL, OBJECT_SUBSCHEMA_SYMBOL, UNPATHED_ERRORS_SYMBOL, } from './symbols.js';
|
|
5
4
|
export function isExternalObject(data) {
|
|
6
5
|
return data[UNPATHED_ERRORS_SYMBOL] !== undefined;
|
|
@@ -21,9 +20,6 @@ export function getUnpathedErrors(object) {
|
|
|
21
20
|
}
|
|
22
21
|
const EMPTY_ARRAY = [];
|
|
23
22
|
const EMPTY_OBJECT = Object.create(null);
|
|
24
|
-
function asyncForEach(array, fn) {
|
|
25
|
-
return array.reduce((prev, curr) => prev.then(() => fn(curr)), new ValueOrPromise(() => { }));
|
|
26
|
-
}
|
|
27
23
|
export const getActualFieldNodes = memoize1(function (fieldNode) {
|
|
28
24
|
return [fieldNode];
|
|
29
25
|
});
|
|
@@ -37,7 +33,19 @@ export function mergeFields(mergedTypeInfo, object, sourceSubschema, context, in
|
|
|
37
33
|
? getActualFieldNodes(info.fieldNodes[0])
|
|
38
34
|
: info.fieldNodes
|
|
39
35
|
: EMPTY_ARRAY);
|
|
40
|
-
|
|
36
|
+
const res$ = delegationMaps.reduce((prev, delegationMap) => {
|
|
37
|
+
function executeFn() {
|
|
38
|
+
return executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info);
|
|
39
|
+
}
|
|
40
|
+
if (isPromise(prev)) {
|
|
41
|
+
return prev.then(executeFn);
|
|
42
|
+
}
|
|
43
|
+
return executeFn();
|
|
44
|
+
}, undefined);
|
|
45
|
+
if (isPromise(res$)) {
|
|
46
|
+
return res$.then(() => object);
|
|
47
|
+
}
|
|
48
|
+
return object;
|
|
41
49
|
}
|
|
42
50
|
function executeDelegationStage(mergedTypeInfo, delegationMap, object, context, info) {
|
|
43
51
|
const combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
@@ -79,14 +87,28 @@ function executeDelegationStage(mergedTypeInfo, delegationMap, object, context,
|
|
|
79
87
|
combinedFieldSubschemaMap[responseKey] = fieldSubschemaMap?.[responseKey] ?? objectSubschema;
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
|
-
return
|
|
90
|
+
return [...delegationMap.entries()].reduce((prev, [subschema, selectionSet]) => {
|
|
83
91
|
const schema = subschema.transformedSchema || info.schema;
|
|
84
92
|
const type = schema.getType(object.__typename);
|
|
85
93
|
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
function resolve() {
|
|
95
|
+
let source$;
|
|
96
|
+
if (resolver) {
|
|
97
|
+
try {
|
|
98
|
+
source$ = resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return finallyFn(error, subschema, selectionSet);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (isPromise(source$)) {
|
|
105
|
+
return source$.then(source => finallyFn(source, subschema, selectionSet)).catch(error => finallyFn(error, subschema, selectionSet));
|
|
106
|
+
}
|
|
107
|
+
return finallyFn(source$, subschema, selectionSet);
|
|
108
|
+
}
|
|
109
|
+
if (isPromise(prev)) {
|
|
110
|
+
return prev.then(resolve);
|
|
88
111
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.catch(error => finallyFn(error, subschema, selectionSet)))).then(() => { });
|
|
112
|
+
return resolve();
|
|
113
|
+
}, undefined);
|
|
92
114
|
}
|
|
@@ -46,7 +46,7 @@ function resolveExternalObject(type, object, unpathedErrors, subschema, context,
|
|
|
46
46
|
if (!targetSubschemas || !targetSubschemas.length) {
|
|
47
47
|
return object;
|
|
48
48
|
}
|
|
49
|
-
return mergeFields(mergedTypeInfo, object, subschema, context, info)
|
|
49
|
+
return mergeFields(mergedTypeInfo, object, subschema, context, info);
|
|
50
50
|
}
|
|
51
51
|
function resolveExternalList(type, list, unpathedErrors, subschema, context, info, skipTypeMerging) {
|
|
52
52
|
return list.map(listMember => resolveExternalValue(listMember, unpathedErrors, subschema, context, info, type.ofType, skipTypeMerging));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.2-alpha-20230802173210-ebef6bb6",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"@graphql-tools/schema": "^10.0.0",
|
|
13
13
|
"@graphql-tools/utils": "^10.0.0",
|
|
14
14
|
"dataloader": "^2.2.2",
|
|
15
|
-
"tslib": "^2.5.0"
|
|
16
|
-
"value-or-promise": "^1.0.12"
|
|
15
|
+
"tslib": "^2.5.0"
|
|
17
16
|
},
|
|
18
17
|
"repository": {
|
|
19
18
|
"type": "git",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldNode, GraphQLError, GraphQLResolveInfo, GraphQLSchema } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { MaybePromise } from '@graphql-tools/utils';
|
|
3
3
|
import { Subschema } from './Subschema.cjs';
|
|
4
4
|
import { ExternalObject, MergedTypeInfo, SubschemaConfig } from './types.cjs';
|
|
5
5
|
export declare function isExternalObject(data: any): data is ExternalObject;
|
|
@@ -7,4 +7,4 @@ export declare function annotateExternalObject<TContext>(object: any, errors: Ar
|
|
|
7
7
|
export declare function getSubschema(object: ExternalObject, responseKey: string): GraphQLSchema | SubschemaConfig;
|
|
8
8
|
export declare function getUnpathedErrors(object: ExternalObject): Array<GraphQLError>;
|
|
9
9
|
export declare const getActualFieldNodes: (fieldNode: FieldNode) => FieldNode[];
|
|
10
|
-
export declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo):
|
|
10
|
+
export declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo): MaybePromise<any>;
|
package/typings/mergeFields.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldNode, GraphQLError, GraphQLResolveInfo, GraphQLSchema } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { MaybePromise } from '@graphql-tools/utils';
|
|
3
3
|
import { Subschema } from './Subschema.js';
|
|
4
4
|
import { ExternalObject, MergedTypeInfo, SubschemaConfig } from './types.js';
|
|
5
5
|
export declare function isExternalObject(data: any): data is ExternalObject;
|
|
@@ -7,4 +7,4 @@ export declare function annotateExternalObject<TContext>(object: any, errors: Ar
|
|
|
7
7
|
export declare function getSubschema(object: ExternalObject, responseKey: string): GraphQLSchema | SubschemaConfig;
|
|
8
8
|
export declare function getUnpathedErrors(object: ExternalObject): Array<GraphQLError>;
|
|
9
9
|
export declare const getActualFieldNodes: (fieldNode: FieldNode) => FieldNode[];
|
|
10
|
-
export declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo):
|
|
10
|
+
export declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo): MaybePromise<any>;
|