graphql-filters 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +165 -1
- data/lib/graphql/filters/input_types/fields_comparison_input_type.rb +12 -1
- data/lib/graphql/filters/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 474fc735080a91dfb20de27a6f30d865130318e8689f2cd3e2fc4c4ba36c5510
|
|
4
|
+
data.tar.gz: aac6eb21e108ae715f69f4256d21491cc23a5b5cc01e64528fbc9e48864c8bac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea105b60ad6f8a8da6c13fd2dc78e0230f0d2ad091645e59acb56c1f38b6b04804eba2acd1487b350234225d3624c8d36dd88a8292b73f0aff003bf30ecacbb7
|
|
7
|
+
data.tar.gz: 746922a0932f6446e1428265d9a8b97ab82dc543af4907cf811b42d24b60430a419e9055cbabfa58b4d25eea3fd42f14b6d00d42d36cf774d8f37da4575ad9a6
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -92,6 +92,7 @@ query {
|
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
+
}
|
|
95
96
|
}
|
|
96
97
|
```
|
|
97
98
|
|
|
@@ -99,6 +100,9 @@ Notice that eager loading is outside the scope of this gem, so without anything
|
|
|
99
100
|
|
|
100
101
|
Each input type is generated based on the respective type: scalar and enum types allow for basic comparisons like equality and inclusion, while object types let you build complex queries that mix and match comparisons on their fields. List types let you make `any`, `all`, and `none` queries based on a nested filter. Support for null-checked filters is planned for future development.
|
|
101
102
|
|
|
103
|
+
> [!NOTE]
|
|
104
|
+
> Active Storage classes don't play well with GraphQL Filters. You should disable filters for their respective fields using `filter: false`. A cleaner handling of these cases is planned for future development.
|
|
105
|
+
|
|
102
106
|
### Underlying models
|
|
103
107
|
|
|
104
108
|
GraphQL Filters relies on the assumption that every object type exists on top of an Active Record model. A field of type `PokemonType` will always be resolved to an instance of `Pokemon`, and its fields will match (at least loosely) the attributes of the model. This assumption allows the gem to generate appropriate subqueries for nested filters.
|
|
@@ -155,9 +159,12 @@ The best way to know what comparators you can use with each field is to open the
|
|
|
155
159
|
`matches` is available for the `String` type. Its value is a string in the format `<version>/<pattern>/<options>`.
|
|
156
160
|
|
|
157
161
|
- At the moment, `<version>` can only be `v1`, but extensions are planned for future development.
|
|
158
|
-
- For version `v1`, `<pattern>` will match a `.` with any one character and a `*` with zero or more characters. To match any literal character you can prefix it with
|
|
162
|
+
- For version `v1`, `<pattern>` will match a `.` with any one character and a `*` with zero or more characters. To match any literal character you can prefix it with `\`.
|
|
159
163
|
- For version `v1`, `<options>` can be empty, or be `i`, which will make the match case insensitive.
|
|
160
164
|
|
|
165
|
+
> [!NOTE]
|
|
166
|
+
> This is *not* a regex engine, just a simple wildcard matcher.
|
|
167
|
+
|
|
161
168
|
#### List comparisons
|
|
162
169
|
|
|
163
170
|
`any`, `all`, and `none` are available for any list, take a comparator for the type of the elements of the list, and match, respectively, if at least one, all, or none, of the elements of the list match the nested comparator.
|
|
@@ -236,6 +243,163 @@ field :name, String, null: false, filter: {enabled: false}
|
|
|
236
243
|
|
|
237
244
|
The type the filters for this field need to be based on, if it's different from the field's own type (for example, a field thet returns a connection will need to be filtered based on the connection's node type). Can also be set calling the `filtered_type` on a resolver/mutation if the field is associated with one.
|
|
238
245
|
|
|
246
|
+
### API usage examples
|
|
247
|
+
|
|
248
|
+
To get all pokémon whose main color is blue:
|
|
249
|
+
|
|
250
|
+
```graphql
|
|
251
|
+
query{
|
|
252
|
+
pokemons(
|
|
253
|
+
filter: {
|
|
254
|
+
fields: {
|
|
255
|
+
mainColor: { equals: "blue" }
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
){
|
|
259
|
+
...
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
To get all pokémon whose main color is either blue or red:
|
|
265
|
+
|
|
266
|
+
```graphql
|
|
267
|
+
query{
|
|
268
|
+
pokemons(
|
|
269
|
+
filter: {
|
|
270
|
+
fields: {
|
|
271
|
+
mainColor: { in: ["blue", "red"] }
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
){
|
|
275
|
+
...
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
To get all pokémon whose name begins with 's':
|
|
281
|
+
|
|
282
|
+
```graphql
|
|
283
|
+
query{
|
|
284
|
+
pokemons(
|
|
285
|
+
filter: {
|
|
286
|
+
fields: {
|
|
287
|
+
name: { match: "v1/s*/i" }
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
){
|
|
291
|
+
...
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
To get all pokémon whose base friendship is 70 or whose catch rate is more than 100:
|
|
297
|
+
|
|
298
|
+
```graphql
|
|
299
|
+
query{
|
|
300
|
+
pokemons(
|
|
301
|
+
filter: {
|
|
302
|
+
or: [
|
|
303
|
+
{
|
|
304
|
+
fields: {
|
|
305
|
+
baseFriendship: { equals: 70 }
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
{
|
|
309
|
+
fields: {
|
|
310
|
+
catchRate: { greaterThanOrEqualsTo: 100 }
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
){
|
|
316
|
+
...
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
To get all pokémon that evolve from Eevee:
|
|
322
|
+
|
|
323
|
+
```graphql
|
|
324
|
+
query{
|
|
325
|
+
pokemons(
|
|
326
|
+
filter: {
|
|
327
|
+
fields: {
|
|
328
|
+
preEvolution: {
|
|
329
|
+
fields: {
|
|
330
|
+
name: { equals: "Eevee" }
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
){
|
|
336
|
+
...
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
To get all pokémon catchable in the Kanto route 1:
|
|
342
|
+
|
|
343
|
+
```graphql
|
|
344
|
+
query{
|
|
345
|
+
pokemons(
|
|
346
|
+
filter: {
|
|
347
|
+
fields: {
|
|
348
|
+
routes: {
|
|
349
|
+
any: {
|
|
350
|
+
fields: {
|
|
351
|
+
name: { equals: "1" }
|
|
352
|
+
region: {
|
|
353
|
+
fields: {
|
|
354
|
+
name: { equals: "Kanto" }
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
){
|
|
363
|
+
...
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
To get all routes in Kanto where you can catch a water type pokémon (this is the example at the top of the page):
|
|
369
|
+
|
|
370
|
+
```graphql
|
|
371
|
+
query {
|
|
372
|
+
routes(
|
|
373
|
+
filter: {
|
|
374
|
+
fields: {
|
|
375
|
+
region: {
|
|
376
|
+
fields: {
|
|
377
|
+
name: { equals: "Kanto" }
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
catchablePokemon: {
|
|
381
|
+
any: {
|
|
382
|
+
fields: {
|
|
383
|
+
pokemon: {
|
|
384
|
+
types: {
|
|
385
|
+
any: {
|
|
386
|
+
fields: {
|
|
387
|
+
name: { equals: "Water"}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
){
|
|
398
|
+
...
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
```
|
|
402
|
+
|
|
239
403
|
## Plans for future development
|
|
240
404
|
|
|
241
405
|
- A finer grain support for non-nullable fields.
|
|
@@ -55,7 +55,18 @@ module GraphQL
|
|
|
55
55
|
|
|
56
56
|
scope.and nested_query
|
|
57
57
|
else
|
|
58
|
-
scope.
|
|
58
|
+
reflection = scope.klass.reflect_on_association association_name
|
|
59
|
+
|
|
60
|
+
if reflection.through_reflection?
|
|
61
|
+
through_reflection = reflection.through_reflection
|
|
62
|
+
scope.where(
|
|
63
|
+
through_reflection.name => through_reflection.klass.where(
|
|
64
|
+
reflection.source_reflection.name => nested_query
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
else
|
|
68
|
+
scope.where association_name => nested_query
|
|
69
|
+
end
|
|
59
70
|
end
|
|
60
71
|
end
|
|
61
72
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: graphql-filters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Moku S.r.l.
|
|
8
8
|
- Riccardo Agatea
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: activerecord
|
|
@@ -131,7 +130,6 @@ metadata:
|
|
|
131
130
|
homepage_uri: https://github.com/moku-io/graphql-filters
|
|
132
131
|
source_code_uri: https://github.com/moku-io/graphql-filters
|
|
133
132
|
changelog_uri: https://github.com/moku-io/graphql-filters/blob/master/CHANGELOG.md
|
|
134
|
-
post_install_message:
|
|
135
133
|
rdoc_options: []
|
|
136
134
|
require_paths:
|
|
137
135
|
- lib
|
|
@@ -146,8 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
146
144
|
- !ruby/object:Gem::Version
|
|
147
145
|
version: '0'
|
|
148
146
|
requirements: []
|
|
149
|
-
rubygems_version: 3.
|
|
150
|
-
signing_key:
|
|
147
|
+
rubygems_version: 3.6.7
|
|
151
148
|
specification_version: 4
|
|
152
149
|
summary: Provide a fully typed interface to filter lists in a GraphQL API.
|
|
153
150
|
test_files: []
|