Using Conditions in GraphQL Queries
Conditions are used to control what results are return
distinct_on
- return unique results from the value of a specified attributelimit
- limit the number of rows returnedoffset
- skip the specified number of resultsorder_by
- sort the rows by one or more columnswhere
- filter results based on the value of specified attributes
Conditions Basic form
Conditions are defined as arguments to the field in the query.
type query_root {
live_match_event(
distinct_on: [live_match_event_select_column!],
limit: Int,
offset: Int,
order_by: [live_match_event_order_by!],
where: live_match_event_bool_exp
)
}
Defining Variables
Dynamic values can be defined using Variables to make queries easier to work with.
Distinct results
A distinct_on
condition for a specified field will return a unique set of results based on the values of that field.
For example, searching for a Player can return the same result multiple times, found across multiple match line-ups. Using distinct_on
for the player_id
filed will ensure that only distinct results are returned for that player_id
.
Limit number of results
Using limits can make your queries return results faster, as the query will return once the number of results in the limit has been reached.
limit
takes an integer number that sets the maximum number of results to return from any query.
Default limits
The LIVE Data API is limited to 4,200 events for queries, with a further limit of 200 on aggregated stats
Offset results
offset
takes an integer number which defines the number of results to skip.
For example, if there are 50 events per minute in a game and are only interested in events after the first 10 minutes. Set an offset value of 500
would skip results from approximately the first 10 minutes.
Order results by a value
Return the results of the query sorted by the value of the attribute specified
Examples Order matches by date
where
Use where
in queries to filter results based on some field’s values You can even use multiple filters in the same where clause using the _and or the _or operators.
Equality
_eq
equal to a value of a field_neq
not equal to a value of a field_gt
greater than_lt
less than_gte
greater than or equal to_lte
less than or equal to
Hint
the _eq
or _neq
operators will not return rows with null values. Use the `_is_null** operator to match on null values.
List Based Searching
_in
in a list- `_nin** not in a list
Text searching
Use the following to search for a string match. Use %
as a wildcard that represents one or more characters in the string.
_like
field string is like pattern_nlike
field string is not like pattern_ilike
field string is like pattern - case insensitive_nilike
field string is like pattern - case insensitive_similar
string similar to one or more patterns "%(United|City)" - team name ending in United or City_nsimilar
string not similar to one or more patterns_regex
regular expression pattern matching_nregex
not a match for regular expression pattern_iregex
regular expression pattern matching - case insensitive_inregex
not a match for regular expression pattern