Skip to content

Commit 5c12269

Browse files
committed
re-introduction of simple errorPath based filtering
removes the need for entire GraphQLResult class and host of helper functions, presumably improving performance in both the non-incremental and incremental cases this filtering can probably be further improved, as we do not have to check for errors in the path tree higher than the current incremental context's path, if we chose to save that information.
1 parent d156b24 commit 5c12269

File tree

5 files changed

+165
-256
lines changed

5 files changed

+165
-256
lines changed

src/execution/IncrementalPublisher.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ export interface FormattedCompletedResult {
166166
}
167167

168168
export function buildIncrementalResponse(
169-
result: GraphQLResult<ObjMap<unknown>>,
169+
result: ObjMap<unknown>,
170170
errors: ReadonlyArray<GraphQLError>,
171+
futures: ReadonlyArray<Future>,
171172
cancellableStreams: Set<StreamRecord>,
172173
): ExperimentalIncrementalExecutionResults {
173174
const incrementalPublisher = new IncrementalPublisher(cancellableStreams);
174-
return incrementalPublisher.buildResponse(result, errors);
175+
return incrementalPublisher.buildResponse(result, errors, futures);
175176
}
176177

177178
/**
@@ -204,11 +205,10 @@ class IncrementalPublisher {
204205
}
205206

206207
buildResponse(
207-
result: GraphQLResult<ObjMap<unknown>>,
208+
data: ObjMap<unknown>,
208209
errors: ReadonlyArray<GraphQLError>,
210+
futures: ReadonlyArray<Future>,
209211
): ExperimentalIncrementalExecutionResults {
210-
const { result: data, futures } = result;
211-
212212
this._addFutures(futures);
213213
this._pruneEmpty();
214214

@@ -636,20 +636,11 @@ export function isDeferredGroupedFieldSetRecord(
636636
return future instanceof DeferredGroupedFieldSetRecord;
637637
}
638638

639-
/** @internal **/
640-
export class GraphQLResult<T> {
641-
result: T;
642-
futures: ReadonlyArray<Future> = [];
643-
644-
constructor(result: T, futures: ReadonlyArray<Future>) {
645-
this.result = result;
646-
this.futures = futures;
647-
}
648-
}
649-
650639
export interface IncrementalContext {
651640
deferUsageSet: DeferUsageSet | undefined;
652641
errors: Array<GraphQLError>;
642+
errorPaths: Set<Path>;
643+
futures: Array<Future>;
653644
}
654645

655646
export interface DeferredGroupedFieldSetResult {
@@ -699,6 +690,8 @@ export class DeferredGroupedFieldSetRecord {
699690
const incrementalContext: IncrementalContext = {
700691
deferUsageSet,
701692
errors: [],
693+
errorPaths: new Set(),
694+
futures: [],
702695
};
703696

704697
for (const deferredFragmentRecord of this.deferredFragmentRecords) {
@@ -793,6 +786,8 @@ export class StreamItemsRecord {
793786
const incrementalContext: IncrementalContext = {
794787
deferUsageSet: undefined,
795788
errors: [],
789+
errorPaths: new Set(),
790+
futures: [],
796791
};
797792

798793
this._result = executor(incrementalContext);

src/execution/__tests__/defer-test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1116,23 +1116,23 @@ describe('Execute: defer directive', () => {
11161116
},
11171117
},
11181118
pending: [
1119-
{ id: '0', path: [] },
1120-
{ id: '1', path: ['a', 'b'] },
1119+
{ id: '0', path: ['a', 'b'] },
1120+
{ id: '1', path: [] },
11211121
],
11221122
hasNext: true,
11231123
},
11241124
{
11251125
incremental: [
11261126
{
11271127
data: { e: { f: 'f' } },
1128-
id: '1',
1128+
id: '0',
11291129
},
11301130
{
11311131
data: { g: { h: 'h' } },
1132-
id: '0',
1132+
id: '1',
11331133
},
11341134
],
1135-
completed: [{ id: '1' }, { id: '0' }],
1135+
completed: [{ id: '0' }, { id: '1' }],
11361136
hasNext: false,
11371137
},
11381138
]);

src/execution/__tests__/stream-test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -2096,14 +2096,23 @@ describe('Execute: stream directive', () => {
20962096
id: '2',
20972097
},
20982098
],
2099-
completed: [{ id: '2' }, { id: '1' }],
2100-
hasNext: false,
2099+
completed: [{ id: '2' }],
2100+
hasNext: true,
21012101
},
21022102
done: false,
21032103
});
21042104

21052105
const result5 = await iterator.next();
21062106
expectJSON(result5).toDeepEqual({
2107+
value: {
2108+
completed: [{ id: '1' }],
2109+
hasNext: false,
2110+
},
2111+
done: false,
2112+
});
2113+
2114+
const result6 = await iterator.next();
2115+
expectJSON(result6).toDeepEqual({
21072116
value: undefined,
21082117
done: true,
21092118
});

0 commit comments

Comments
 (0)