Comparing version 17.0.0-alpha.3.canary.pr.4026.5e657d31b3abdc38acd6bb21c50ed3a41aa33905 to 17.0.0-alpha.3.canary.pr.4026.74aa85f56dea9ab9feb4445165eb0e2347ea674f
@@ -18,3 +18,3 @@ import type { ObjMap } from '../jsutils/ObjMap.js'; | ||
export type FieldGroup = ReadonlyArray<FieldDetails>; | ||
export type GroupedFieldSet = Map<string, FieldGroup>; | ||
export type GroupedFieldSet = ReadonlyMap<string, FieldGroup>; | ||
/** | ||
@@ -21,0 +21,0 @@ * Given a selectionSet, collects all of the fields and returns them. |
@@ -64,6 +64,5 @@ import type { Maybe } from '../jsutils/Maybe.js'; | ||
subscribeFieldResolver: GraphQLFieldResolver<any, any>; | ||
errors: Array<GraphQLError>; | ||
cancellableStreams: Set<StreamRecord>; | ||
errorPaths: Set<Path | undefined>; | ||
futures: Array<Future>; | ||
errors?: Map<Path | undefined, GraphQLError> | undefined; | ||
cancellableStreams?: Set<StreamRecord> | undefined; | ||
futures?: Array<Future>; | ||
} | ||
@@ -70,0 +69,0 @@ export interface ExecutionArgs { |
@@ -20,3 +20,2 @@ 'use strict'; | ||
const memoize3_js_1 = require('../jsutils/memoize3.js'); | ||
const memoizeByFirst_js_1 = require('../jsutils/memoizeByFirst.js'); | ||
const Path_js_1 = require('../jsutils/Path.js'); | ||
@@ -56,9 +55,14 @@ const promiseForObject_js_1 = require('../jsutils/promiseForObject.js'); | ||
); | ||
const buildSubFieldPlan = (0, memoizeByFirst_js_1.memoizeByFirst)( | ||
(originalGroupedFieldSet, deferUsageSet) => | ||
(0, buildFieldPlan_js_1.buildFieldPlan)( | ||
originalGroupedFieldSet, | ||
deferUsageSet, | ||
), | ||
); | ||
const buildSubFieldPlan = (originalGroupedFieldSet, deferUsageSet) => { | ||
let fieldPlan = originalGroupedFieldSet._fieldPlan; | ||
if (fieldPlan !== undefined) { | ||
return fieldPlan; | ||
} | ||
fieldPlan = (0, buildFieldPlan_js_1.buildFieldPlan)( | ||
originalGroupedFieldSet, | ||
deferUsageSet, | ||
); | ||
originalGroupedFieldSet._fieldPlan = fieldPlan; | ||
return fieldPlan; | ||
}; | ||
const UNEXPECTED_EXPERIMENTAL_DIRECTIVES = | ||
@@ -144,13 +148,4 @@ 'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.'; | ||
let data; | ||
const { | ||
operation, | ||
schema, | ||
fragments, | ||
variableValues, | ||
rootValue, | ||
errors, | ||
errorPaths, | ||
futures, | ||
cancellableStreams, | ||
} = exeContext; | ||
const { operation, schema, fragments, variableValues, rootValue } = | ||
exeContext; | ||
const rootType = schema.getRootType(operation.operation); | ||
@@ -202,3 +197,3 @@ if (rootType == null) { | ||
); | ||
futures.push(...newDeferredGroupedFieldSetRecords); | ||
addFutures(exeContext, newDeferredGroupedFieldSetRecords); | ||
} | ||
@@ -208,46 +203,63 @@ } | ||
return data.then( | ||
(resolved) => | ||
buildDataResponse( | ||
resolved, | ||
errors, | ||
errorPaths, | ||
futures, | ||
cancellableStreams, | ||
), | ||
(error) => buildErrorResponse(error, errors), | ||
(resolved) => buildDataResponse(exeContext, resolved), | ||
(error) => ({ | ||
data: null, | ||
errors: withError(exeContext.errors, error), | ||
}), | ||
); | ||
} | ||
return buildDataResponse( | ||
data, | ||
exeContext.errors, | ||
errorPaths, | ||
futures, | ||
cancellableStreams, | ||
); | ||
return buildDataResponse(exeContext, data); | ||
} catch (error) { | ||
return buildErrorResponse(error, exeContext.errors); | ||
return { data: null, errors: withError(exeContext.errors, error) }; | ||
} | ||
} | ||
function buildDataResponse( | ||
data, | ||
errors, | ||
errorPaths, | ||
futures, | ||
cancellableStreams, | ||
) { | ||
const filteredFutures = filterFutures(undefined, errorPaths, futures); | ||
if (filteredFutures.length > 0) { | ||
function addFutures(context, newFutures) { | ||
const futures = context.futures; | ||
if (futures === undefined) { | ||
context.futures = [...newFutures]; | ||
return; | ||
} | ||
futures.push(...newFutures); | ||
} | ||
function addFuture(context, newFuture) { | ||
const futures = context.futures; | ||
if (futures === undefined) { | ||
context.futures = [newFuture]; | ||
return; | ||
} | ||
futures.push(newFuture); | ||
} | ||
function withError(errors, error) { | ||
return errors === undefined ? [error] : [...errors.values(), error]; | ||
} | ||
function buildDataResponse(exeContext, data) { | ||
const { errors, futures } = exeContext; | ||
if (futures === undefined) { | ||
return buildSingleResult(data, errors); | ||
} | ||
if (errors === undefined) { | ||
return (0, IncrementalPublisher_js_1.buildIncrementalResponse)( | ||
exeContext, | ||
data, | ||
errors, | ||
undefined, | ||
futures, | ||
cancellableStreams, | ||
); | ||
} | ||
return errors.length > 0 ? { errors, data } : { data }; | ||
const filteredFutures = filterFutures(undefined, errors, futures); | ||
if (filteredFutures.length === 0) { | ||
return buildSingleResult(data, errors); | ||
} | ||
return (0, IncrementalPublisher_js_1.buildIncrementalResponse)( | ||
exeContext, | ||
data, | ||
Array.from(errors.values()), | ||
filteredFutures, | ||
); | ||
} | ||
function filterFutures(initialPath, errorPaths, futures) { | ||
if (errorPaths.size === 0) { | ||
return futures; | ||
} | ||
function buildSingleResult(data, errors) { | ||
return errors !== undefined | ||
? { errors: Array.from(errors.values()), data } | ||
: { data }; | ||
} | ||
function filterFutures(initialPath, errors, futures) { | ||
const filteredFutures = []; | ||
@@ -259,3 +271,3 @@ for (const future of futures) { | ||
: future.streamRecord.path; | ||
if (errorPaths.has(currentPath)) { | ||
if (errors.has(currentPath)) { | ||
continue; | ||
@@ -272,3 +284,3 @@ } | ||
currentPath = currentPath.prev; | ||
if (errorPaths.has(currentPath)) { | ||
if (errors.has(currentPath)) { | ||
filtered = true; | ||
@@ -285,6 +297,2 @@ break; | ||
} | ||
function buildErrorResponse(error, errors) { | ||
errors.push(error); | ||
return { data: null, errors }; | ||
} | ||
/** | ||
@@ -385,6 +393,2 @@ * Also implements the "Executing requests" section of the GraphQL specification. | ||
subscribeFieldResolver ?? exports.defaultFieldResolver, | ||
errors: [], | ||
errorPaths: new Set(), | ||
futures: [], | ||
cancellableStreams: new Set(), | ||
}; | ||
@@ -397,3 +401,3 @@ } | ||
rootValue: payload, | ||
errors: [], | ||
errors: undefined, | ||
}; | ||
@@ -683,5 +687,9 @@ } | ||
// a null value for this field if one is encountered. | ||
const { errors, errorPaths } = incrementalContext ?? exeContext; | ||
errors.push(error); | ||
errorPaths.add(path); | ||
const context = incrementalContext ?? exeContext; | ||
let errors = context.errors; | ||
if (errors === undefined) { | ||
errors = new Map(); | ||
context.errors = errors; | ||
} | ||
errors.set(path, error); | ||
} | ||
@@ -851,4 +859,5 @@ /** | ||
/* c8 ignore next 7 */ | ||
if (fieldGroup._streamUsage !== undefined) { | ||
return fieldGroup._streamUsage; | ||
let streamUsage = fieldGroup._streamUsage; | ||
if (streamUsage !== undefined) { | ||
return streamUsage; | ||
} | ||
@@ -884,3 +893,3 @@ // validation only allows equivalent streams on multiple fields, so it is | ||
})); | ||
const streamUsage = { | ||
streamUsage = { | ||
initialCount: stream.initialCount, | ||
@@ -919,2 +928,5 @@ label: typeof stream.label === 'string' ? stream.label : undefined, | ||
}); | ||
if (exeContext.cancellableStreams === undefined) { | ||
exeContext.cancellableStreams = new Set(); | ||
} | ||
exeContext.cancellableStreams.add(streamRecord); | ||
@@ -939,3 +951,4 @@ const firstStreamItems = firstAsyncStreamItems( | ||
); | ||
(incrementalContext ?? exeContext).futures.push(firstStreamItems); | ||
const context = incrementalContext ?? exeContext; | ||
addFuture(context, firstStreamItems); | ||
break; | ||
@@ -1042,3 +1055,4 @@ } | ||
); | ||
(incrementalContext ?? exeContext).futures.push(firstStreamItems); | ||
const context = incrementalContext ?? exeContext; | ||
addFuture(context, firstStreamItems); | ||
break; | ||
@@ -1407,5 +1421,4 @@ } | ||
); | ||
(incrementalContext ?? exeContext).futures.push( | ||
...newDeferredGroupedFieldSetRecords, | ||
); | ||
const context = incrementalContext ?? exeContext; | ||
addFutures(context, newDeferredGroupedFieldSetRecords); | ||
} | ||
@@ -1441,5 +1454,4 @@ return subFields; | ||
); | ||
(incrementalContext ?? exeContext).futures.push( | ||
...newDeferredGroupedFieldSetRecords, | ||
); | ||
const context = incrementalContext ?? exeContext; | ||
addFutures(context, newDeferredGroupedFieldSetRecords); | ||
} | ||
@@ -1762,37 +1774,65 @@ return subFields; | ||
} catch (error) { | ||
incrementalContext.errors.push(error); | ||
return { | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
data: null, | ||
errors: incrementalContext.errors, | ||
result: null, | ||
errors: withError(incrementalContext.errors, error), | ||
}; | ||
} | ||
const { errors, errorPaths, futures } = incrementalContext; | ||
if ((0, isPromise_js_1.isPromise)(data)) { | ||
return data.then( | ||
(resolved) => ({ | ||
(resolved) => | ||
buildDeferredGroupedFieldSetResult( | ||
incrementalContext, | ||
deferredFragmentRecords, | ||
path, | ||
resolved, | ||
), | ||
(error) => ({ | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
data: resolved, | ||
futures: filterFutures(path, errorPaths, futures), | ||
errors, | ||
result: null, | ||
errors: withError(incrementalContext.errors, error), | ||
}), | ||
(error) => { | ||
incrementalContext.errors.push(error); | ||
return { | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
data: null, | ||
errors, | ||
}; | ||
}, | ||
); | ||
} | ||
return buildDeferredGroupedFieldSetResult( | ||
incrementalContext, | ||
deferredFragmentRecords, | ||
path, | ||
data, | ||
); | ||
} | ||
function buildDeferredGroupedFieldSetResult( | ||
incrementalContext, | ||
deferredFragmentRecords, | ||
path, | ||
data, | ||
) { | ||
const { errors, futures } = incrementalContext; | ||
if (futures === undefined) { | ||
return { | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
result: | ||
errors === undefined | ||
? { | ||
data, | ||
} | ||
: { data, errors: [...errors.values()] }, | ||
}; | ||
} | ||
if (errors === undefined) { | ||
return { | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
result: { data }, | ||
futures, | ||
}; | ||
} | ||
return { | ||
deferredFragmentRecords, | ||
path: (0, Path_js_1.pathToArray)(path), | ||
data, | ||
futures: filterFutures(path, errorPaths, futures), | ||
errors, | ||
result: { data, errors: [...errors.values()] }, | ||
futures: filterFutures(path, errors, futures), | ||
}; | ||
@@ -1900,3 +1940,3 @@ } | ||
streamRecord, | ||
items: null, | ||
result: null, | ||
errors: [ | ||
@@ -1966,3 +2006,2 @@ (0, locatedError_js_1.locatedError)( | ||
) { | ||
const { path, errors, errorPaths, futures } = incrementalContext; | ||
if ((0, isPromise_js_1.isPromise)(item)) { | ||
@@ -1979,16 +2018,9 @@ return completePromisedValue( | ||
).then( | ||
(resolvedItem) => ({ | ||
(resolvedItem) => | ||
buildStreamItemsResult(incrementalContext, streamRecord, resolvedItem), | ||
(error) => ({ | ||
streamRecord, | ||
items: [resolvedItem], | ||
futures: filterFutures(path, errorPaths, futures), | ||
errors, | ||
result: null, | ||
errors: withError(incrementalContext.errors, error), | ||
}), | ||
(error) => { | ||
errors.push(error); | ||
return { | ||
streamRecord, | ||
items: null, | ||
errors, | ||
}; | ||
}, | ||
); | ||
@@ -2021,7 +2053,6 @@ } | ||
} catch (error) { | ||
incrementalContext.errors.push(error); | ||
return { | ||
streamRecord, | ||
items: null, | ||
errors, | ||
result: null, | ||
errors: withError(incrementalContext.errors, error), | ||
}; | ||
@@ -2043,24 +2074,55 @@ } | ||
.then( | ||
(resolvedItem) => ({ | ||
(resolvedItem) => | ||
buildStreamItemsResult( | ||
incrementalContext, | ||
streamRecord, | ||
resolvedItem, | ||
), | ||
(error) => ({ | ||
streamRecord, | ||
items: [resolvedItem], | ||
futures: filterFutures(path, errorPaths, futures), | ||
errors, | ||
result: null, | ||
errors: withError(incrementalContext.errors, error), | ||
}), | ||
(error) => { | ||
incrementalContext.errors.push(error); | ||
return { | ||
streamRecord, | ||
items: null, | ||
errors, | ||
}; | ||
}, | ||
); | ||
} | ||
return buildStreamItemsResult( | ||
incrementalContext, | ||
streamRecord, | ||
completedItem, | ||
); | ||
} | ||
function buildStreamItemsResult( | ||
incrementalContext, | ||
streamRecord, | ||
completedItem, | ||
) { | ||
const { errors, futures } = incrementalContext; | ||
if (futures === undefined) { | ||
return { | ||
streamRecord, | ||
result: | ||
errors === undefined | ||
? { items: [completedItem] } | ||
: { | ||
items: [completedItem], | ||
errors: [...errors.values()], | ||
}, | ||
}; | ||
} | ||
if (errors === undefined) { | ||
return { | ||
streamRecord, | ||
result: { items: [completedItem] }, | ||
futures, | ||
}; | ||
} | ||
const path = incrementalContext.path; | ||
return { | ||
streamRecord, | ||
items: [completedItem], | ||
futures: filterFutures(path, errorPaths, futures), | ||
errors, | ||
result: { | ||
items: [completedItem], | ||
errors: [...errors.values()], | ||
}, | ||
futures: filterFutures(path, errors, futures), | ||
}; | ||
} |
@@ -83,8 +83,10 @@ import type { ObjMap } from '../jsutils/ObjMap.js'; | ||
} | ||
interface RawDeferResult<TData = ObjMap<unknown>> { | ||
errors?: ReadonlyArray<GraphQLError>; | ||
data: TData; | ||
} | ||
export interface IncrementalDeferResult< | ||
TData = ObjMap<unknown>, | ||
TExtensions = ObjMap<unknown>, | ||
> { | ||
errors?: ReadonlyArray<GraphQLError>; | ||
data: TData; | ||
> extends RawDeferResult<TData> { | ||
id: string; | ||
@@ -104,8 +106,10 @@ subPath?: ReadonlyArray<string | number>; | ||
} | ||
interface RawStreamItemsResult<TData = ReadonlyArray<unknown>> { | ||
errors?: ReadonlyArray<GraphQLError>; | ||
items: TData; | ||
} | ||
export interface IncrementalStreamResult< | ||
TData = Array<unknown>, | ||
TData = ReadonlyArray<unknown>, | ||
TExtensions = ObjMap<unknown>, | ||
> { | ||
errors?: ReadonlyArray<GraphQLError>; | ||
items: TData; | ||
> extends RawStreamItemsResult<TData> { | ||
id: string; | ||
@@ -149,7 +153,10 @@ subPath?: ReadonlyArray<string | number>; | ||
export declare function buildIncrementalResponse( | ||
context: IncrementalPublisherContext, | ||
result: ObjMap<unknown>, | ||
errors: ReadonlyArray<GraphQLError>, | ||
errors: ReadonlyArray<GraphQLError> | undefined, | ||
futures: ReadonlyArray<Future>, | ||
cancellableStreams: Set<StreamRecord>, | ||
): ExperimentalIncrementalExecutionResults; | ||
interface IncrementalPublisherContext { | ||
cancellableStreams?: Set<StreamRecord> | undefined; | ||
} | ||
export declare function isDeferredFragmentRecord( | ||
@@ -164,24 +171,27 @@ subsequentResultRecord: SubsequentResultRecord, | ||
path: Path | undefined; | ||
errors: Array<GraphQLError>; | ||
errorPaths: Set<Path>; | ||
futures: Array<Future>; | ||
errors?: Map<Path | undefined, GraphQLError> | undefined; | ||
futures?: Array<Future> | undefined; | ||
} | ||
export interface DeferredGroupedFieldSetResult { | ||
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>; | ||
path: Array<string | number>; | ||
data: ObjMap<unknown> | null; | ||
futures?: ReadonlyArray<Future>; | ||
errors: ReadonlyArray<GraphQLError>; | ||
} | ||
export type DeferredGroupedFieldSetResult = | ||
| ReconcilableDeferredGroupedFieldSetResult | ||
| NonReconcilableDeferredGroupedFieldSetResult; | ||
export declare function isDeferredGroupedFieldSetResult( | ||
subsequentResult: DeferredGroupedFieldSetResult | StreamItemsResult, | ||
): subsequentResult is DeferredGroupedFieldSetResult; | ||
interface ReconcilableDeferredGroupedFieldSetResult | ||
extends DeferredGroupedFieldSetResult { | ||
data: ObjMap<unknown>; | ||
interface ReconcilableDeferredGroupedFieldSetResult { | ||
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>; | ||
path: Array<string | number>; | ||
result: RawDeferResult; | ||
futures?: ReadonlyArray<Future> | undefined; | ||
sent?: true | undefined; | ||
} | ||
export declare function isReconcilableDeferredGroupedFieldSetResult( | ||
interface NonReconcilableDeferredGroupedFieldSetResult { | ||
result: null; | ||
errors: ReadonlyArray<GraphQLError>; | ||
deferredFragmentRecords: ReadonlyArray<DeferredFragmentRecord>; | ||
path: Array<string | number>; | ||
} | ||
export declare function isNonReconcilableDeferredGroupedFieldSetResult( | ||
deferredGroupedFieldSetResult: DeferredGroupedFieldSetResult, | ||
): deferredGroupedFieldSetResult is ReconcilableDeferredGroupedFieldSetResult; | ||
): deferredGroupedFieldSetResult is NonReconcilableDeferredGroupedFieldSetResult; | ||
/** @internal */ | ||
@@ -229,11 +239,15 @@ export declare class DeferredGroupedFieldSetRecord { | ||
} | ||
interface NonTerminatingStreamItemsResult { | ||
interface NonReconcilableStreamItemsResult { | ||
streamRecord: StreamRecord; | ||
items: ReadonlyArray<unknown> | null; | ||
futures?: ReadonlyArray<Future>; | ||
result: null; | ||
errors: ReadonlyArray<GraphQLError>; | ||
} | ||
interface NonTerminatingStreamItemsResult { | ||
streamRecord: StreamRecord; | ||
result: RawStreamItemsResult; | ||
futures?: ReadonlyArray<Future> | undefined; | ||
} | ||
interface TerminatingStreamItemsResult { | ||
streamRecord: StreamRecord; | ||
items?: never; | ||
result?: never; | ||
futures?: never; | ||
@@ -243,4 +257,8 @@ errors?: never; | ||
export type StreamItemsResult = | ||
| NonReconcilableStreamItemsResult | ||
| NonTerminatingStreamItemsResult | ||
| TerminatingStreamItemsResult; | ||
export declare function isNonTerminatingStreamItemsResult( | ||
streamItemsResult: StreamItemsResult, | ||
): streamItemsResult is NonTerminatingStreamItemsResult; | ||
/** @internal */ | ||
@@ -247,0 +265,0 @@ export declare class StreamItemsRecord { |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
exports.StreamItemsRecord = | ||
exports.isNonTerminatingStreamItemsResult = | ||
exports.StreamRecord = | ||
exports.DeferredFragmentRecord = | ||
exports.DeferredGroupedFieldSetRecord = | ||
exports.isReconcilableDeferredGroupedFieldSetResult = | ||
exports.isNonReconcilableDeferredGroupedFieldSetResult = | ||
exports.isDeferredGroupedFieldSetResult = | ||
@@ -16,4 +17,4 @@ exports.isDeferredGroupedFieldSetRecord = | ||
const promiseWithResolvers_js_1 = require('../jsutils/promiseWithResolvers.js'); | ||
function buildIncrementalResponse(result, errors, futures, cancellableStreams) { | ||
const incrementalPublisher = new IncrementalPublisher(cancellableStreams); | ||
function buildIncrementalResponse(context, result, errors, futures) { | ||
const incrementalPublisher = new IncrementalPublisher(context); | ||
return incrementalPublisher.buildResponse(result, errors, futures); | ||
@@ -29,4 +30,4 @@ } | ||
class IncrementalPublisher { | ||
constructor(cancellableStreams) { | ||
this._cancellableStreams = cancellableStreams; | ||
constructor(context) { | ||
this._context = context; | ||
this._nextId = 0; | ||
@@ -45,3 +46,3 @@ this._pending = new Set(); | ||
const initialResult = | ||
errors.length === 0 | ||
errors === undefined | ||
? { data, pending, hasNext: true } | ||
@@ -212,4 +213,8 @@ : { errors, data, pending, hasNext: true }; | ||
const returnStreamIterators = async () => { | ||
const cancellableStreams = this._context.cancellableStreams; | ||
if (cancellableStreams === undefined) { | ||
return; | ||
} | ||
const promises = []; | ||
for (const streamRecord of this._cancellableStreams) { | ||
for (const streamRecord of cancellableStreams) { | ||
if (streamRecord.earlyReturn !== undefined) { | ||
@@ -253,8 +258,15 @@ promises.push(streamRecord.earlyReturn()); | ||
} | ||
_handleCompletedDeferredGroupedFieldSet(result) { | ||
if (!isReconcilableDeferredGroupedFieldSetResult(result)) { | ||
for (const deferredFragmentRecord of result.deferredFragmentRecords) { | ||
_handleCompletedDeferredGroupedFieldSet(deferredGroupedFieldSetResult) { | ||
if ( | ||
isNonReconcilableDeferredGroupedFieldSetResult( | ||
deferredGroupedFieldSetResult, | ||
) | ||
) { | ||
for (const deferredFragmentRecord of deferredGroupedFieldSetResult.deferredFragmentRecords) { | ||
const id = deferredFragmentRecord.id; | ||
if (id !== undefined) { | ||
this._completed.push({ id, errors: result.errors }); | ||
this._completed.push({ | ||
id, | ||
errors: deferredGroupedFieldSetResult.errors, | ||
}); | ||
this._pending.delete(deferredFragmentRecord); | ||
@@ -265,9 +277,11 @@ } | ||
} | ||
for (const deferredFragmentRecord of result.deferredFragmentRecords) { | ||
deferredFragmentRecord.reconcilableResults.push(result); | ||
for (const deferredFragmentRecord of deferredGroupedFieldSetResult.deferredFragmentRecords) { | ||
deferredFragmentRecord.reconcilableResults.push( | ||
deferredGroupedFieldSetResult, | ||
); | ||
} | ||
if (result.futures) { | ||
this._addFutures(result.futures); | ||
if (deferredGroupedFieldSetResult.futures) { | ||
this._addFutures(deferredGroupedFieldSetResult.futures); | ||
} | ||
for (const deferredFragmentRecord of result.deferredFragmentRecords) { | ||
for (const deferredFragmentRecord of deferredGroupedFieldSetResult.deferredFragmentRecords) { | ||
const id = deferredFragmentRecord.id; | ||
@@ -299,8 +313,5 @@ // TODO: add test case for this. | ||
const incrementalEntry = { | ||
data: fragmentResult.data, | ||
...fragmentResult.result, | ||
id: bestId, | ||
}; | ||
if (result.errors.length > 0) { | ||
incrementalEntry.errors = fragmentResult.errors; | ||
} | ||
if (subPath !== undefined) { | ||
@@ -324,4 +335,4 @@ incrementalEntry.subPath = subPath; | ||
} | ||
_handleCompletedStreamItems(result) { | ||
const streamRecord = result.streamRecord; | ||
_handleCompletedStreamItems(streamItemsResult) { | ||
const streamRecord = streamItemsResult.streamRecord; | ||
const id = streamRecord.id; | ||
@@ -334,13 +345,19 @@ // TODO: Consider adding invariant or non-null assertion, as this should never happen. Since the stream is converted into a linked list | ||
} | ||
if (result.items === undefined) { | ||
if (streamItemsResult.result === undefined) { | ||
this._completed.push({ id }); | ||
this._pending.delete(streamRecord); | ||
this._cancellableStreams.delete(streamRecord); | ||
} else if (result.items === null) { | ||
const cancellableStreams = this._context.cancellableStreams; | ||
if (cancellableStreams !== undefined) { | ||
cancellableStreams.delete(streamRecord); | ||
} | ||
} else if (streamItemsResult.result === null) { | ||
this._completed.push({ | ||
id, | ||
errors: result.errors, | ||
errors: streamItemsResult.errors, | ||
}); | ||
this._pending.delete(streamRecord); | ||
this._cancellableStreams.delete(streamRecord); | ||
const cancellableStreams = this._context.cancellableStreams; | ||
if (cancellableStreams !== undefined) { | ||
cancellableStreams.delete(streamRecord); | ||
} | ||
streamRecord.earlyReturn?.().catch(() => { | ||
@@ -353,10 +370,7 @@ /* c8 ignore next 1 */ | ||
id, | ||
items: result.items, // FIX! | ||
...streamItemsResult.result, | ||
}; | ||
if (result.errors !== undefined && result.errors.length > 0) { | ||
incrementalEntry.errors = result.errors; | ||
} | ||
this._incremental.push(incrementalEntry); | ||
if (result.futures) { | ||
this._addFutures(result.futures); | ||
if (streamItemsResult.futures) { | ||
this._addFutures(streamItemsResult.futures); | ||
this._pruneEmpty(); | ||
@@ -413,9 +427,9 @@ } | ||
exports.isDeferredGroupedFieldSetResult = isDeferredGroupedFieldSetResult; | ||
function isReconcilableDeferredGroupedFieldSetResult( | ||
function isNonReconcilableDeferredGroupedFieldSetResult( | ||
deferredGroupedFieldSetResult, | ||
) { | ||
return deferredGroupedFieldSetResult.data !== null; | ||
return deferredGroupedFieldSetResult.result === null; | ||
} | ||
exports.isReconcilableDeferredGroupedFieldSetResult = | ||
isReconcilableDeferredGroupedFieldSetResult; | ||
exports.isNonReconcilableDeferredGroupedFieldSetResult = | ||
isNonReconcilableDeferredGroupedFieldSetResult; | ||
/** @internal */ | ||
@@ -430,5 +444,2 @@ class DeferredGroupedFieldSetRecord { | ||
path, | ||
errors: [], | ||
errorPaths: new Set(), | ||
futures: [], | ||
}; | ||
@@ -469,2 +480,6 @@ for (const deferredFragmentRecord of deferredFragmentRecords) { | ||
exports.StreamRecord = StreamRecord; | ||
function isNonTerminatingStreamItemsResult(streamItemsResult) { | ||
return streamItemsResult.result != null; | ||
} | ||
exports.isNonTerminatingStreamItemsResult = isNonTerminatingStreamItemsResult; | ||
/** @internal */ | ||
@@ -478,5 +493,2 @@ class StreamItemsRecord { | ||
path: itemPath, | ||
errors: [], | ||
errorPaths: new Set(), | ||
futures: [], | ||
}; | ||
@@ -494,10 +506,11 @@ this._result = executor(incrementalContext); | ||
_prependNextStreamItems(result) { | ||
return this.nextStreamItems === undefined | ||
? result | ||
: { | ||
return isNonTerminatingStreamItemsResult(result) && | ||
this.nextStreamItems !== undefined | ||
? { | ||
...result, | ||
futures: [this.nextStreamItems, ...(result.futures ?? [])], | ||
}; | ||
} | ||
: result; | ||
} | ||
} | ||
exports.StreamItemsRecord = StreamItemsRecord; |
{ | ||
"name": "graphql", | ||
"version": "17.0.0-alpha.3.canary.pr.4026.5e657d31b3abdc38acd6bb21c50ed3a41aa33905", | ||
"version": "17.0.0-alpha.3.canary.pr.4026.74aa85f56dea9ab9feb4445165eb0e2347ea674f", | ||
"description": "A Query Language and Runtime which can target any service.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1433974
44450
412