Dgraph GraphQL Tour
Basic
Functions and filtering
Nodes are filtered based on functions applied to the node’s outgoing edges.
So far, the queries have only applied a filter to the top level nodes using the
getPerson
function, but you can apply filters to any edge in the query.
Dgraph has many functions available for filtering results, including the following:
-
fieldName: { allofterms: "term1 ... termN" }
: matches nodes with an outgoingstring
fieldfieldName
where the string contains all listed terms -
fieldName: { anyofterms: "term1 ... termN" }
: As withallOfTerms
, but matches at least one term -
The equalities and inequalities can be applied to edges of types:
Int
,Int64
,Float
,String
andDateTime
, including:fieldName: { eq: value }
: equal tofieldName: { ge: value }
: greater than or equal tofieldName: { le: value }
: less than or equal tofieldName: { gt: value }
: greater thanfieldName: { lt: value }
: less than
In addition to these capabilities, you can filter on regular expressions, use full text search, or use geographic (geo) search.
These filter functions are applied as arguments on fields in the GraphQL syntax. Dgraph only generates these arguments on fields that have the proper search directive applied for indexing.
Something to try: You can query all people under the age of 30, along with
the name of their pets. (Hint: use a filter argument with the queryPerson
root
function.)