Skip to content

Examples of GraphQL operations: Queries with filters and counts

  Less than to read

Filtering syntaxes can have various forms and use several operators, such as _eq, _ne, _lt, _gt, or _in. The string constants are placed between single brackets.

The following pages describe different cases of GraphQL queries using filters and counts. The queries use real examples.

Here are some examples of filters:

Simple value equality
query(filter: "{ minimumPrice: 45}")
Comparison operators (less than)
query(filter: "{minimumPrice:{_lt:45}}")
Combined filters (and)
query(filter: "{isActive:true,minimumPrice:{_lt:45}}")
Filter on nested properties (not equal)
query(filter: "{stockUnit:{name:{_ne:'each'}}}")
Combined filters (or)
query(filter: "{_or: [{isActive:true},{minimumPrice:{_lt:45}}]}")
List of values
query(filter: "{minimumPrice:{_in:[0,45,450]}}")
Regular expression
query(filter: "{stockUnit:{name:{_regex:'.*i.*'}}}")
Minimum number of lines in a secondary level
query (filter:"{customers: {_atLeast:1}}")
Minimum count on condition
query (filter:"{customers: {_atLeast:2,customer:{currency:{id:'EUR'}}}}")
Not on condition
query (filter:"{id:{ _not: {_regex: 'FCR.*'}}}")