Skip to content

Commit

Permalink
filtering for nested data (#215)
Browse files Browse the repository at this point in the history
based on the filtering functionality introduced in #209, this PR adds new filtering capabilities for nested objects.

reminder: the filtering functionality currently present was designed after [dgraphs filtering proposal](https://dgraph.io/docs/graphql/queries/search-filtering/), so basically via an argument called `filter`, e.g.

* filter based on an attributes value `filter: { name: "some name" }`
* filter on list membership `filter: { names: { in: {'name one", "name two" } } }`

this `filter` argument was applicable only to top level fields of a GQL type, but now it can be applied to filter on nested objects by nesting `filter`s

this example query will return information for clusters of a specific organization. the `filter` argument is nested under the `ocm` property, which describes the organization of a cluster.

```gql
{
  clusters: cluster_v1(filter: {
    ocm: {
      filter: {
        orgId: "some org id"
      }
    }
  }) {
    name
  }
}
```

Signed-off-by: Gerd Oberlechner <[email protected]>

* typo

Signed-off-by: Gerd Oberlechner <[email protected]>

* use Array.isArray

Signed-off-by: Gerd Oberlechner <[email protected]>

* extractListOfValues remove duplicate logic

Signed-off-by: Gerd Oberlechner <[email protected]>

* remove obsolete args parameter of resolveValue

Signed-off-by: Gerd Oberlechner <[email protected]>

* check for unknown fields

Signed-off-by: Gerd Oberlechner <[email protected]>

* remove list eq

Signed-off-by: Gerd Oberlechner <[email protected]>

* remove duplicate logic

Signed-off-by: Gerd Oberlechner <[email protected]>

* cleanup

Signed-off-by: Gerd Oberlechner <[email protected]>

* readme

Signed-off-by: Gerd Oberlechner <[email protected]>

* change

Signed-off-by: Gerd Oberlechner <[email protected]>

---------

Signed-off-by: Gerd Oberlechner <[email protected]>
  • Loading branch information
geoberle authored Jan 15, 2024
1 parent e90f99a commit e14920f
Show file tree
Hide file tree
Showing 4 changed files with 414 additions and 130 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,57 @@ projects lint script:
```sh
yarn run lint
```

## GQL query filtering

While GQL does not define how filtering should work, it provides room for arguments to passed into queries. `qontract-server` offers a generic `filter` argument, that can be used to filter the resultset of a query.

```gql
query MyQuery($filter: JSON) {
clusters: clusters_v1(filter: $filter) {
...
}
}
```

The filter argument is a JSON document that can have the following content.

### Field equality predicate

To filter on an fields value, use the following filter object syntax

```json
"filter": {
"my_field": "my_value"
}
```

This way only resources with such a field and value are returned by the query.

### List contains predicate

Field values can be also compared towards a list of acceptable values.

```json
"filter": {
"my_field": {
"in": ["a", "b", "c"]
}
}
```

This way only resources are returned where the respective field is a or b or c.

### Nested predicates

Filtering is also supported on nested structures of a resource.

```json
"filter": {
"nested_resources": {
"filter": {
"nested_field": "nested_value"
}
}
}
```
Loading

0 comments on commit e14920f

Please sign in to comment.