Skip to content

Commit f791b87

Browse files
syndesismattbretl
authored andcommitted
Add support for filtering inet types with network operators (#49)
* Add support for filtering with network operators * Update README
1 parent 98e38e2 commit f791b87

12 files changed

+417
-39
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ connectionFilterOperatorNames: {
4242
| 4.0.0-alpha2.33 | 1.0.0-alpha.9 - 1.0.0-alpha.10 |
4343
| 4.0.0-beta.0 - 4.0.0-beta.7 | 1.0.0-beta.0 - 1.0.0-beta.6 |
4444
| 4.0.0-beta.8 or later | 1.0.0-beta.7 or later |
45+
| 4.0.0-rc.4 or later | 1.0.0-beta.15 or later |
4546

4647
## Performance and Security
4748

@@ -131,6 +132,12 @@ The following filter operators are exposed by default:
131132
| NOT SIMILAR TO '...' | notSimilarTo | String |
132133
| @> | contains | JSON |
133134
| <@ | containedBy | JSON |
135+
| &lt;&lt; | inetContainedBy | InternetAddress |
136+
| &lt;&lt;= | inetContainedByOrEquals | InternetAddress |
137+
| &gt;&gt; | inetContains | InternetAddress |
138+
| &gt;&gt;= | inetContainsOrEquals | InternetAddress |
139+
| &amp;&amp; | inetContainsOrIsContainedBy | InternetAddress |
140+
134141

135142
### List Comparison Operators
136143

__tests__/fixtures/queries/connections-filter.graphql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ query {
6060
intArray_anyLessThanOrEqualTo_2: allFilterables(filter: { intArray: { anyLessThanOrEqualTo: 2 } }) { ...filterableIntArrayConnection }
6161
intArray_anyGreaterThan_2: allFilterables(filter: { intArray: { anyGreaterThan: 2 } }) { ...filterableIntArrayConnection }
6262
intArray_anyGreaterThanOrEqualTo_2: allFilterables(filter: { intArray: { anyGreaterThanOrEqualTo: 2 } }) { ...filterableIntArrayConnection }
63+
inet_containedBy: allFilterables(filter: { inet: { inetContainedBy: "192.168.0.0/24" } }) { ...filterableInetConnection }
64+
inet_containedByOrEquals_ContainedBy: allFilterables(filter: { inet: { inetContainedByOrEquals: "192.168.1.0/24" } }) { ...filterableInetConnection }
65+
inet_containedByOrEquals_Equals: allFilterables(filter: { inet: { inetContainedByOrEquals: "192.168.1.1" } }) { ...filterableInetConnection }
66+
inet_contains: allFilterables(filter: { inet: { inetContains: "10.0.0.1" } }) { ...filterableInetConnection }
67+
inet_containsOrEquals_Contains: allFilterables(filter: { inet: { inetContainsOrEquals: "10.0.0.2" } }) { ...filterableInetConnection }
68+
inet_containsOrEquals_Equals: allFilterables(filter: { inet: { inetContainsOrEquals: "10.0.0.1/24" } }) { ...filterableInetConnection }
69+
inet_containsOrIsContainedBy_Contains: allFilterables(filter: { inet: { inetContainsOrIsContainedBy: "172.168.1.0/24" } }) { ...filterableInetConnection }
70+
inet_containsOrIsContainedBy_ContainedBy: allFilterables(filter: { inet: { inetContainsOrIsContainedBy: "10.0.0.5" } }) { ...filterableInetConnection }
6371
}
6472

6573
fragment filterableConnection on FilterablesConnection {
@@ -95,4 +103,11 @@ fragment filterableIntArrayConnection on FilterablesConnection {
95103
id
96104
intArray
97105
}
106+
}
107+
108+
fragment filterableInetConnection on FilterablesConnection {
109+
nodes {
110+
id
111+
inet
112+
}
98113
}

__tests__/integration/__snapshots__/queries.test.js.snap

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,70 @@ Object {
288288
},
289289
"totalCount": 1,
290290
},
291+
"inet_containedBy": Object {
292+
"nodes": Array [
293+
Object {
294+
"id": 1,
295+
"inet": "192.168.0.1",
296+
},
297+
],
298+
},
299+
"inet_containedByOrEquals_ContainedBy": Object {
300+
"nodes": Array [
301+
Object {
302+
"id": 2,
303+
"inet": "192.168.1.1",
304+
},
305+
],
306+
},
307+
"inet_containedByOrEquals_Equals": Object {
308+
"nodes": Array [
309+
Object {
310+
"id": 2,
311+
"inet": "192.168.1.1",
312+
},
313+
],
314+
},
315+
"inet_contains": Object {
316+
"nodes": Array [
317+
Object {
318+
"id": 3,
319+
"inet": "10.0.0.0/24",
320+
},
321+
],
322+
},
323+
"inet_containsOrEquals_Contains": Object {
324+
"nodes": Array [
325+
Object {
326+
"id": 3,
327+
"inet": "10.0.0.0/24",
328+
},
329+
],
330+
},
331+
"inet_containsOrEquals_Equals": Object {
332+
"nodes": Array [
333+
Object {
334+
"id": 3,
335+
"inet": "10.0.0.0/24",
336+
},
337+
],
338+
},
339+
"inet_containsOrIsContainedBy_ContainedBy": Object {
340+
"nodes": Array [
341+
Object {
342+
"id": 3,
343+
"inet": "10.0.0.0/24",
344+
},
345+
],
346+
},
347+
"inet_containsOrIsContainedBy_Contains": Object {
348+
"nodes": Array [
349+
Object {
350+
"id": 4,
351+
"inet": "172.168.1.1",
352+
},
353+
],
354+
},
291355
"intArray_anyEqualTo_2": Object {
292356
"nodes": Array [
293357
Object {

__tests__/integration/schema/__snapshots__/connectionFilter.test.js.snap

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ type Filterable implements Node {
173173
computed: String
174174
computed2: String
175175
id: Int!
176+
inet: InternetAddress
176177
int: Int
177178
intArray: [Int]
178179
jsonb: JSON
@@ -197,6 +198,9 @@ input FilterableCondition {
197198
\\"\\"\\"Checks for equality with the object’s \`id\` field.\\"\\"\\"
198199
id: Int
199200
201+
\\"\\"\\"Checks for equality with the object’s \`inet\` field.\\"\\"\\"
202+
inet: InternetAddress
203+
200204
\\"\\"\\"Checks for equality with the object’s \`int\` field.\\"\\"\\"
201205
int: Int
202206
@@ -229,6 +233,9 @@ input FilterableFilter {
229233
\\"\\"\\"Filter by the object’s \`id\` field.\\"\\"\\"
230234
id: IntFilter
231235
236+
\\"\\"\\"Filter by the object’s \`inet\` field.\\"\\"\\"
237+
inet: InternetAddressFilter
238+
232239
\\"\\"\\"Filter by the object’s \`int\` field.\\"\\"\\"
233240
int: IntFilter
234241
@@ -255,6 +262,7 @@ input FilterableFilter {
255262
input FilterableInput {
256263
boolean: Boolean
257264
id: Int
265+
inet: InternetAddress
258266
int: Int
259267
intArray: [Int]
260268
jsonb: JSON
@@ -269,6 +277,7 @@ Represents an update to a \`Filterable\`. Fields that are set will be updated.
269277
input FilterablePatch {
270278
boolean: Boolean
271279
id: Int
280+
inet: InternetAddress
272281
int: Int
273282
intArray: [Int]
274283
jsonb: JSON
@@ -309,6 +318,8 @@ enum FilterablesOrderBy {
309318
BOOLEAN_DESC
310319
ID_ASC
311320
ID_DESC
321+
INET_ASC
322+
INET_DESC
312323
INT_ARRAY_ASC
313324
INT_ARRAY_DESC
314325
INT_ASC
@@ -326,6 +337,56 @@ enum FilterablesOrderBy {
326337
STRING_DESC
327338
}
328339
340+
\\"\\"\\"An IPv4 or IPv6 host address, and optionally its subnet.\\"\\"\\"
341+
scalar InternetAddress
342+
343+
\\"\\"\\"
344+
A filter to be used against InternetAddress fields. All fields are combined with a logical ‘and.’
345+
\\"\\"\\"
346+
input InternetAddressFilter {
347+
\\"\\"\\"
348+
Checks for values not equal to this value, treating null like an ordinary value.
349+
\\"\\"\\"
350+
distinctFrom: InternetAddress
351+
352+
\\"\\"\\"Checks for values equal to this value.\\"\\"\\"
353+
equalTo: InternetAddress
354+
355+
\\"\\"\\"Checks for values in this list.\\"\\"\\"
356+
in: [InternetAddress!]
357+
358+
\\"\\"\\"Checks if an inet is contained by another inet\\"\\"\\"
359+
inetContainedBy: InternetAddress
360+
361+
\\"\\"\\"Checks if an inet is contained by or equals another inet\\"\\"\\"
362+
inetContainedByOrEquals: InternetAddress
363+
364+
\\"\\"\\"Checks if an inet contains another inet\\"\\"\\"
365+
inetContains: InternetAddress
366+
367+
\\"\\"\\"Checks if an inet contains or equals another inet\\"\\"\\"
368+
inetContainsOrEquals: InternetAddress
369+
370+
\\"\\"\\"Checks if an inet contains or is contained by another inet\\"\\"\\"
371+
inetContainsOrIsContainedBy: InternetAddress
372+
373+
\\"\\"\\"
374+
If set to true, checks for null values. If set to false, checks for non-null values.
375+
\\"\\"\\"
376+
isNull: Boolean
377+
378+
\\"\\"\\"
379+
Checks for values equal to this value, treating null like an ordinary value.
380+
\\"\\"\\"
381+
notDistinctFrom: InternetAddress
382+
383+
\\"\\"\\"Checks for values not equal to this value.\\"\\"\\"
384+
notEqualTo: InternetAddress
385+
386+
\\"\\"\\"Checks for values not in this list.\\"\\"\\"
387+
notIn: [InternetAddress!]
388+
}
389+
329390
\\"\\"\\"
330391
A filter to be used against Int fields. All fields are combined with a logical ‘and.’
331392
\\"\\"\\"

__tests__/integration/schema/__snapshots__/connectionFilterAllowedOperators.test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ type Filterable implements Node {
119119
computed: String
120120
computed2: String
121121
id: Int!
122+
inet: InternetAddress
122123
int: Int
123124
intArray: [Int]
124125
jsonb: JSON
@@ -143,6 +144,9 @@ input FilterableCondition {
143144
\\"\\"\\"Checks for equality with the object’s \`id\` field.\\"\\"\\"
144145
id: Int
145146
147+
\\"\\"\\"Checks for equality with the object’s \`inet\` field.\\"\\"\\"
148+
inet: InternetAddress
149+
146150
\\"\\"\\"Checks for equality with the object’s \`int\` field.\\"\\"\\"
147151
int: Int
148152
@@ -175,6 +179,9 @@ input FilterableFilter {
175179
\\"\\"\\"Filter by the object’s \`id\` field.\\"\\"\\"
176180
id: IntFilter
177181
182+
\\"\\"\\"Filter by the object’s \`inet\` field.\\"\\"\\"
183+
inet: InternetAddressFilter
184+
178185
\\"\\"\\"Filter by the object’s \`int\` field.\\"\\"\\"
179186
int: IntFilter
180187
@@ -201,6 +208,7 @@ input FilterableFilter {
201208
input FilterableInput {
202209
boolean: Boolean
203210
id: Int
211+
inet: InternetAddress
204212
int: Int
205213
intArray: [Int]
206214
jsonb: JSON
@@ -215,6 +223,7 @@ Represents an update to a \`Filterable\`. Fields that are set will be updated.
215223
input FilterablePatch {
216224
boolean: Boolean
217225
id: Int
226+
inet: InternetAddress
218227
int: Int
219228
intArray: [Int]
220229
jsonb: JSON
@@ -255,6 +264,8 @@ enum FilterablesOrderBy {
255264
BOOLEAN_DESC
256265
ID_ASC
257266
ID_DESC
267+
INET_ASC
268+
INET_DESC
258269
INT_ARRAY_ASC
259270
INT_ARRAY_DESC
260271
INT_ASC
@@ -272,6 +283,20 @@ enum FilterablesOrderBy {
272283
STRING_DESC
273284
}
274285
286+
\\"\\"\\"An IPv4 or IPv6 host address, and optionally its subnet.\\"\\"\\"
287+
scalar InternetAddress
288+
289+
\\"\\"\\"
290+
A filter to be used against InternetAddress fields. All fields are combined with a logical ‘and.’
291+
\\"\\"\\"
292+
input InternetAddressFilter {
293+
\\"\\"\\"Checks for values equal to this value.\\"\\"\\"
294+
equalTo: InternetAddress
295+
296+
\\"\\"\\"Checks for values not equal to this value.\\"\\"\\"
297+
notEqualTo: InternetAddress
298+
}
299+
275300
\\"\\"\\"
276301
A filter to be used against Int fields. All fields are combined with a logical ‘and.’
277302
\\"\\"\\"

0 commit comments

Comments
 (0)