Skip to content

Commit 47946d3

Browse files
sabrogdenyoavkarako
authored and
yoavkarako
committed
Added support for $all mongo query (#49)
1 parent 7740c8b commit 47946d3

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/graphQLFilterType.ts

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const GetOprType = () => cache(typesCache, "Opr", () => new GraphQLEnumType({
1212
GT: { value: "$gt" },
1313
GTE: { value: "$gte" },
1414
IN: { value: "$in" },
15+
ALL: { value: "$all" },
1516
LT: { value: "$lt" },
1617
LTE: { value: "$lte" },
1718
NE: { value: "$ne" },
@@ -101,6 +102,7 @@ function getGraphQLScalarFilterTypeFields(scalarType: GraphQLLeafType, not: bool
101102
GT: { type: scalarType, description: '$gt' },
102103
GTE: { type: scalarType, description: '$gte' },
103104
IN: { type: new GraphQLList(scalarType), description: '$in' },
105+
ALL: { type: new GraphQLList(scalarType), description: '$all' },
104106
LT: { type: scalarType, description: '$lt' },
105107
LTE: { type: scalarType, description: '$lte' },
106108
NE: { type: scalarType, description: '$ne' },

src/mongoDbFilter.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { isType, GraphQLObjectType, isLeafType, GraphQLLeafType } from 'graphql'
22
import { getTypeFields, getInnerType, isListField, addPrefixToProperties, GraphQLFieldsType } from './common';
33
import { warn, logOnError } from './logger';
44

5-
type GraphQLLeafOperators = 'EQ' | 'GT' | 'GTE' | 'IN' | 'LT' | 'LTE' | 'NE' | 'NEQ' | 'NEQ' | 'NIN' | 'REGEX' | 'OPTIONS' | 'NOT';
6-
type MongoDbLeafOperators = '$eq' | '$gt' | '$gte' | '$in' | '$lt' | '$lte' | '$ne' | '$neq' | '$nin' | '$regex' | '$options' | '$not';
5+
type GraphQLLeafOperators = 'EQ' | 'GT' | 'GTE' | 'IN' | 'ALL' | 'LT' | 'LTE' | 'NE' | 'NEQ' | 'NEQ' | 'NIN' | 'REGEX' | 'OPTIONS' | 'NOT';
6+
type MongoDbLeafOperators = '$eq' | '$gt' | '$gte' | '$in' | '$all' | '$lt' | '$lte' | '$ne' | '$neq' | '$nin' | '$regex' | '$options' | '$not';
77
type GraphQLRootOperators = 'OR' | 'AND' | 'NOR';
88
export type MongoDbRootOperators = '$or' | '$and' | '$nor';
99
type GraphQLOperators = GraphQLLeafOperators | GraphQLRootOperators;
@@ -54,6 +54,7 @@ const operatorsMongoDbKeys: { [key in GraphQLOperators]: MongoDbOperators } = {
5454
GT: '$gt',
5555
GTE: '$gte',
5656
IN: '$in',
57+
ALL: '$all',
5758
LT: '$lt',
5859
LTE: '$lte',
5960
NE: '$ne',
@@ -183,7 +184,7 @@ function parseMongoDbScalarFilterOpr(opr: MongoDbLeafOperators, graphQLFilter: G
183184
dperecatedMessageSent = true;
184185
}
185186

186-
if (["$in", "$nin"].includes(opr)) {
187+
if (["$in", "$nin", "$all"].includes(opr)) {
187188
if (graphQLFilter['values']) {
188189
return { [opr]: graphQLFilter['values'] };
189190
}

tests/specs/graphQLFilterType.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe("graphQLFilterType", () => {
1818
GT: { value: "$gt" },
1919
GTE: { value: "$gte" },
2020
IN: { value: "$in" },
21+
ALL: { value: "$all" },
2122
LT: { value: "$lt" },
2223
LTE: { value: "$lte" },
2324
NE: { value: "$ne" },
@@ -43,6 +44,7 @@ describe("graphQLFilterType", () => {
4344
GT: { type: GraphQLID, description: "$gt" },
4445
GTE: { type: GraphQLID, description: "$gte" },
4546
IN: { type: new GraphQLList(GraphQLID), description: "$in" },
47+
ALL: { type: new GraphQLList(GraphQLID), description: "$all" },
4648
LT: { type: GraphQLID, description: "$lt" },
4749
LTE: { type: GraphQLID, description: "$lte" },
4850
NE: { type: GraphQLID, description: "$ne" },
@@ -58,6 +60,7 @@ describe("graphQLFilterType", () => {
5860
GT: { type: GraphQLID, description: "$gt" },
5961
GTE: { type: GraphQLID, description: "$gte" },
6062
IN: { type: new GraphQLList(GraphQLID), description: "$in" },
63+
ALL: { type: new GraphQLList(GraphQLID), description: "$all" },
6164
LT: { type: GraphQLID, description: "$lt" },
6265
LTE: { type: GraphQLID, description: "$lte" },
6366
NE: { type: GraphQLID, description: "$ne" },
@@ -80,6 +83,7 @@ describe("graphQLFilterType", () => {
8083
GT: { type: GraphQLString, description: "$gt" },
8184
GTE: { type: GraphQLString, description: "$gte" },
8285
IN: { type: new GraphQLList(GraphQLString), description: "$in" },
86+
ALL: { type: new GraphQLList(GraphQLString), description: "$all" },
8387
LT: { type: GraphQLString, description: "$lt" },
8488
LTE: { type: GraphQLString, description: "$lte" },
8589
NE: { type: GraphQLString, description: "$ne" },
@@ -98,6 +102,7 @@ describe("graphQLFilterType", () => {
98102
GT: { type: GraphQLString, description: "$gt" },
99103
GTE: { type: GraphQLString, description: "$gte" },
100104
IN: { type: new GraphQLList(GraphQLString), description: "$in" },
105+
ALL: { type: new GraphQLList(GraphQLString), description: "$all" },
101106
LT: { type: GraphQLString, description: "$lt" },
102107
LTE: { type: GraphQLString, description: "$lte" },
103108
NE: { type: GraphQLString, description: "$ne" },
@@ -123,6 +128,7 @@ describe("graphQLFilterType", () => {
123128
GT: { type: GraphQLInt, description: "$gt" },
124129
GTE: { type: GraphQLInt, description: "$gte" },
125130
IN: { type: new GraphQLList(GraphQLInt), description: "$in" },
131+
ALL: { type: new GraphQLList(GraphQLInt), description: "$all" },
126132
LT: { type: GraphQLInt, description: "$lt" },
127133
LTE: { type: GraphQLInt, description: "$lte" },
128134
NE: { type: GraphQLInt, description: "$ne" },
@@ -138,6 +144,7 @@ describe("graphQLFilterType", () => {
138144
GT: { type: GraphQLInt, description: "$gt" },
139145
GTE: { type: GraphQLInt, description: "$gte" },
140146
IN: { type: new GraphQLList(GraphQLInt), description: "$in" },
147+
ALL: { type: new GraphQLList(GraphQLInt), description: "$all" },
141148
LT: { type: GraphQLInt, description: "$lt" },
142149
LTE: { type: GraphQLInt, description: "$lte" },
143150
NE: { type: GraphQLInt, description: "$ne" },
@@ -160,6 +167,7 @@ describe("graphQLFilterType", () => {
160167
GT: { type: GraphQLFloat, description: "$gt" },
161168
GTE: { type: GraphQLFloat, description: "$gte" },
162169
IN: { type: new GraphQLList(GraphQLFloat), description: "$in" },
170+
ALL: { type: new GraphQLList(GraphQLFloat), description: "$all" },
163171
LT: { type: GraphQLFloat, description: "$lt" },
164172
LTE: { type: GraphQLFloat, description: "$lte" },
165173
NE: { type: GraphQLFloat, description: "$ne" },
@@ -175,6 +183,7 @@ describe("graphQLFilterType", () => {
175183
GT: { type: GraphQLFloat, description: "$gt" },
176184
GTE: { type: GraphQLFloat, description: "$gte" },
177185
IN: { type: new GraphQLList(GraphQLFloat), description: "$in" },
186+
ALL: { type: new GraphQLList(GraphQLFloat), description: "$all" },
178187
LT: { type: GraphQLFloat, description: "$lt" },
179188
LTE: { type: GraphQLFloat, description: "$lte" },
180189
NE: { type: GraphQLFloat, description: "$ne" },
@@ -197,6 +206,7 @@ describe("graphQLFilterType", () => {
197206
GT: { type: CharactersEnum, description: "$gt" },
198207
GTE: { type: CharactersEnum, description: "$gte" },
199208
IN: { type: new GraphQLList(CharactersEnum), description: "$in" },
209+
ALL: { type: new GraphQLList(CharactersEnum), description: "$all" },
200210
LT: { type: CharactersEnum, description: "$lt" },
201211
LTE: { type: CharactersEnum, description: "$lte" },
202212
NE: { type: CharactersEnum, description: "$ne" },
@@ -212,6 +222,7 @@ describe("graphQLFilterType", () => {
212222
GT: { type: CharactersEnum, description: "$gt" },
213223
GTE: { type: CharactersEnum, description: "$gte" },
214224
IN: { type: new GraphQLList(CharactersEnum), description: "$in" },
225+
ALL: { type: new GraphQLList(CharactersEnum), description: "$all" },
215226
LT: { type: CharactersEnum, description: "$lt" },
216227
LTE: { type: CharactersEnum, description: "$lte" },
217228
NE: { type: CharactersEnum, description: "$ne" },
@@ -320,6 +331,7 @@ describe("graphQLFilterType", () => {
320331
GT: { value: "$gt" },
321332
GTE: { value: "$gte" },
322333
IN: { value: "$in" },
334+
ALL: { value: "$all" },
323335
LT: { value: "$lt" },
324336
LTE: { value: "$lte" },
325337
NE: { value: "$ne" },
@@ -343,6 +355,7 @@ describe("graphQLFilterType", () => {
343355
GT: { type: GraphQLString, description: "$gt" },
344356
GTE: { type: GraphQLString, description: "$gte" },
345357
IN: { type: new GraphQLList(GraphQLString), description: "$in" },
358+
ALL: { type: new GraphQLList(GraphQLString), description: "$all" },
346359
LT: { type: GraphQLString, description: "$lt" },
347360
LTE: { type: GraphQLString, description: "$lte" },
348361
NE: { type: GraphQLString, description: "$ne" },
@@ -361,6 +374,7 @@ describe("graphQLFilterType", () => {
361374
GT: { type: GraphQLString, description: "$gt" },
362375
GTE: { type: GraphQLString, description: "$gte" },
363376
IN: { type: new GraphQLList(GraphQLString), description: "$in" },
377+
ALL: { type: new GraphQLList(GraphQLString), description: "$all" },
364378
LT: { type: GraphQLString, description: "$lt" },
365379
LTE: { type: GraphQLString, description: "$lte" },
366380
NE: { type: GraphQLString, description: "$ne" },
@@ -386,6 +400,7 @@ describe("graphQLFilterType", () => {
386400
GT: { type: GraphQLInt, description: "$gt" },
387401
GTE: { type: GraphQLInt, description: "$gte" },
388402
IN: { type: new GraphQLList(GraphQLInt), description: "$in" },
403+
ALL: { type: new GraphQLList(GraphQLInt), description: "$all" },
389404
LT: { type: GraphQLInt, description: "$lt" },
390405
LTE: { type: GraphQLInt, description: "$lte" },
391406
NE: { type: GraphQLInt, description: "$ne" },
@@ -401,6 +416,7 @@ describe("graphQLFilterType", () => {
401416
GT: { type: GraphQLInt, description: "$gt" },
402417
GTE: { type: GraphQLInt, description: "$gte" },
403418
IN: { type: new GraphQLList(GraphQLInt), description: "$in" },
419+
ALL: { type: new GraphQLList(GraphQLInt), description: "$all" },
404420
LT: { type: GraphQLInt, description: "$lt" },
405421
LTE: { type: GraphQLInt, description: "$lte" },
406422
NE: { type: GraphQLInt, description: "$ne" },
@@ -423,6 +439,7 @@ describe("graphQLFilterType", () => {
423439
GT: { type: GraphQLFloat, description: "$gt" },
424440
GTE: { type: GraphQLFloat, description: "$gte" },
425441
IN: { type: new GraphQLList(GraphQLFloat), description: "$in" },
442+
ALL: { type: new GraphQLList(GraphQLFloat), description: "$all" },
426443
LT: { type: GraphQLFloat, description: "$lt" },
427444
LTE: { type: GraphQLFloat, description: "$lte" },
428445
NE: { type: GraphQLFloat, description: "$ne" },
@@ -438,6 +455,7 @@ describe("graphQLFilterType", () => {
438455
GT: { type: GraphQLFloat, description: "$gt" },
439456
GTE: { type: GraphQLFloat, description: "$gte" },
440457
IN: { type: new GraphQLList(GraphQLFloat), description: "$in" },
458+
ALL: { type: new GraphQLList(GraphQLFloat), description: "$all" },
441459
LT: { type: GraphQLFloat, description: "$lt" },
442460
LTE: { type: GraphQLFloat, description: "$lte" },
443461
NE: { type: GraphQLFloat, description: "$ne" },
@@ -460,6 +478,7 @@ describe("graphQLFilterType", () => {
460478
GT: { type: CharactersEnum, description: "$gt" },
461479
GTE: { type: CharactersEnum, description: "$gte" },
462480
IN: { type: new GraphQLList(CharactersEnum), description: "$in" },
481+
ALL: { type: new GraphQLList(CharactersEnum), description: "$all" },
463482
LT: { type: CharactersEnum, description: "$lt" },
464483
LTE: { type: CharactersEnum, description: "$lte" },
465484
NE: { type: CharactersEnum, description: "$ne" },
@@ -475,6 +494,7 @@ describe("graphQLFilterType", () => {
475494
GT: { type: CharactersEnum, description: "$gt" },
476495
GTE: { type: CharactersEnum, description: "$gte" },
477496
IN: { type: new GraphQLList(CharactersEnum), description: "$in" },
497+
ALL: { type: new GraphQLList(CharactersEnum), description: "$all" },
478498
LT: { type: CharactersEnum, description: "$lt" },
479499
LTE: { type: CharactersEnum, description: "$lte" },
480500
NE: { type: CharactersEnum, description: "$ne" },

0 commit comments

Comments
 (0)