Skip to content

Commit

Permalink
incremental: add id
Browse files Browse the repository at this point in the history
TODO: use `id` to shorten `path` to `id` + `subPath`
  • Loading branch information
yaacovCR committed Aug 25, 2023
1 parent fe65bc8 commit 8a66084
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 242 deletions.
20 changes: 14 additions & 6 deletions src/execution/IncrementalPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ export type FormattedIncrementalResult<
| FormattedIncrementalStreamResult<TData, TExtensions>;

export interface PendingResult {
id: string;
path: ReadonlyArray<string | number>;
label?: string;
}

export interface CompletedResult {
path: ReadonlyArray<string | number>;
label?: string;
id: string;
errors?: ReadonlyArray<GraphQLError>;
}

Expand All @@ -178,6 +178,7 @@ export interface FormattedCompletedResult {
* @internal
*/
export class IncrementalPublisher {
private _nextId = 0;
private _released: Set<SubsequentResultRecord>;
private _pending: Set<SubsequentResultRecord>;

Expand Down Expand Up @@ -372,7 +373,10 @@ export class IncrementalPublisher {
const pendingResults: Array<PendingResult> = [];
for (const pendingSource of pendingSources) {
pendingSource.pendingSent = true;
const id = this._getNextId();
pendingSource.id = id;
const pendingResult: PendingResult = {
id,
path: pendingSource.path,
};
if (pendingSource.label !== undefined) {
Expand All @@ -383,6 +387,10 @@ export class IncrementalPublisher {
return pendingResults;
}

private _getNextId(): string {
return String(this._nextId++);
}

private _subscribe(): AsyncGenerator<
SubsequentIncrementalExecutionResult,
void,
Expand Down Expand Up @@ -596,11 +604,9 @@ export class IncrementalPublisher {
completedRecord: DeferredFragmentRecord | StreamRecord,
): CompletedResult {
const result: CompletedResult = {
path: completedRecord.path,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: completedRecord.id!,
};
if (completedRecord.label !== undefined) {
result.label = completedRecord.label;
}
if (completedRecord.errors.length > 0) {
result.errors = completedRecord.errors;
}
Expand Down Expand Up @@ -736,6 +742,7 @@ export class DeferredGroupedFieldSetRecord {
export class DeferredFragmentRecord {
path: ReadonlyArray<string | number>;
label: string | undefined;
id: string | undefined;
children: Set<SubsequentResultRecord>;
deferredGroupedFieldSetRecords: Set<DeferredGroupedFieldSetRecord>;
errors: Array<GraphQLError>;
Expand All @@ -758,6 +765,7 @@ export class DeferredFragmentRecord {
export class StreamRecord {
label: string | undefined;
path: ReadonlyArray<string | number>;
id: string | undefined;
errors: Array<GraphQLError>;
earlyReturn?: (() => Promise<unknown>) | undefined;
pendingSent?: boolean;
Expand Down
Loading

0 comments on commit 8a66084

Please sign in to comment.