Skip to content

Commit

Permalink
feat: allow to pass custom findManyResolver & countResolver as co…
Browse files Browse the repository at this point in the history
…nfig params to `connection` & `pagination` resolvers

relates #288
  • Loading branch information
nodkz committed Jul 21, 2021
1 parent e4b916b commit 1b13d4e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/resolvers/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export type ConnectionResolverOpts<TContext = any> = Omit<
_ConnectionResolverOpts<TContext>,
'countResolver' | 'findManyResolver' | 'sort'
> & {
findManyResolver?: Resolver;
countResolver?: Resolver;
countOpts?: CountResolverOpts;
findManyOpts?: FindManyResolverOpts;
sort?: _ConnectionSortMapOpts;
Expand Down Expand Up @@ -60,11 +62,11 @@ export function connection<TSource = any, TContext = any, TDoc extends Document
};
});

const { findManyOpts, countOpts, ...restOpts } = opts || {};
const { findManyOpts, countOpts, findManyResolver, countResolver, ...restOpts } = opts || {};

return prepareConnectionResolver<any, any>(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,
});
Expand Down
8 changes: 5 additions & 3 deletions src/resolvers/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export type PaginationResolverOpts = Omit<
_PaginationResolverOpts,
'countResolver' | 'findManyResolver'
> & {
findManyResolver?: Resolver;
countResolver?: Resolver;
countOpts?: CountResolverOpts;
findManyOpts?: FindManyResolverOpts;
};
Expand All @@ -21,10 +23,10 @@ export function pagination<TSource = any, TContext = any, TDoc extends Document
tc: ObjectTypeComposer<TDoc, TContext> | InterfaceTypeComposer<TDoc, TContext>,
opts?: PaginationResolverOpts
): Resolver<TSource, TContext, PaginationTArgs, TDoc> {
const { countOpts, findManyOpts, ...restOpts } = opts || {};
const { countOpts, findManyOpts, findManyResolver, countResolver, ...restOpts } = opts || {};
const resolver = preparePaginationResolver<any, any>(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;
Expand Down

0 comments on commit 1b13d4e

Please sign in to comment.