@graphql-tools/delegate 12.3.0 → 12.3.1-rc-ef032c8edad551d6d5e4d3460a8ba2a638d0b79b
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 +11 -0
- package/dist/index.cjs +97 -8
- package/dist/index.js +97 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @graphql-tools/delegate
|
|
2
2
|
|
|
3
|
+
## 12.3.1-rc-ef032c8edad551d6d5e4d3460a8ba2a638d0b79b
|
|
4
|
+
### Patch Changes
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
- [#2687](https://github.com/graphql-hive/gateway/pull/2687) [`aabe28a`](https://github.com/graphql-hive/gateway/commit/aabe28a87cc4e85f590bbf4340a9c8700d544223) Thanks [@ardatan](https://github.com/ardatan)! - Deliver forwarded `@defer` patches for nested list items and avoid recursion through `wrapSchema` over a stitched schema
|
|
9
|
+
|
|
10
|
+
When a subschema has `defer: true`, deferred fields inside list items were resolved as `null`: `IncrementalReceiver` did not merge patches into existing list items (including nested lists), and when the subgraph sent several patches in one chunk, every re-emitted patch carried the chunk's `hasNext: false`, so only the first one was applied.
|
|
11
|
+
|
|
12
|
+
Without `defer: true`, a deferred field owned by another inner subschema under `wrapSchema` over a stitched schema called `defaultMergedResolver` on the nested schema with the same parent and recursed. Re-fetch via the nested merged-type resolver for the field owner instead.
|
|
13
|
+
|
|
3
14
|
## 12.3.0
|
|
4
15
|
### Minor Changes
|
|
5
16
|
|
package/dist/index.cjs
CHANGED
|
@@ -3013,6 +3013,16 @@ class IncrementalReceiver {
|
|
|
3013
3013
|
}
|
|
3014
3014
|
if (existing != null && value != null && typeof existing === "object" && typeof value === "object" && !Array.isArray(existing) && !Array.isArray(value) && !(value instanceof Error)) {
|
|
3015
3015
|
this.mergeInto(root, appendPath(relPath, key), value);
|
|
3016
|
+
} else if (Array.isArray(existing) && value != null && typeof value === "object" && !(value instanceof Error)) {
|
|
3017
|
+
const listPath = appendPath(relPath, key);
|
|
3018
|
+
for (const indexKey of Object.keys(value)) {
|
|
3019
|
+
const index = Number(indexKey);
|
|
3020
|
+
const item = value[indexKey];
|
|
3021
|
+
const existingItem = existing[index];
|
|
3022
|
+
if (Number.isInteger(index) && item != null && typeof item === "object" && !(item instanceof Error) && existingItem != null && typeof existingItem === "object" && !(existingItem instanceof Error)) {
|
|
3023
|
+
this.mergeInto(root, appendPath(listPath, index), item);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3016
3026
|
}
|
|
3017
3027
|
continue;
|
|
3018
3028
|
}
|
|
@@ -3234,6 +3244,23 @@ function asHoistLike(transform) {
|
|
|
3234
3244
|
return void 0;
|
|
3235
3245
|
}
|
|
3236
3246
|
|
|
3247
|
+
function pickInnerFieldOwner(mergedTypeInfo, fieldName, info, context) {
|
|
3248
|
+
const uniqueOwner = mergedTypeInfo.uniqueFields[fieldName];
|
|
3249
|
+
if (uniqueOwner != null) {
|
|
3250
|
+
return uniqueOwner;
|
|
3251
|
+
}
|
|
3252
|
+
const candidates = mergedTypeInfo.nonUniqueFields[fieldName];
|
|
3253
|
+
if (candidates == null || candidates.length === 0) {
|
|
3254
|
+
return void 0;
|
|
3255
|
+
}
|
|
3256
|
+
for (const candidate of candidates) {
|
|
3257
|
+
const overrideHandler = candidate.merge?.[mergedTypeInfo.typeName]?.fields?.[fieldName]?.override;
|
|
3258
|
+
if (overrideHandler != null && context != null && handleOverrideByDelegation(info, context, overrideHandler)) {
|
|
3259
|
+
return candidate;
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
return candidates[0];
|
|
3263
|
+
}
|
|
3237
3264
|
function isMissingFieldValue(parent, responseKey) {
|
|
3238
3265
|
return !Object.prototype.hasOwnProperty.call(parent, responseKey) || parent[responseKey] === void 0;
|
|
3239
3266
|
}
|
|
@@ -3478,6 +3505,66 @@ function resolveMissingFieldFromSourceSubschema(parent, args, context, info, sub
|
|
|
3478
3505
|
if (resolve == null || resolve === graphql.defaultFieldResolver) {
|
|
3479
3506
|
return void 0;
|
|
3480
3507
|
}
|
|
3508
|
+
if (resolve === defaultMergedResolver) {
|
|
3509
|
+
const innerStitchingInfo = originalSchema.extensions?.["stitchingInfo"];
|
|
3510
|
+
const innerTypeName = typeof parent.__typename === "string" && parent.__typename || parentTypeName;
|
|
3511
|
+
const innerMergedTypeInfo = innerStitchingInfo?.mergedTypes[innerTypeName];
|
|
3512
|
+
const fieldOwner = innerMergedTypeInfo && pickInnerFieldOwner(innerMergedTypeInfo, sourceFieldName, info, context);
|
|
3513
|
+
const ownerResolver = fieldOwner && innerMergedTypeInfo?.resolvers.get(fieldOwner);
|
|
3514
|
+
const typeInOwner = fieldOwner && (fieldOwner.transformedSchema.getType(innerTypeName) ?? originalSchema.getType(innerTypeName));
|
|
3515
|
+
if (ownerResolver && fieldOwner && typeInOwner && graphql.isObjectType(typeInOwner)) {
|
|
3516
|
+
const selectionSet = {
|
|
3517
|
+
kind: graphql.Kind.SELECTION_SET,
|
|
3518
|
+
selections: info.fieldNodes
|
|
3519
|
+
};
|
|
3520
|
+
const innerParent = annotateExternalObject(
|
|
3521
|
+
{ ...parent },
|
|
3522
|
+
getUnpathedErrors(parent),
|
|
3523
|
+
fieldOwner,
|
|
3524
|
+
/* @__PURE__ */ Object.create(null)
|
|
3525
|
+
);
|
|
3526
|
+
const innerInfo = { ...info, schema: originalSchema };
|
|
3527
|
+
return promiseHelpers.handleMaybePromise(
|
|
3528
|
+
() => ownerResolver(
|
|
3529
|
+
innerParent,
|
|
3530
|
+
context,
|
|
3531
|
+
innerInfo,
|
|
3532
|
+
fieldOwner,
|
|
3533
|
+
selectionSet,
|
|
3534
|
+
void 0,
|
|
3535
|
+
typeInOwner
|
|
3536
|
+
),
|
|
3537
|
+
(resolverResult) => {
|
|
3538
|
+
handleResolverResult(
|
|
3539
|
+
resolverResult,
|
|
3540
|
+
fieldOwner,
|
|
3541
|
+
selectionSet,
|
|
3542
|
+
innerParent,
|
|
3543
|
+
innerParent[FIELD_SUBSCHEMA_MAP_SYMBOL] ?? /* @__PURE__ */ Object.create(null),
|
|
3544
|
+
innerInfo,
|
|
3545
|
+
graphql.responsePathAsArray(info.path).slice(0, -1),
|
|
3546
|
+
innerParent[UNPATHED_ERRORS_SYMBOL] ?? []
|
|
3547
|
+
);
|
|
3548
|
+
if (!isMissingFieldValue(innerParent, responseKey)) {
|
|
3549
|
+
const value = innerParent[responseKey];
|
|
3550
|
+
parent[responseKey] = value;
|
|
3551
|
+
if (parent[FIELD_SUBSCHEMA_MAP_SYMBOL]) {
|
|
3552
|
+
parent[FIELD_SUBSCHEMA_MAP_SYMBOL][responseKey] = subschema;
|
|
3553
|
+
}
|
|
3554
|
+
return resolveExternalValue(
|
|
3555
|
+
value,
|
|
3556
|
+
getUnpathedErrors(parent),
|
|
3557
|
+
subschema,
|
|
3558
|
+
context,
|
|
3559
|
+
info
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
return void 0;
|
|
3563
|
+
}
|
|
3564
|
+
);
|
|
3565
|
+
}
|
|
3566
|
+
return void 0;
|
|
3567
|
+
}
|
|
3481
3568
|
return promiseHelpers.handleMaybePromise(
|
|
3482
3569
|
() => resolve(parent, args, context, info),
|
|
3483
3570
|
(value) => {
|
|
@@ -4202,7 +4289,9 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4202
4289
|
const fieldName = delegationContext.fieldName;
|
|
4203
4290
|
for await (const result of iterable) {
|
|
4204
4291
|
if (result?.incremental?.length) {
|
|
4205
|
-
|
|
4292
|
+
const lastPatchIndex = result.incremental.length - 1;
|
|
4293
|
+
for (const [patchIndex, patch] of result.incremental.entries()) {
|
|
4294
|
+
const hasNext = patchIndex < lastPatchIndex ? true : result.hasNext;
|
|
4206
4295
|
if (patch.items != null) {
|
|
4207
4296
|
const rewrittenPath = Array.isArray(patch.path) && patch.path.length > 0 ? applyErrorPathTransformers(
|
|
4208
4297
|
patch.path,
|
|
@@ -4212,7 +4301,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4212
4301
|
incremental: [
|
|
4213
4302
|
rewrittenPath != null ? { ...patch, path: rewrittenPath } : patch
|
|
4214
4303
|
],
|
|
4215
|
-
hasNext
|
|
4304
|
+
hasNext
|
|
4216
4305
|
};
|
|
4217
4306
|
continue;
|
|
4218
4307
|
}
|
|
@@ -4229,7 +4318,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4229
4318
|
path: rewrittenPath
|
|
4230
4319
|
}
|
|
4231
4320
|
],
|
|
4232
|
-
hasNext
|
|
4321
|
+
hasNext
|
|
4233
4322
|
};
|
|
4234
4323
|
continue;
|
|
4235
4324
|
}
|
|
@@ -4260,23 +4349,23 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4260
4349
|
errors: [transformedValue]
|
|
4261
4350
|
}
|
|
4262
4351
|
],
|
|
4263
|
-
hasNext
|
|
4352
|
+
hasNext
|
|
4264
4353
|
};
|
|
4265
4354
|
} else if (transformedValue != null && typeof transformedValue === "object") {
|
|
4266
4355
|
yield {
|
|
4267
4356
|
data: { [fieldName]: transformedValue },
|
|
4268
|
-
hasNext
|
|
4357
|
+
hasNext
|
|
4269
4358
|
};
|
|
4270
4359
|
} else {
|
|
4271
4360
|
yield {
|
|
4272
4361
|
incremental: [patch],
|
|
4273
|
-
hasNext
|
|
4362
|
+
hasNext
|
|
4274
4363
|
};
|
|
4275
4364
|
}
|
|
4276
4365
|
} catch {
|
|
4277
4366
|
yield {
|
|
4278
4367
|
incremental: [patch],
|
|
4279
|
-
hasNext
|
|
4368
|
+
hasNext
|
|
4280
4369
|
};
|
|
4281
4370
|
}
|
|
4282
4371
|
continue;
|
|
@@ -4289,7 +4378,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4289
4378
|
incremental: [
|
|
4290
4379
|
rewrittenErrorPath != null ? { ...patch, path: rewrittenErrorPath } : patch
|
|
4291
4380
|
],
|
|
4292
|
-
hasNext
|
|
4381
|
+
hasNext
|
|
4293
4382
|
};
|
|
4294
4383
|
}
|
|
4295
4384
|
} else if (result?.data) {
|
package/dist/index.js
CHANGED
|
@@ -3013,6 +3013,16 @@ class IncrementalReceiver {
|
|
|
3013
3013
|
}
|
|
3014
3014
|
if (existing != null && value != null && typeof existing === "object" && typeof value === "object" && !Array.isArray(existing) && !Array.isArray(value) && !(value instanceof Error)) {
|
|
3015
3015
|
this.mergeInto(root, appendPath(relPath, key), value);
|
|
3016
|
+
} else if (Array.isArray(existing) && value != null && typeof value === "object" && !(value instanceof Error)) {
|
|
3017
|
+
const listPath = appendPath(relPath, key);
|
|
3018
|
+
for (const indexKey of Object.keys(value)) {
|
|
3019
|
+
const index = Number(indexKey);
|
|
3020
|
+
const item = value[indexKey];
|
|
3021
|
+
const existingItem = existing[index];
|
|
3022
|
+
if (Number.isInteger(index) && item != null && typeof item === "object" && !(item instanceof Error) && existingItem != null && typeof existingItem === "object" && !(existingItem instanceof Error)) {
|
|
3023
|
+
this.mergeInto(root, appendPath(listPath, index), item);
|
|
3024
|
+
}
|
|
3025
|
+
}
|
|
3016
3026
|
}
|
|
3017
3027
|
continue;
|
|
3018
3028
|
}
|
|
@@ -3234,6 +3244,23 @@ function asHoistLike(transform) {
|
|
|
3234
3244
|
return void 0;
|
|
3235
3245
|
}
|
|
3236
3246
|
|
|
3247
|
+
function pickInnerFieldOwner(mergedTypeInfo, fieldName, info, context) {
|
|
3248
|
+
const uniqueOwner = mergedTypeInfo.uniqueFields[fieldName];
|
|
3249
|
+
if (uniqueOwner != null) {
|
|
3250
|
+
return uniqueOwner;
|
|
3251
|
+
}
|
|
3252
|
+
const candidates = mergedTypeInfo.nonUniqueFields[fieldName];
|
|
3253
|
+
if (candidates == null || candidates.length === 0) {
|
|
3254
|
+
return void 0;
|
|
3255
|
+
}
|
|
3256
|
+
for (const candidate of candidates) {
|
|
3257
|
+
const overrideHandler = candidate.merge?.[mergedTypeInfo.typeName]?.fields?.[fieldName]?.override;
|
|
3258
|
+
if (overrideHandler != null && context != null && handleOverrideByDelegation(info, context, overrideHandler)) {
|
|
3259
|
+
return candidate;
|
|
3260
|
+
}
|
|
3261
|
+
}
|
|
3262
|
+
return candidates[0];
|
|
3263
|
+
}
|
|
3237
3264
|
function isMissingFieldValue(parent, responseKey) {
|
|
3238
3265
|
return !Object.prototype.hasOwnProperty.call(parent, responseKey) || parent[responseKey] === void 0;
|
|
3239
3266
|
}
|
|
@@ -3478,6 +3505,66 @@ function resolveMissingFieldFromSourceSubschema(parent, args, context, info, sub
|
|
|
3478
3505
|
if (resolve == null || resolve === defaultFieldResolver) {
|
|
3479
3506
|
return void 0;
|
|
3480
3507
|
}
|
|
3508
|
+
if (resolve === defaultMergedResolver) {
|
|
3509
|
+
const innerStitchingInfo = originalSchema.extensions?.["stitchingInfo"];
|
|
3510
|
+
const innerTypeName = typeof parent.__typename === "string" && parent.__typename || parentTypeName;
|
|
3511
|
+
const innerMergedTypeInfo = innerStitchingInfo?.mergedTypes[innerTypeName];
|
|
3512
|
+
const fieldOwner = innerMergedTypeInfo && pickInnerFieldOwner(innerMergedTypeInfo, sourceFieldName, info, context);
|
|
3513
|
+
const ownerResolver = fieldOwner && innerMergedTypeInfo?.resolvers.get(fieldOwner);
|
|
3514
|
+
const typeInOwner = fieldOwner && (fieldOwner.transformedSchema.getType(innerTypeName) ?? originalSchema.getType(innerTypeName));
|
|
3515
|
+
if (ownerResolver && fieldOwner && typeInOwner && isObjectType(typeInOwner)) {
|
|
3516
|
+
const selectionSet = {
|
|
3517
|
+
kind: Kind.SELECTION_SET,
|
|
3518
|
+
selections: info.fieldNodes
|
|
3519
|
+
};
|
|
3520
|
+
const innerParent = annotateExternalObject(
|
|
3521
|
+
{ ...parent },
|
|
3522
|
+
getUnpathedErrors(parent),
|
|
3523
|
+
fieldOwner,
|
|
3524
|
+
/* @__PURE__ */ Object.create(null)
|
|
3525
|
+
);
|
|
3526
|
+
const innerInfo = { ...info, schema: originalSchema };
|
|
3527
|
+
return handleMaybePromise(
|
|
3528
|
+
() => ownerResolver(
|
|
3529
|
+
innerParent,
|
|
3530
|
+
context,
|
|
3531
|
+
innerInfo,
|
|
3532
|
+
fieldOwner,
|
|
3533
|
+
selectionSet,
|
|
3534
|
+
void 0,
|
|
3535
|
+
typeInOwner
|
|
3536
|
+
),
|
|
3537
|
+
(resolverResult) => {
|
|
3538
|
+
handleResolverResult(
|
|
3539
|
+
resolverResult,
|
|
3540
|
+
fieldOwner,
|
|
3541
|
+
selectionSet,
|
|
3542
|
+
innerParent,
|
|
3543
|
+
innerParent[FIELD_SUBSCHEMA_MAP_SYMBOL] ?? /* @__PURE__ */ Object.create(null),
|
|
3544
|
+
innerInfo,
|
|
3545
|
+
responsePathAsArray(info.path).slice(0, -1),
|
|
3546
|
+
innerParent[UNPATHED_ERRORS_SYMBOL] ?? []
|
|
3547
|
+
);
|
|
3548
|
+
if (!isMissingFieldValue(innerParent, responseKey)) {
|
|
3549
|
+
const value = innerParent[responseKey];
|
|
3550
|
+
parent[responseKey] = value;
|
|
3551
|
+
if (parent[FIELD_SUBSCHEMA_MAP_SYMBOL]) {
|
|
3552
|
+
parent[FIELD_SUBSCHEMA_MAP_SYMBOL][responseKey] = subschema;
|
|
3553
|
+
}
|
|
3554
|
+
return resolveExternalValue(
|
|
3555
|
+
value,
|
|
3556
|
+
getUnpathedErrors(parent),
|
|
3557
|
+
subschema,
|
|
3558
|
+
context,
|
|
3559
|
+
info
|
|
3560
|
+
);
|
|
3561
|
+
}
|
|
3562
|
+
return void 0;
|
|
3563
|
+
}
|
|
3564
|
+
);
|
|
3565
|
+
}
|
|
3566
|
+
return void 0;
|
|
3567
|
+
}
|
|
3481
3568
|
return handleMaybePromise(
|
|
3482
3569
|
() => resolve(parent, args, context, info),
|
|
3483
3570
|
(value) => {
|
|
@@ -4202,7 +4289,9 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4202
4289
|
const fieldName = delegationContext.fieldName;
|
|
4203
4290
|
for await (const result of iterable) {
|
|
4204
4291
|
if (result?.incremental?.length) {
|
|
4205
|
-
|
|
4292
|
+
const lastPatchIndex = result.incremental.length - 1;
|
|
4293
|
+
for (const [patchIndex, patch] of result.incremental.entries()) {
|
|
4294
|
+
const hasNext = patchIndex < lastPatchIndex ? true : result.hasNext;
|
|
4206
4295
|
if (patch.items != null) {
|
|
4207
4296
|
const rewrittenPath = Array.isArray(patch.path) && patch.path.length > 0 ? applyErrorPathTransformers(
|
|
4208
4297
|
patch.path,
|
|
@@ -4212,7 +4301,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4212
4301
|
incremental: [
|
|
4213
4302
|
rewrittenPath != null ? { ...patch, path: rewrittenPath } : patch
|
|
4214
4303
|
],
|
|
4215
|
-
hasNext
|
|
4304
|
+
hasNext
|
|
4216
4305
|
};
|
|
4217
4306
|
continue;
|
|
4218
4307
|
}
|
|
@@ -4229,7 +4318,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4229
4318
|
path: rewrittenPath
|
|
4230
4319
|
}
|
|
4231
4320
|
],
|
|
4232
|
-
hasNext
|
|
4321
|
+
hasNext
|
|
4233
4322
|
};
|
|
4234
4323
|
continue;
|
|
4235
4324
|
}
|
|
@@ -4260,23 +4349,23 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4260
4349
|
errors: [transformedValue]
|
|
4261
4350
|
}
|
|
4262
4351
|
],
|
|
4263
|
-
hasNext
|
|
4352
|
+
hasNext
|
|
4264
4353
|
};
|
|
4265
4354
|
} else if (transformedValue != null && typeof transformedValue === "object") {
|
|
4266
4355
|
yield {
|
|
4267
4356
|
data: { [fieldName]: transformedValue },
|
|
4268
|
-
hasNext
|
|
4357
|
+
hasNext
|
|
4269
4358
|
};
|
|
4270
4359
|
} else {
|
|
4271
4360
|
yield {
|
|
4272
4361
|
incremental: [patch],
|
|
4273
|
-
hasNext
|
|
4362
|
+
hasNext
|
|
4274
4363
|
};
|
|
4275
4364
|
}
|
|
4276
4365
|
} catch {
|
|
4277
4366
|
yield {
|
|
4278
4367
|
incremental: [patch],
|
|
4279
|
-
hasNext
|
|
4368
|
+
hasNext
|
|
4280
4369
|
};
|
|
4281
4370
|
}
|
|
4282
4371
|
continue;
|
|
@@ -4289,7 +4378,7 @@ async function* transformDeferredChunks(iterable, transformer, delegationContext
|
|
|
4289
4378
|
incremental: [
|
|
4290
4379
|
rewrittenErrorPath != null ? { ...patch, path: rewrittenErrorPath } : patch
|
|
4291
4380
|
],
|
|
4292
|
-
hasNext
|
|
4381
|
+
hasNext
|
|
4293
4382
|
};
|
|
4294
4383
|
}
|
|
4295
4384
|
} else if (result?.data) {
|
package/package.json
CHANGED