@graphql-tools/delegate 12.1.1 → 12.1.2-alpha-a25a0e4521aff5261d06903efe4386cd565f2e57
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +28 -7
- package/dist/index.d.cts +2 -3
- package/dist/index.d.ts +2 -3
- package/dist/index.js +29 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @graphql-tools/delegate
|
|
2
2
|
|
|
3
|
+
## 12.1.2-alpha-a25a0e4521aff5261d06903efe4386cd565f2e57
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#2555](https://github.com/graphql-hive/gateway/pull/2555) [`a25a0e4`](https://github.com/graphql-hive/gateway/commit/a25a0e4521aff5261d06903efe4386cd565f2e57) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Flush deferred merged fields without blocking the initial payload
|
|
9
|
+
|
|
10
|
+
Deferred fields on merged entity types are now delegated when their deferred resolvers run instead of being included in the initial delegation plan. This allows the initial payload to be delivered before slower merged subgraph fields resolve.
|
|
11
|
+
|
|
3
12
|
## 12.1.1
|
|
4
13
|
### Patch Changes
|
|
5
14
|
|
package/dist/index.cjs
CHANGED
|
@@ -96,18 +96,17 @@ function getSubschema(object, responseKey) {
|
|
|
96
96
|
function getUnpathedErrors(object) {
|
|
97
97
|
return object[UNPATHED_ERRORS_SYMBOL];
|
|
98
98
|
}
|
|
99
|
-
const EMPTY_ARRAY = [];
|
|
100
99
|
const EMPTY_OBJECT = /* @__PURE__ */ Object.create(null);
|
|
101
100
|
const getActualFieldNodes = utils.memoize1(function(fieldNode) {
|
|
102
101
|
return [fieldNode];
|
|
103
102
|
});
|
|
104
|
-
function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
103
|
+
function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info, fieldNodes = info.fieldNodes) {
|
|
105
104
|
const delegationMaps = mergedTypeInfo.delegationPlanBuilder(
|
|
106
105
|
info.schema,
|
|
107
106
|
sourceSubschema,
|
|
108
107
|
info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
|
|
109
108
|
info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
|
|
110
|
-
|
|
109
|
+
fieldNodes.length === 1 && fieldNodes[0] ? getActualFieldNodes(fieldNodes[0]) : fieldNodes,
|
|
111
110
|
context,
|
|
112
111
|
info
|
|
113
112
|
);
|
|
@@ -2572,9 +2571,9 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
2572
2571
|
}
|
|
2573
2572
|
const deferred = promiseHelpers.createDeferredPromise();
|
|
2574
2573
|
missingDeferredFields.set(responseKey, deferred);
|
|
2575
|
-
const
|
|
2576
|
-
const
|
|
2577
|
-
const fieldNodesByType =
|
|
2574
|
+
const stitchingInfo2 = info.schema.extensions?.["stitchingInfo"];
|
|
2575
|
+
const parentTypeName2 = parent?.__typename || info.parentType.name;
|
|
2576
|
+
const fieldNodesByType = stitchingInfo2?.fieldNodesByField?.[parentTypeName2]?.[info.fieldName];
|
|
2578
2577
|
if (fieldNodesByType?.every((fieldNode) => {
|
|
2579
2578
|
const responseKey2 = fieldNode.alias?.value ?? fieldNode.name.value;
|
|
2580
2579
|
return Object.prototype.hasOwnProperty.call(parent, responseKey2);
|
|
@@ -2588,6 +2587,29 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
2588
2587
|
if (Object.prototype.hasOwnProperty.call(parent, info.fieldName)) {
|
|
2589
2588
|
return graphql.defaultFieldResolver(parent, args, context, info);
|
|
2590
2589
|
}
|
|
2590
|
+
const stitchingInfo = info.schema?.extensions?.["stitchingInfo"];
|
|
2591
|
+
const parentTypeName = parent.__typename || info.parentType?.name;
|
|
2592
|
+
const mergedTypeInfo = parentTypeName ? stitchingInfo?.mergedTypes[parentTypeName] : void 0;
|
|
2593
|
+
const sourceSubschema = parent[OBJECT_SUBSCHEMA_SYMBOL];
|
|
2594
|
+
if (mergedTypeInfo && sourceSubschema) {
|
|
2595
|
+
const fieldNode = {
|
|
2596
|
+
kind: graphql.Kind.FIELD,
|
|
2597
|
+
name: info.fieldNodes[0]?.name ?? {
|
|
2598
|
+
kind: graphql.Kind.NAME,
|
|
2599
|
+
value: info.fieldName
|
|
2600
|
+
},
|
|
2601
|
+
selectionSet: {
|
|
2602
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
2603
|
+
selections: info.fieldNodes
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
return promiseHelpers.handleMaybePromise(
|
|
2607
|
+
() => mergeFields(mergedTypeInfo, parent, sourceSubschema, context, info, [
|
|
2608
|
+
fieldNode
|
|
2609
|
+
]),
|
|
2610
|
+
() => Object.prototype.hasOwnProperty.call(parent, responseKey) ? handleResult(parent, responseKey, context, info) : void 0
|
|
2611
|
+
);
|
|
2612
|
+
}
|
|
2591
2613
|
return void 0;
|
|
2592
2614
|
}
|
|
2593
2615
|
return handleResult(parent, responseKey, context, info);
|
|
@@ -3494,7 +3516,6 @@ Object.defineProperty(exports, "createDefaultExecutor", {
|
|
|
3494
3516
|
enumerable: true,
|
|
3495
3517
|
get: function () { return executor.executorFromSchema; }
|
|
3496
3518
|
});
|
|
3497
|
-
exports.EMPTY_ARRAY = EMPTY_ARRAY;
|
|
3498
3519
|
exports.EMPTY_OBJECT = EMPTY_OBJECT;
|
|
3499
3520
|
exports.FIELD_SUBSCHEMA_MAP_SYMBOL = FIELD_SUBSCHEMA_MAP_SYMBOL;
|
|
3500
3521
|
exports.OBJECT_SUBSCHEMA_SYMBOL = OBJECT_SUBSCHEMA_SYMBOL;
|
package/dist/index.d.cts
CHANGED
|
@@ -199,10 +199,9 @@ declare function isExternalObject(data: any): data is ExternalObject;
|
|
|
199
199
|
declare function annotateExternalObject<TContext>(object: any, errors: Array<GraphQLError>, subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext> | undefined, subschemaMap: Record<string, GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>>): ExternalObject;
|
|
200
200
|
declare function getSubschema(object: ExternalObject, responseKey: string): GraphQLSchema | SubschemaConfig;
|
|
201
201
|
declare function getUnpathedErrors(object: ExternalObject): Array<GraphQLError>;
|
|
202
|
-
declare const EMPTY_ARRAY: any[];
|
|
203
202
|
declare const EMPTY_OBJECT: any;
|
|
204
203
|
declare const getActualFieldNodes: (fieldNode: FieldNode) => FieldNode[];
|
|
205
|
-
declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo): MaybePromise<any>;
|
|
204
|
+
declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo, fieldNodes?: FieldNode[]): MaybePromise<any>;
|
|
206
205
|
declare function handleResolverResult(resolverResult: any, subschema: Subschema, selectionSet: SelectionSetNode, object: ExternalObject, combinedFieldSubschemaMap: Record<string, GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>>, info: GraphQLResolveInfo, path: Array<string | number>, combinedErrors: Array<GraphQLError>): void;
|
|
207
206
|
|
|
208
207
|
declare function resolveExternalValue<TContext extends Record<string, any>>(result: any, unpathedErrors: Array<GraphQLError>, subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext>, context?: Record<string, any>, info?: GraphQLResolveInfo, returnType?: GraphQLOutputType, skipTypeMerging?: boolean): any;
|
|
@@ -239,4 +238,4 @@ declare function isPrototypePollutingKey(key: string): key is PrototypePolluting
|
|
|
239
238
|
|
|
240
239
|
declare const handleOverrideByDelegation: (info: GraphQLResolveInfo$1, context: any, overrideHandler: OverrideHandler) => boolean;
|
|
241
240
|
|
|
242
|
-
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver,
|
|
241
|
+
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, EMPTY_OBJECT, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, type OverrideHandler, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getTypeInfo, getTypeInfoWithType, getUnpathedErrors, handleOverrideByDelegation, handleResolverResult, isExternalObject, isPrototypePollutingKey, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/dist/index.d.ts
CHANGED
|
@@ -199,10 +199,9 @@ declare function isExternalObject(data: any): data is ExternalObject;
|
|
|
199
199
|
declare function annotateExternalObject<TContext>(object: any, errors: Array<GraphQLError>, subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext> | undefined, subschemaMap: Record<string, GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>>): ExternalObject;
|
|
200
200
|
declare function getSubschema(object: ExternalObject, responseKey: string): GraphQLSchema | SubschemaConfig;
|
|
201
201
|
declare function getUnpathedErrors(object: ExternalObject): Array<GraphQLError>;
|
|
202
|
-
declare const EMPTY_ARRAY: any[];
|
|
203
202
|
declare const EMPTY_OBJECT: any;
|
|
204
203
|
declare const getActualFieldNodes: (fieldNode: FieldNode) => FieldNode[];
|
|
205
|
-
declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo): MaybePromise<any>;
|
|
204
|
+
declare function mergeFields<TContext>(mergedTypeInfo: MergedTypeInfo, object: any, sourceSubschema: Subschema<any, any, any, TContext>, context: any, info: GraphQLResolveInfo, fieldNodes?: FieldNode[]): MaybePromise<any>;
|
|
206
205
|
declare function handleResolverResult(resolverResult: any, subschema: Subschema, selectionSet: SelectionSetNode, object: ExternalObject, combinedFieldSubschemaMap: Record<string, GraphQLSchema | SubschemaConfig<any, any, any, Record<string, any>>>, info: GraphQLResolveInfo, path: Array<string | number>, combinedErrors: Array<GraphQLError>): void;
|
|
207
206
|
|
|
208
207
|
declare function resolveExternalValue<TContext extends Record<string, any>>(result: any, unpathedErrors: Array<GraphQLError>, subschema: GraphQLSchema | SubschemaConfig<any, any, any, TContext>, context?: Record<string, any>, info?: GraphQLResolveInfo, returnType?: GraphQLOutputType, skipTypeMerging?: boolean): any;
|
|
@@ -239,4 +238,4 @@ declare function isPrototypePollutingKey(key: string): key is PrototypePolluting
|
|
|
239
238
|
|
|
240
239
|
declare const handleOverrideByDelegation: (info: GraphQLResolveInfo$1, context: any, overrideHandler: OverrideHandler) => boolean;
|
|
241
240
|
|
|
242
|
-
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver,
|
|
241
|
+
export { type BatchingOptions, type CreateProxyingResolverFn, type Deferred, type DelegationContext, type DelegationPlanBuilder, type DelegationPlanLeftOver, EMPTY_OBJECT, type ExternalObject, FIELD_SUBSCHEMA_MAP_SYMBOL, type ICreateProxyingResolverOptions, type ICreateRequest, type IDelegateRequestOptions, type IDelegateToSchemaOptions, type MergedFieldConfig, type MergedTypeConfig, type MergedTypeEntryPoint, type MergedTypeInfo, type MergedTypeResolver, type MergedTypeResolverOptions, OBJECT_SUBSCHEMA_SYMBOL, type OverrideHandler, PLAN_LEFT_OVER, type RequestTransform, type ResultTransform, type SchemaTransform, type StitchingInfo, Subschema, type SubschemaConfig, type Transform, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getTypeInfo, getTypeInfoWithType, getUnpathedErrors, handleOverrideByDelegation, handleResolverResult, isExternalObject, isPrototypePollutingKey, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/dist/index.js
CHANGED
|
@@ -96,18 +96,17 @@ function getSubschema(object, responseKey) {
|
|
|
96
96
|
function getUnpathedErrors(object) {
|
|
97
97
|
return object[UNPATHED_ERRORS_SYMBOL];
|
|
98
98
|
}
|
|
99
|
-
const EMPTY_ARRAY = [];
|
|
100
99
|
const EMPTY_OBJECT = /* @__PURE__ */ Object.create(null);
|
|
101
100
|
const getActualFieldNodes = memoize1(function(fieldNode) {
|
|
102
101
|
return [fieldNode];
|
|
103
102
|
});
|
|
104
|
-
function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
|
|
103
|
+
function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info, fieldNodes = info.fieldNodes) {
|
|
105
104
|
const delegationMaps = mergedTypeInfo.delegationPlanBuilder(
|
|
106
105
|
info.schema,
|
|
107
106
|
sourceSubschema,
|
|
108
107
|
info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
|
|
109
108
|
info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
|
|
110
|
-
|
|
109
|
+
fieldNodes.length === 1 && fieldNodes[0] ? getActualFieldNodes(fieldNodes[0]) : fieldNodes,
|
|
111
110
|
context,
|
|
112
111
|
info
|
|
113
112
|
);
|
|
@@ -2572,9 +2571,9 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
2572
2571
|
}
|
|
2573
2572
|
const deferred = createDeferredPromise();
|
|
2574
2573
|
missingDeferredFields.set(responseKey, deferred);
|
|
2575
|
-
const
|
|
2576
|
-
const
|
|
2577
|
-
const fieldNodesByType =
|
|
2574
|
+
const stitchingInfo2 = info.schema.extensions?.["stitchingInfo"];
|
|
2575
|
+
const parentTypeName2 = parent?.__typename || info.parentType.name;
|
|
2576
|
+
const fieldNodesByType = stitchingInfo2?.fieldNodesByField?.[parentTypeName2]?.[info.fieldName];
|
|
2578
2577
|
if (fieldNodesByType?.every((fieldNode) => {
|
|
2579
2578
|
const responseKey2 = fieldNode.alias?.value ?? fieldNode.name.value;
|
|
2580
2579
|
return Object.prototype.hasOwnProperty.call(parent, responseKey2);
|
|
@@ -2588,6 +2587,29 @@ function defaultMergedResolver(parent, args, context, info) {
|
|
|
2588
2587
|
if (Object.prototype.hasOwnProperty.call(parent, info.fieldName)) {
|
|
2589
2588
|
return defaultFieldResolver(parent, args, context, info);
|
|
2590
2589
|
}
|
|
2590
|
+
const stitchingInfo = info.schema?.extensions?.["stitchingInfo"];
|
|
2591
|
+
const parentTypeName = parent.__typename || info.parentType?.name;
|
|
2592
|
+
const mergedTypeInfo = parentTypeName ? stitchingInfo?.mergedTypes[parentTypeName] : void 0;
|
|
2593
|
+
const sourceSubschema = parent[OBJECT_SUBSCHEMA_SYMBOL];
|
|
2594
|
+
if (mergedTypeInfo && sourceSubschema) {
|
|
2595
|
+
const fieldNode = {
|
|
2596
|
+
kind: Kind.FIELD,
|
|
2597
|
+
name: info.fieldNodes[0]?.name ?? {
|
|
2598
|
+
kind: Kind.NAME,
|
|
2599
|
+
value: info.fieldName
|
|
2600
|
+
},
|
|
2601
|
+
selectionSet: {
|
|
2602
|
+
kind: Kind.SELECTION_SET,
|
|
2603
|
+
selections: info.fieldNodes
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
return handleMaybePromise(
|
|
2607
|
+
() => mergeFields(mergedTypeInfo, parent, sourceSubschema, context, info, [
|
|
2608
|
+
fieldNode
|
|
2609
|
+
]),
|
|
2610
|
+
() => Object.prototype.hasOwnProperty.call(parent, responseKey) ? handleResult(parent, responseKey, context, info) : void 0
|
|
2611
|
+
);
|
|
2612
|
+
}
|
|
2591
2613
|
return void 0;
|
|
2592
2614
|
}
|
|
2593
2615
|
return handleResult(parent, responseKey, context, info);
|
|
@@ -3486,4 +3508,4 @@ function subtractSelectionSets(selectionSetA, selectionSetB, fragments = {}) {
|
|
|
3486
3508
|
};
|
|
3487
3509
|
}
|
|
3488
3510
|
|
|
3489
|
-
export {
|
|
3511
|
+
export { EMPTY_OBJECT, FIELD_SUBSCHEMA_MAP_SYMBOL, OBJECT_SUBSCHEMA_SYMBOL, PLAN_LEFT_OVER, Subschema, Transformer, UNPATHED_ERRORS_SYMBOL, annotateExternalObject, applySchemaTransforms, cloneSubschemaConfig, createRequest, defaultMergedResolver, delegateRequest, delegateToSchema, extractUnavailableFields, extractUnavailableFieldsFromSelectionSet, getActualFieldNodes, getDelegatingOperation, getPlanLeftOverFromParent, getSubschema, getTypeInfo, getTypeInfoWithType, getUnpathedErrors, handleOverrideByDelegation, handleResolverResult, isExternalObject, isPrototypePollutingKey, isSubschema, isSubschemaConfig, leftOverByDelegationPlan, mergeFields, resolveExternalValue, subtractSelectionSets };
|
package/package.json
CHANGED