( queryFn: T, params: TInput, ctx?: Ctx, loggingOptions?: RpcLoggerOptions, )
| 3 | import {RpcLoggerOptions} from "./plugin" |
| 4 | |
| 5 | export async function invoke<T extends (...args: any) => any, TInput = FirstParam<T>>( |
| 6 | queryFn: T, |
| 7 | params: TInput, |
| 8 | ctx?: Ctx, |
| 9 | loggingOptions?: RpcLoggerOptions, |
| 10 | ): Promise<PromiseReturnType<T>> { |
| 11 | if (typeof queryFn === "undefined") { |
| 12 | throw new Error( |
| 13 | "invoke is missing the first argument - it must be a query or mutation function", |
| 14 | ) |
| 15 | } |
| 16 | const rpcLogger = new RpcLogger((queryFn as any)._resolverName, loggingOptions, "blitz-invoke") |
| 17 | rpcLogger.timer.initResolver() |
| 18 | rpcLogger.preResolver(params) |
| 19 | |
| 20 | const result = await queryFn(params, ctx) |
| 21 | rpcLogger.postResolver(result) |
| 22 | |
| 23 | rpcLogger.timer.resolverDuration().totalDuration() |
| 24 | rpcLogger.postResponse() |
| 25 | return result |
| 26 | } |
no test coverage detected