Skip to content

Commit 5c3a9ee

Browse files
authored
Cleanup type casting as usages in the code (#803)
1 parent db92b55 commit 5c3a9ee

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

bench/federation/federation.bench.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('Federation', async () => {
109109
(response) => {
110110
expect(response).toEqual(result);
111111
},
112-
) as Promise<void>;
112+
);
113113
},
114114
{
115115
async setup() {
@@ -152,7 +152,7 @@ describe('Federation', async () => {
152152
(response) => {
153153
expect(response).toEqual(result);
154154
},
155-
) as Promise<void>,
155+
),
156156
{
157157
setup() {
158158
stitchedSchema = getStitchedSchemaFromSupergraphSdl({

packages/delegate/src/defaultMergedResolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ function parentSatisfiedSelectionSet(
479479

480480
function flattenPromise<T>(data: T): Promise<T> | T {
481481
if (isPromise(data)) {
482-
return data.then(flattenPromise) as Promise<T>;
482+
return data.then(flattenPromise);
483483
}
484484
if (Array.isArray(data)) {
485485
return Promise.all(data.map(flattenPromise)) as Promise<T>;
@@ -509,9 +509,9 @@ function flattenPromise<T>(data: T): Promise<T> | T {
509509
newData[UNPATHED_ERRORS_SYMBOL] = data[UNPATHED_ERRORS_SYMBOL];
510510
}
511511
if (jobs.length) {
512-
return Promise.all(jobs).then(() => newData) as Promise<T>;
512+
return Promise.all(jobs).then(() => newData);
513513
}
514-
return newData as T;
514+
return newData;
515515
}
516516
return data;
517517
}

packages/runtime/src/createGatewayRuntime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ export function createGatewayRuntime<
379379
document: parse(`query ReadinessCheck { __typename }`),
380380
}),
381381
(res) => !isAsyncIterable(res) && !!res.data?.__typename,
382-
) as MaybePromise<boolean>;
382+
);
383383
schemaInvalidator = () => {
384384
// @ts-expect-error TODO: this is illegal but somehow we want it
385385
unifiedGraph = undefined;

packages/runtime/src/plugins/useUpstreamRetry.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ export function useUpstreamRetry<TContext extends Record<string, any>>(
106106
const requestTime = Date.now();
107107
attemptsLeft--;
108108
return handleMaybePromise(
109-
() =>
110-
executor(
111-
executionRequest,
112-
) as MaybeAsyncIterable<ExecutionResult>,
109+
() => executor(executionRequest),
113110
(currRes) => {
114111
executionResult = currRes;
115112
let retryAfterSecondsFromHeader: number | undefined;

packages/runtime/src/plugins/useUpstreamTimeout.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
ExecutionRequest,
88
ExecutionResult,
99
isAsyncIterable,
10-
MaybeAsyncIterable,
11-
MaybePromise,
10+
isPromise,
1211
registerAbortSignalListener,
1312
} from '@graphql-tools/utils';
1413
import { GatewayPlugin } from '../types';
@@ -55,17 +54,24 @@ export function useUpstreamTimeout<TContext extends Record<string, any>>(
5554
timeoutSignal,
5655
);
5756
}
58-
const timeoutDeferred = createDeferred<void>();
57+
const signals: AbortSignal[] = [];
58+
signals.push(timeoutSignal);
59+
if (executionRequest.signal) {
60+
signals.push(executionRequest.signal);
61+
}
62+
const timeoutDeferred = createDeferred<ExecutionResult>();
5963
function rejectDeferred() {
6064
timeoutDeferred.reject(timeoutSignal?.reason);
6165
}
6266
timeoutSignal.addEventListener('abort', rejectDeferred, {
6367
once: true,
6468
});
65-
const signals: AbortSignal[] = [];
66-
signals.push(timeoutSignal);
67-
if (executionRequest.signal) {
68-
signals.push(executionRequest.signal);
69+
const res$ = executor({
70+
...executionRequest,
71+
signal: AbortSignal.any(signals),
72+
});
73+
if (!isPromise(res$)) {
74+
return res$;
6975
}
7076
return Promise.race([
7177
timeoutDeferred.promise,
@@ -102,12 +108,12 @@ export function useUpstreamTimeout<TContext extends Record<string, any>>(
102108
throw e;
103109
})
104110
.finally(() => {
105-
timeoutDeferred.resolve();
111+
timeoutDeferred.resolve(undefined as any);
106112
timeoutSignal.removeEventListener('abort', rejectDeferred);
107113
// Remove from the map after used so we don't see it again
108114
errorExtensionsByExecRequest.delete(executionRequest);
109115
timeoutSignalsByExecutionRequest.delete(executionRequest);
110-
}) as MaybePromise<MaybeAsyncIterable<ExecutionResult>>;
116+
});
111117
});
112118
}
113119
return undefined;

0 commit comments

Comments
 (0)