Skip to content

Commit 739abdc

Browse files
AlessioGrlablancas
andauthored
feat: query support for geo within and intersects + dynamic GraphQL operator types (#3183)
Co-authored-by: Lucas Blancas <lablancas@gmail.com>
1 parent c7cf2d3 commit 739abdc

File tree

14 files changed

+674
-110
lines changed

14 files changed

+674
-110
lines changed

src/admin/components/elements/WhereBuilder/field-types.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ const geo = [
5757
},
5858
];
5959

60+
const within = {
61+
label: 'within',
62+
value: 'within',
63+
};
64+
65+
const intersects = {
66+
label: 'intersects',
67+
value: 'intersects',
68+
};
69+
6070
const like = {
6171
label: 'isLike',
6272
value: 'like',
@@ -86,7 +96,7 @@ const fieldTypeConditions = {
8696
},
8797
json: {
8898
component: 'Text',
89-
operators: [...base, like, contains],
99+
operators: [...base, like, contains, within, intersects],
90100
},
91101
richText: {
92102
component: 'Text',
@@ -102,7 +112,7 @@ const fieldTypeConditions = {
102112
},
103113
point: {
104114
component: 'Point',
105-
operators: [...geo],
115+
operators: [...geo, within, intersects],
106116
},
107117
upload: {
108118
component: 'Text',

src/graphql/schema/buildWhereInputType.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@ import formatName from '../utilities/formatName';
1515
import { withOperators } from './withOperators';
1616
import fieldToSchemaMap from './fieldToWhereInputSchemaMap';
1717

18-
// buildWhereInputType is similar to buildObjectType and operates
19-
// on a field basis with a few distinct differences.
20-
//
21-
// 1. Everything needs to be a GraphQLInputObjectType or scalar / enum
22-
// 2. Relationships, groups, repeaters and flex content are not
23-
// directly searchable. Instead, we need to build a chained pathname
24-
// using dot notation so MongoDB can properly search nested paths.
18+
/** This does as the function name suggests. It builds a where GraphQL input type
19+
* for all the fields which are passed to the function.
20+
* Each field has different operators which may be valid for a where input type.
21+
* For example, a text field may have a "contains" operator, but a number field
22+
* may not.
23+
*
24+
* buildWhereInputType is similar to buildObjectType and operates
25+
* on a field basis with a few distinct differences.
26+
*
27+
* 1. Everything needs to be a GraphQLInputObjectType or scalar / enum
28+
* 2. Relationships, groups, repeaters and flex content are not
29+
* directly searchable. Instead, we need to build a chained pathname
30+
* using dot notation so MongoDB can properly search nested paths.
31+
*/
2532
const buildWhereInputType = (name: string, fields: Field[], parentName: string): GraphQLInputObjectType => {
2633
// This is the function that builds nested paths for all
2734
// field types with nested paths.

src/graphql/schema/operators.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const operators = {
44
contains: ['in', 'not_in', 'all'],
55
comparison: ['greater_than_equal', 'greater_than', 'less_than_equal', 'less_than'],
66
geo: ['near'],
7+
geojson: ['within', 'intersects'],
78
};
89

910
export default operators;

0 commit comments

Comments
 (0)