graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
708 stars 94 forks source link

`sort` param should be optional on `connection` resolver factory opts #337

Closed yoadsn closed 3 years ago

yoadsn commented 3 years ago

I might read it wrong, but when using the connection resolver factory and specifying opts for findMany (for example) the sort prop is also required. But in fact the factory knows to generate it from the indexes of the model. Can we make this optional in this type def? https://github.com/graphql-compose/graphql-compose-mongoose/blob/e32b4412a5e5b983a278738504a257a8b0335939/src/resolvers/connection.ts#L12

I can create a PR if this is indeed something to fix. Maybe something like this?

--- a/src/resolvers/connection.ts
+++ b/src/resolvers/connection.ts
@@ -2,6 +2,7 @@ import type { Document, Model } from 'mongoose';
 import {
   prepareConnectionResolver,
   ConnectionResolverOpts as _ConnectionResolverOpts,
+  ConnectionSortMapOpts as _ConnectionSortMapOpts,
   ConnectionTArgs,
 } from 'graphql-compose-connection';
 import type { Resolver, ObjectTypeComposer } from 'graphql-compose';
@@ -11,10 +12,11 @@ import { getUniqueIndexes, extendByReversedIndexes, IndexT } from '../utils/getI

 export type ConnectionResolverOpts<TContext = any> = Omit<
   _ConnectionResolverOpts<TContext>,
-  'countResolver' | 'findManyResolver'
+  'countResolver' | 'findManyResolver' | 'sort'
 > & {
   countOpts?: CountResolverOpts;
   findManyOpts?: FindManyResolverOpts;
+  sort?: _ConnectionSortMapOpts;
 };
nodkz commented 3 years ago

If you want to add this option to typedef for overriding internal behavior then I don't see any problems. Feel free to open PR but it's required to add some jsdoc explanation to it ;)

yoadsn commented 3 years ago

@nodkz Thanks! please see PR - I found some tests that needed fixing since the last refactors to this factory.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 9.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: