Filtering NReco.GraphQL documentation


Filters allows us to constrain queries to a particular account, requests by date or set logical conditions which exposes Boolean algebra on nodes. Without filters, queries can suffer performance degradation, results can easily be enormous and using is fulled by pain.

Filter configuration

In NReco.GraphQL we have one main or standard approach to use filter which is a quite friendly to use (syntax based on json-format); supports nested logical operators OR/AND (similar to https://developers.cloudflare.com/analytics/graphql-api/features/filtering ). By default, filter is available by argument key "filter" for all defined schemas and it can be changed via setting filter option in the json file. Alternative filter is based on NReco.Relex and allows to set compact filter expressions. By default, filter is available by argument key "filter_relex" for all defined schemas and can be changed from the json file as well. To change filter keys set Filter section inside section of Options in the JSON configuration:
"Options": {
	"Filter": {
		"Key": "filter_jsonstyle",
		"RelexKey": "new_filter_relex",
		"Enabled":true
	}
Property Purpose
Key standard (json-style) filter argument name in the GraphQL query
RelexKey

alternative (based on NReco.Relex) filter argument name in the GraphQL query

Enabled

turn on/off filter; field may be omitted - by default true

An example of using standard filter

Graphql query:
query {
	orders(filter:{
			incidentid_in:[426],
			OR:[
				{validityend:null},
				{validityend_gt:"2021-08-27"},
				{
					AND:[
						{validityend_eq:"2021"},
						{approved_neq:"Yes"}
					]
				}
			],
			status_in:["Approved","InProgress"]
		}) 
	{
		orderId
		status
	}
}
		
Response:
{
	"data": {
		"orders": [
			{
				"orderId": 1006,
				"status": "Approved"
			},
			{
				"orderId": 1106,
				"status": "InProgress"
			}
		]
	}
}
		

Inside filter argument you can:

use any of defined schema's fields (name should be the same as it defined in the json) which are ended with of postfixes:

like determines whether a specific character string matches a specified pattern (filer value can contain the percent sign "%" - it will be applied SQL-operator in the WHERE clause)

nlike not like (the same as previous but negate)

gt greater than

lt less than

geq greater or equal to

leq less or equal to

neq not equal

in in (array)

nin not in (array)

Use the AND/OR operators to create and/or combine multi-node filter

An example of using alternative, relex-based filter

Graphql query:
query {
	orders(filter_relex:"orderId >= \"1000\" AND ShipCountry IN \"Brazil,Mexico\":string[]") {
		orderId
		ShipCountry
	}
}
		
Response:
{
	"data": {
		"orders": [
			{
				"orderId": 10276,
				"ShipCountry": "Mexico"
			},
			{
				"orderId": 1106,
				"ShipCountry": "Brazil"
			}
		]
	}
}
		

filter_relex argument is string expression based on Boolean algebra, for example:

get one item by id orderId="5":int

get one item(s) by id (NOT equal) orderId!="5":int

get one item by ShipCountry (LIKE operator) and Property less or equal to "5"(ShipCountry like \"Mex%\" and Priority<=\"5\")

get items in array orderId in "2,65,98":int[] (it may be string type as we have in an example above)

get items in array orderId in "2,65,98":int[] (it may be string type as we have in an example above)

get items NOT in array orderId !in "2,65,98":int[] (it may be string type as we have in an example above)

get one item(s) by simple condition plus group of condition (boolean AND)AddedDate > "2020-Jan-01":datetime and (Expired = "true":boolean or Balance<"0":decimal)

get one item by id orderId="5":int