Skip to content

Commit 30f40ee

Browse files
committed
feat(updateMany, removeMany): Add resolveParams to beforeQuery. This is experemental feature, caus
1 parent 40a53f0 commit 30f40ee

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/resolvers/removeById.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from 'graphql';
88
import { Resolver, TypeComposer } from 'graphql-compose';
99
import findById from './findById';
10-
import { projectionHelper } from './helpers/projection';
1110
import GraphQLMongoID from '../types/mongoid';
1211
import typeStorage from '../typeStorage';
1312
import type {
@@ -82,7 +81,7 @@ export default function removeById(
8281
// So empty projection returns all fields.
8382
resolveParams.projection = {};
8483

85-
// FlowFixMe
84+
// $FlowFixMe
8685
return findByIdResolver.resolve(resolveParams)
8786
.then((doc) => {
8887
// $FlowFixMe

src/resolvers/removeMany.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default function removeMany(
5959
...(opts && opts.filter),
6060
}),
6161
},
62+
// $FlowFixMe
6263
resolve: (resolveParams: ExtendedResolveParams) => {
6364
const filterData = (resolveParams.args && resolveParams.args.filter) || {};
6465

@@ -72,15 +73,20 @@ export default function removeMany(
7273
}
7374

7475
resolveParams.query = model.find();
76+
// $FlowFixMe
7577
filterHelper(resolveParams);
7678
resolveParams.query = resolveParams.query.remove();
7779

7880
return (
81+
// `beforeQuery` is experemental feature, if you want to use it
82+
// please open an issue with your use case, cause I suppose that
83+
// this option is excessive
84+
// $FlowFixMe
7985
resolveParams.beforeQuery
80-
? Promise.resolve(resolveParams.beforeQuery(resolveParams.query))
86+
? Promise.resolve(resolveParams.beforeQuery(resolveParams.query, resolveParams))
8187
: resolveParams.query.exec()
8288
)
83-
.then(res => {
89+
.then((res) => {
8490
if (res.result && res.result.ok) {
8591
return {
8692
numAffected: res.result.n,

src/resolvers/updateMany.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export default function updateMany(
7575
...(opts && opts.limit),
7676
}),
7777
},
78+
// $FlowFixMe
7879
resolve: (resolveParams: ExtendedResolveParams) => {
7980
const recordData = (resolveParams.args && resolveParams.args.record) || {};
8081

@@ -88,17 +89,25 @@ export default function updateMany(
8889
}
8990

9091
resolveParams.query = model.find();
92+
// $FlowFixMe
9193
filterHelper(resolveParams);
94+
// $FlowFixMe
9295
skipHelper(resolveParams);
96+
// $FlowFixMe
9397
sortHelper(resolveParams);
98+
// $FlowFixMe
9499
limitHelper(resolveParams);
95100

96101
resolveParams.query = resolveParams.query.setOptions({ multi: true }); // eslint-disable-line
97102
resolveParams.query.update({ $set: toDottedObject(recordData) });
98103

99104
return (
105+
// `beforeQuery` is experemental feature, if you want to use it
106+
// please open an issue with your use case, cause I suppose that
107+
// this option is excessive
108+
// $FlowFixMe
100109
resolveParams.beforeQuery
101-
? Promise.resolve(resolveParams.beforeQuery(resolveParams.query))
110+
? Promise.resolve(resolveParams.beforeQuery(resolveParams.query, resolveParams))
102111
: resolveParams.query.exec()
103112
)
104113
.then((res) => {

0 commit comments

Comments
 (0)