Skip to content

Commit 1004c20

Browse files
committed
feat(ConnectionResolver): Migrated to new major version of graphql-compose-connection@2.0.0
1 parent 37d178c commit 1004c20

File tree

2 files changed

+21
-24
lines changed

2 files changed

+21
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"peerDependencies": {
3131
"graphql": ">=0.7.1 || >=0.8.0",
3232
"graphql-compose": ">=1.0.0",
33-
"graphql-compose-connection": ">=1.0.0",
33+
"graphql-compose-connection": ">=2.0.0",
3434
"mongoose": ">=4.0.0"
3535
},
3636
"devDependencies": {

src/composeWithMongoose.js

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { TypeComposer, InputTypeComposer } from 'graphql-compose';
55
import composeWithConnection from 'graphql-compose-connection';
66
import { convertModelToGraphQL } from './fieldsConverter';
77
import * as resolvers from './resolvers';
8-
import { OPERATORS_FIELDNAME } from './resolvers/helpers/filter';
98

109
import type {
1110
MongooseModelT,
@@ -139,37 +138,35 @@ export function prepareConnectionResolver(
139138
countResolverName: 'count',
140139
sort: {
141140
_ID_DESC: {
142-
uniqueFields: ['_id'],
143-
sortValue: { _id: -1 },
144-
directionFilter: (filter, cursorData, isBefore) => {
141+
value: { _id: -1 },
142+
cursorFields: ['_id'],
143+
beforeCursorQuery: (rawQuery, cursorData) => {
145144
// $FlowFixMe
146-
filter[OPERATORS_FIELDNAME] = filter[OPERATORS_FIELDNAME] || {};
145+
if (!rawQuery._id) rawQuery._id = {};
147146
// $FlowFixMe
148-
filter[OPERATORS_FIELDNAME]._id = filter[OPERATORS_FIELDNAME]._id || {};
149-
if (isBefore) {
150-
filter[OPERATORS_FIELDNAME]._id.gt = cursorData._id;
151-
} else {
152-
filter[OPERATORS_FIELDNAME]._id.lt = cursorData._id;
153-
}
147+
rawQuery._id.$gt = cursorData._id;
148+
},
149+
afterCursorQuery: (rawQuery, cursorData) => {
150+
// $FlowFixMe
151+
if (!rawQuery._id) rawQuery._id = {};
154152
// $FlowFixMe
155-
return filter;
153+
rawQuery._id.$lt = cursorData._id;
156154
},
157155
},
158156
_ID_ASC: {
159-
uniqueFields: ['_id'],
160-
sortValue: { _id: 1 },
161-
directionFilter: (filter, cursorData, isBefore) => {
157+
value: { _id: 1 },
158+
cursorFields: ['_id'],
159+
beforeCursorQuery: (rawQuery, cursorData) => {
162160
// $FlowFixMe
163-
filter[OPERATORS_FIELDNAME] = filter[OPERATORS_FIELDNAME] || {};
161+
if (!rawQuery._id) rawQuery._id = {};
162+
// $FlowFixMe
163+
rawQuery._id.$gt = cursorData._id;
164+
},
165+
afterCursorQuery: (rawQuery, cursorData) => {
164166
// $FlowFixMe
165-
filter[OPERATORS_FIELDNAME]._id = filter[OPERATORS_FIELDNAME]._id || {};
166-
if (isBefore) {
167-
filter[OPERATORS_FIELDNAME]._id.lt = cursorData._id;
168-
} else {
169-
filter[OPERATORS_FIELDNAME]._id.gt = cursorData._id;
170-
}
167+
if (!rawQuery._id) rawQuery._id = {};
171168
// $FlowFixMe
172-
return filter;
169+
rawQuery._id.$lt = cursorData._id;
173170
},
174171
},
175172
...opts,

0 commit comments

Comments
 (0)