@graphql-tools/delegate 8.5.2 → 8.6.0-alpha-bd5ea4d7.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/createRequest.d.ts +1 -2
- package/index.js +20 -31
- package/index.mjs +21 -31
- package/package.json +5 -5
- package/types.d.ts +2 -12
package/createRequest.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { GraphQLSchema, GraphQLObjectType, OperationTypeNode } from 'graphql';
|
|
2
2
|
import { ExecutionRequest } from '@graphql-tools/utils';
|
|
3
|
-
import {
|
|
3
|
+
import { ICreateRequest } from './types';
|
|
4
4
|
export declare function getDelegatingOperation(parentType: GraphQLObjectType, schema: GraphQLSchema): OperationTypeNode;
|
|
5
|
-
export declare function createRequestFromInfo({ info, rootValue, operationName, operation, fieldName, selectionSet, fieldNodes, context, }: ICreateRequestFromInfo): ExecutionRequest;
|
|
6
5
|
export declare function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetRootValue, targetOperationName, targetOperation, targetFieldName, selectionSet, fieldNodes, context, info, }: ICreateRequest): ExecutionRequest;
|
package/index.js
CHANGED
|
@@ -708,20 +708,21 @@ async function executeDelegationStage(mergedTypeInfo, delegationMap, object, con
|
|
|
708
708
|
const combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
709
709
|
const path = graphql.responsePathAsArray(info.path);
|
|
710
710
|
const combinedFieldSubschemaMap = object[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
711
|
-
|
|
712
|
-
await Promise.all([...delegationMap.entries()].map(async ([s, selectionSet]) => {
|
|
711
|
+
await Promise.all([...delegationMap.entries()].map(async ([subschema, selectionSet]) => {
|
|
713
712
|
var _a;
|
|
714
|
-
const
|
|
713
|
+
const schema = subschema.transformedSchema || info.schema;
|
|
714
|
+
const type = schema.getType(object.__typename);
|
|
715
|
+
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
715
716
|
if (resolver) {
|
|
716
717
|
let source;
|
|
717
718
|
try {
|
|
718
|
-
source = await resolver(object, context, info,
|
|
719
|
+
source = await resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
719
720
|
}
|
|
720
721
|
catch (error) {
|
|
721
722
|
source = error;
|
|
722
723
|
}
|
|
723
724
|
if (source instanceof Error || source == null) {
|
|
724
|
-
const fieldNodeResponseKeyMap = utils.collectFields(
|
|
725
|
+
const fieldNodeResponseKeyMap = utils.collectFields(schema, EMPTY_OBJECT, EMPTY_OBJECT, type, selectionSet, new Map(), new Set());
|
|
725
726
|
const nullResult = {};
|
|
726
727
|
for (const [responseKey, fieldNodes] of fieldNodeResponseKeyMap) {
|
|
727
728
|
const combinedPath = [...path, responseKey];
|
|
@@ -967,24 +968,6 @@ function getDelegatingOperation(parentType, schema) {
|
|
|
967
968
|
}
|
|
968
969
|
return 'query';
|
|
969
970
|
}
|
|
970
|
-
function createRequestFromInfo({ info, rootValue, operationName, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, context, }) {
|
|
971
|
-
return createRequest({
|
|
972
|
-
sourceSchema: info.schema,
|
|
973
|
-
sourceParentType: info.parentType,
|
|
974
|
-
sourceFieldName: info.fieldName,
|
|
975
|
-
fragments: info.fragments,
|
|
976
|
-
variableDefinitions: info.operation.variableDefinitions,
|
|
977
|
-
variableValues: info.variableValues,
|
|
978
|
-
targetRootValue: rootValue,
|
|
979
|
-
targetOperationName: operationName,
|
|
980
|
-
targetOperation: operation,
|
|
981
|
-
targetFieldName: fieldName,
|
|
982
|
-
selectionSet,
|
|
983
|
-
fieldNodes,
|
|
984
|
-
context,
|
|
985
|
-
info,
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
971
|
function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetRootValue, targetOperationName, targetOperation, targetFieldName, selectionSet, fieldNodes, context, info, }) {
|
|
989
972
|
var _a, _b;
|
|
990
973
|
let newSelectionSet;
|
|
@@ -1145,16 +1128,23 @@ function cloneSubschemaConfig(subschemaConfig) {
|
|
|
1145
1128
|
}
|
|
1146
1129
|
|
|
1147
1130
|
function delegateToSchema(options) {
|
|
1148
|
-
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1131
|
+
var _a, _b;
|
|
1132
|
+
const { info, schema, rootValue = (_a = schema.rootValue) !== null && _a !== void 0 ? _a : info.rootValue, operationName = (_b = info.operation.name) === null || _b === void 0 ? void 0 : _b.value, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, context, } = options;
|
|
1133
|
+
const request = createRequest({
|
|
1134
|
+
sourceSchema: info.schema,
|
|
1135
|
+
sourceParentType: info.parentType,
|
|
1136
|
+
sourceFieldName: info.fieldName,
|
|
1137
|
+
fragments: info.fragments,
|
|
1138
|
+
variableDefinitions: info.operation.variableDefinitions,
|
|
1139
|
+
variableValues: info.variableValues,
|
|
1140
|
+
targetRootValue: rootValue,
|
|
1141
|
+
targetOperationName: operationName,
|
|
1142
|
+
targetOperation: operation,
|
|
1143
|
+
targetFieldName: fieldName,
|
|
1153
1144
|
selectionSet,
|
|
1154
1145
|
fieldNodes,
|
|
1155
|
-
rootValue: rootValue !== null && rootValue !== void 0 ? rootValue : schema.rootValue,
|
|
1156
|
-
operationName,
|
|
1157
1146
|
context,
|
|
1147
|
+
info,
|
|
1158
1148
|
});
|
|
1159
1149
|
return delegateRequest({
|
|
1160
1150
|
...options,
|
|
@@ -1278,7 +1268,6 @@ exports.applySchemaTransforms = applySchemaTransforms;
|
|
|
1278
1268
|
exports.cloneSubschemaConfig = cloneSubschemaConfig;
|
|
1279
1269
|
exports.createDefaultExecutor = createDefaultExecutor;
|
|
1280
1270
|
exports.createRequest = createRequest;
|
|
1281
|
-
exports.createRequestFromInfo = createRequestFromInfo;
|
|
1282
1271
|
exports.defaultMergedResolver = defaultMergedResolver;
|
|
1283
1272
|
exports.delegateRequest = delegateRequest;
|
|
1284
1273
|
exports.delegateToSchema = delegateToSchema;
|
package/index.mjs
CHANGED
|
@@ -704,20 +704,21 @@ async function executeDelegationStage(mergedTypeInfo, delegationMap, object, con
|
|
|
704
704
|
const combinedErrors = object[UNPATHED_ERRORS_SYMBOL];
|
|
705
705
|
const path = responsePathAsArray(info.path);
|
|
706
706
|
const combinedFieldSubschemaMap = object[FIELD_SUBSCHEMA_MAP_SYMBOL];
|
|
707
|
-
|
|
708
|
-
await Promise.all([...delegationMap.entries()].map(async ([s, selectionSet]) => {
|
|
707
|
+
await Promise.all([...delegationMap.entries()].map(async ([subschema, selectionSet]) => {
|
|
709
708
|
var _a;
|
|
710
|
-
const
|
|
709
|
+
const schema = subschema.transformedSchema || info.schema;
|
|
710
|
+
const type = schema.getType(object.__typename);
|
|
711
|
+
const resolver = mergedTypeInfo.resolvers.get(subschema);
|
|
711
712
|
if (resolver) {
|
|
712
713
|
let source;
|
|
713
714
|
try {
|
|
714
|
-
source = await resolver(object, context, info,
|
|
715
|
+
source = await resolver(object, context, info, subschema, selectionSet, undefined, type);
|
|
715
716
|
}
|
|
716
717
|
catch (error) {
|
|
717
718
|
source = error;
|
|
718
719
|
}
|
|
719
720
|
if (source instanceof Error || source == null) {
|
|
720
|
-
const fieldNodeResponseKeyMap = collectFields(
|
|
721
|
+
const fieldNodeResponseKeyMap = collectFields(schema, EMPTY_OBJECT, EMPTY_OBJECT, type, selectionSet, new Map(), new Set());
|
|
721
722
|
const nullResult = {};
|
|
722
723
|
for (const [responseKey, fieldNodes] of fieldNodeResponseKeyMap) {
|
|
723
724
|
const combinedPath = [...path, responseKey];
|
|
@@ -963,24 +964,6 @@ function getDelegatingOperation(parentType, schema) {
|
|
|
963
964
|
}
|
|
964
965
|
return 'query';
|
|
965
966
|
}
|
|
966
|
-
function createRequestFromInfo({ info, rootValue, operationName, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, context, }) {
|
|
967
|
-
return createRequest({
|
|
968
|
-
sourceSchema: info.schema,
|
|
969
|
-
sourceParentType: info.parentType,
|
|
970
|
-
sourceFieldName: info.fieldName,
|
|
971
|
-
fragments: info.fragments,
|
|
972
|
-
variableDefinitions: info.operation.variableDefinitions,
|
|
973
|
-
variableValues: info.variableValues,
|
|
974
|
-
targetRootValue: rootValue,
|
|
975
|
-
targetOperationName: operationName,
|
|
976
|
-
targetOperation: operation,
|
|
977
|
-
targetFieldName: fieldName,
|
|
978
|
-
selectionSet,
|
|
979
|
-
fieldNodes,
|
|
980
|
-
context,
|
|
981
|
-
info,
|
|
982
|
-
});
|
|
983
|
-
}
|
|
984
967
|
function createRequest({ sourceSchema, sourceParentType, sourceFieldName, fragments, variableDefinitions, variableValues, targetRootValue, targetOperationName, targetOperation, targetFieldName, selectionSet, fieldNodes, context, info, }) {
|
|
985
968
|
var _a, _b;
|
|
986
969
|
let newSelectionSet;
|
|
@@ -1141,16 +1124,23 @@ function cloneSubschemaConfig(subschemaConfig) {
|
|
|
1141
1124
|
}
|
|
1142
1125
|
|
|
1143
1126
|
function delegateToSchema(options) {
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1127
|
+
var _a, _b;
|
|
1128
|
+
const { info, schema, rootValue = (_a = schema.rootValue) !== null && _a !== void 0 ? _a : info.rootValue, operationName = (_b = info.operation.name) === null || _b === void 0 ? void 0 : _b.value, operation = getDelegatingOperation(info.parentType, info.schema), fieldName = info.fieldName, selectionSet, fieldNodes = info.fieldNodes, context, } = options;
|
|
1129
|
+
const request = createRequest({
|
|
1130
|
+
sourceSchema: info.schema,
|
|
1131
|
+
sourceParentType: info.parentType,
|
|
1132
|
+
sourceFieldName: info.fieldName,
|
|
1133
|
+
fragments: info.fragments,
|
|
1134
|
+
variableDefinitions: info.operation.variableDefinitions,
|
|
1135
|
+
variableValues: info.variableValues,
|
|
1136
|
+
targetRootValue: rootValue,
|
|
1137
|
+
targetOperationName: operationName,
|
|
1138
|
+
targetOperation: operation,
|
|
1139
|
+
targetFieldName: fieldName,
|
|
1149
1140
|
selectionSet,
|
|
1150
1141
|
fieldNodes,
|
|
1151
|
-
rootValue: rootValue !== null && rootValue !== void 0 ? rootValue : schema.rootValue,
|
|
1152
|
-
operationName,
|
|
1153
1142
|
context,
|
|
1143
|
+
info,
|
|
1154
1144
|
});
|
|
1155
1145
|
return delegateRequest({
|
|
1156
1146
|
...options,
|
|
@@ -1267,4 +1257,4 @@ const createDefaultExecutor = memoize1(function createDefaultExecutor(schema) {
|
|
|
1267
1257
|
};
|
|
1268
1258
|
});
|
|
1269
1259
|
|
|
1270
|
-
export { Subschema, Transformer, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor, createRequest,
|
|
1260
|
+
export { Subschema, Transformer, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createDefaultExecutor, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, getDelegatingOperation, getSubschema, getUnpathedErrors, isExternalObject, isSubschema, isSubschemaConfig, mergeFields, resolveExternalValue };
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/delegate",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0-alpha-bd5ea4d7.0",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/batch-execute": "
|
|
11
|
-
"@graphql-tools/schema": "
|
|
12
|
-
"@graphql-tools/utils": "
|
|
10
|
+
"@graphql-tools/batch-execute": "8.4.0-alpha-bd5ea4d7.0",
|
|
11
|
+
"@graphql-tools/schema": "8.3.3",
|
|
12
|
+
"@graphql-tools/utils": "8.6.3",
|
|
13
13
|
"dataloader": "2.0.0",
|
|
14
|
-
"graphql-executor": "0.0.
|
|
14
|
+
"graphql-executor": "0.0.21",
|
|
15
15
|
"tslib": "~2.3.0",
|
|
16
16
|
"value-or-promise": "1.0.11"
|
|
17
17
|
},
|
package/types.d.ts
CHANGED
|
@@ -48,16 +48,6 @@ export interface IDelegateToSchemaOptions<TContext = Record<string, any>, TArgs
|
|
|
48
48
|
export interface IDelegateRequestOptions<TContext = Record<string, any>, TArgs = Record<string, any>> extends IDelegateToSchemaOptions<TContext, TArgs> {
|
|
49
49
|
request: ExecutionRequest;
|
|
50
50
|
}
|
|
51
|
-
export interface ICreateRequestFromInfo {
|
|
52
|
-
info: GraphQLResolveInfo;
|
|
53
|
-
rootValue?: any;
|
|
54
|
-
operationName?: string;
|
|
55
|
-
operation?: OperationTypeNode;
|
|
56
|
-
fieldName?: string;
|
|
57
|
-
selectionSet?: SelectionSetNode;
|
|
58
|
-
fieldNodes?: ReadonlyArray<FieldNode>;
|
|
59
|
-
context?: any;
|
|
60
|
-
}
|
|
61
51
|
export interface ICreateRequest {
|
|
62
52
|
sourceSchema?: GraphQLSchema;
|
|
63
53
|
sourceParentType?: GraphQLObjectType;
|
|
@@ -118,7 +108,7 @@ export interface MergedTypeConfig<K = any, V = any, TContext = Record<string, an
|
|
|
118
108
|
}
|
|
119
109
|
export interface MergedTypeEntryPoint<K = any, V = any, TContext = Record<string, any>> extends MergedTypeResolverOptions<K, V> {
|
|
120
110
|
selectionSet?: string;
|
|
121
|
-
key?: (originalResult: any) => K
|
|
111
|
+
key?: (originalResult: any) => K | PromiseLike<K>;
|
|
122
112
|
resolve?: MergedTypeResolver<TContext>;
|
|
123
113
|
}
|
|
124
114
|
export interface MergedTypeResolverOptions<K = any, V = any> {
|
|
@@ -132,7 +122,7 @@ export interface MergedFieldConfig {
|
|
|
132
122
|
computed?: boolean;
|
|
133
123
|
canonical?: boolean;
|
|
134
124
|
}
|
|
135
|
-
export declare type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema:
|
|
125
|
+
export declare type MergedTypeResolver<TContext = Record<string, any>> = (originalResult: any, context: TContext, info: GraphQLResolveInfo, subschema: Subschema<any, any, any, TContext>, selectionSet: SelectionSetNode, key: any | undefined, type: GraphQLOutputType) => any;
|
|
136
126
|
export interface StitchingInfo<TContext = Record<string, any>> {
|
|
137
127
|
subschemaMap: Map<GraphQLSchema | SubschemaConfig<any, any, any, TContext>, Subschema<any, any, any, TContext>>;
|
|
138
128
|
fieldNodesByType: Record<string, Array<FieldNode>>;
|