diff --git a/utils/graphile-config/src/middleware.ts b/utils/graphile-config/src/middleware.ts index 15f2af5600..f0128d1f1c 100644 --- a/utils/graphile-config/src/middleware.ts +++ b/utils/graphile-config/src/middleware.ts @@ -11,11 +11,7 @@ export interface MiddlewareNext< > { (): TRawResult; callback( - callback: ( - params: - | { error: object; result?: never } - | { error?: undefined; result: TAwaitedResult }, - ) => TRawResult, + callback: (error: object | null, result: TAwaitedResult) => TRawResult, ): TRawResult; } @@ -163,15 +159,18 @@ function makeNext>( try { result = fn() as PromiseOrDirect; } catch (error) { - return callback({ error }); + return callback(error, undefined as any); } if (isPromiseLike(result)) { return result.then( - (result) => callback({ result }), - (error) => callback({ error }), + (result) => + callback(null, result) as + | TAwaitedResult + | PromiseLike, + callback as any, ) as TRawResult; } else { - return callback({ result }); + return callback(null, result); } }; return next;