From 1b13d4ef873c8da34a24b8da1a4af037e5bdc3e1 Mon Sep 17 00:00:00 2001 From: nodkz Date: Wed, 21 Jul 2021 22:34:40 +0600 Subject: [PATCH] feat: allow to pass custom `findManyResolver` & `countResolver` as config params to `connection` & `pagination` resolvers relates #288 --- src/resolvers/connection.ts | 8 +++++--- src/resolvers/pagination.ts | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/resolvers/connection.ts b/src/resolvers/connection.ts index 72d2d982..8191c2da 100644 --- a/src/resolvers/connection.ts +++ b/src/resolvers/connection.ts @@ -23,6 +23,8 @@ export type ConnectionResolverOpts = Omit< _ConnectionResolverOpts, 'countResolver' | 'findManyResolver' | 'sort' > & { + findManyResolver?: Resolver; + countResolver?: Resolver; countOpts?: CountResolverOpts; findManyOpts?: FindManyResolverOpts; sort?: _ConnectionSortMapOpts; @@ -60,11 +62,11 @@ export function connection(tc, { - findManyResolver: findMany(model, tc, findManyOpts), - countResolver: count(model, tc, countOpts), + findManyResolver: findManyResolver || findMany(model, tc, findManyOpts), + countResolver: countResolver || count(model, tc, countOpts), sort: sortConfigs, ...restOpts, }); diff --git a/src/resolvers/pagination.ts b/src/resolvers/pagination.ts index 248ebe88..a72fad88 100644 --- a/src/resolvers/pagination.ts +++ b/src/resolvers/pagination.ts @@ -12,6 +12,8 @@ export type PaginationResolverOpts = Omit< _PaginationResolverOpts, 'countResolver' | 'findManyResolver' > & { + findManyResolver?: Resolver; + countResolver?: Resolver; countOpts?: CountResolverOpts; findManyOpts?: FindManyResolverOpts; }; @@ -21,10 +23,10 @@ export function pagination | InterfaceTypeComposer, opts?: PaginationResolverOpts ): Resolver { - const { countOpts, findManyOpts, ...restOpts } = opts || {}; + const { countOpts, findManyOpts, findManyResolver, countResolver, ...restOpts } = opts || {}; const resolver = preparePaginationResolver(tc, { - findManyResolver: findMany(model, tc, findManyOpts), - countResolver: count(model, tc, countOpts), + findManyResolver: findManyResolver || findMany(model, tc, findManyOpts), + countResolver: countResolver || count(model, tc, countOpts), ...restOpts, }); return resolver;