diff --git a/packages/schema/src/hooks/resolve.ts b/packages/schema/src/hooks/resolve.ts index 83558fc1ce..8c36b5778a 100644 --- a/packages/schema/src/hooks/resolve.ts +++ b/packages/schema/src/hooks/resolve.ts @@ -53,6 +53,9 @@ export type ResolveAllSettings = { export const DISPATCH = Symbol('@feathersjs/schema/dispatch') +export const getDispatch = (value: any) => + typeof value === 'object' && value !== null && value[DISPATCH] !== undefined ? value[DISPATCH] : value + export const resolveQuery = (...resolvers: Resolver[]) => async (context: H, next?: NextFunction) => { @@ -139,20 +142,19 @@ export const resolveDispatch = const ctx = getContext(context) const status = context.params.resolve const { isPaginated, data } = getData(context) - const resolveDispatch = async (current: any) => { + const resolveAndGetDispatch = async (current: any) => { const resolved = await runResolvers(resolvers, current, ctx, status) return Object.keys(resolved).reduce((res, key) => { - const value = current[key] - const hasDispatch = typeof value === 'object' && value !== null && value[DISPATCH] !== undefined - - res[key] = hasDispatch ? value[DISPATCH] : value + res[key] = getDispatch(current[key]) return res }, {} as any) } - const result = await (Array.isArray(data) ? Promise.all(data.map(resolveDispatch)) : resolveDispatch(data)) + const result = await (Array.isArray(data) + ? Promise.all(data.map(resolveAndGetDispatch)) + : resolveAndGetDispatch(data)) const dispatch = isPaginated ? { ...context.result,