11/* @flow */
2- /* eslint-disable no-use-before-define */
2+ /* eslint-disable no-use-before-define, no-param-reassign */
33
44import { convertModelToGraphQL } from './fieldsConverter' ;
55import { TypeComposer , InputTypeComposer } from 'graphql-compose' ;
@@ -12,6 +12,7 @@ import type {
1212 typeConverterOpts ,
1313 typeConverterResolversOpts ,
1414 typeConverterInputTypeOpts ,
15+ connectionSortMapOpts ,
1516} from './definition' ;
1617
1718
@@ -124,20 +125,23 @@ export function createResolvers(
124125 }
125126 } ) ;
126127
127- if ( ! opts . hasOwnProperty ( 'connection' ) || opts [ ' connection' ] !== false ) {
128- prepareConnectionResolver ( typeComposer , opts [ ' connection' ] ) ;
128+ if ( ! opts . hasOwnProperty ( 'connection' ) || opts . connection !== false ) {
129+ prepareConnectionResolver ( typeComposer , opts . connection ) ;
129130 }
130131}
131132
132- export function prepareConnectionResolver ( typeComposer : TypeComposer , opts ) {
133+ export function prepareConnectionResolver (
134+ typeComposer : TypeComposer ,
135+ opts : connectionSortMapOpts
136+ ) {
133137 composeWithConnection ( typeComposer , {
134138 findResolverName : 'findMany' ,
135139 countResolverName : 'count' ,
136140 sort : {
137141 _ID_DESC : {
138142 uniqueFields : [ '_id' ] ,
139143 sortValue : { _id : - 1 } ,
140- directionFilter : ( cursorData , filter , isBefore ) => {
144+ directionFilter : ( filter , cursorData , isBefore ) => {
141145 filter [ OPERATORS_FIELDNAME ] = filter [ OPERATORS_FIELDNAME ] || { } ;
142146 filter [ OPERATORS_FIELDNAME ] . _id = filter [ OPERATORS_FIELDNAME ] . _id || { } ;
143147 if ( isBefore ) {
@@ -151,7 +155,7 @@ export function prepareConnectionResolver(typeComposer: TypeComposer, opts) {
151155 _ID_ASC : {
152156 uniqueFields : [ '_id' ] ,
153157 sortValue : { _id : 1 } ,
154- directionFilter : ( cursorData , filter , isBefore ) => {
158+ directionFilter : ( filter , cursorData , isBefore ) => {
155159 filter [ OPERATORS_FIELDNAME ] = filter [ OPERATORS_FIELDNAME ] || { } ;
156160 filter [ OPERATORS_FIELDNAME ] . _id = filter [ OPERATORS_FIELDNAME ] . _id || { } ;
157161 if ( isBefore ) {
@@ -161,7 +165,8 @@ export function prepareConnectionResolver(typeComposer: TypeComposer, opts) {
161165 }
162166 return filter ;
163167 } ,
164- }
168+ } ,
169+ ...opts ,
165170 } ,
166- } )
171+ } ) ;
167172}
0 commit comments