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 outgoing string field fieldName where the string contains all listed terms

  • fieldName: { anyofterms: "term1 ... termN" }: As with allOfTerms, but matches at least one term

  • The equalities and inequalities can be applied to edges of types: Int, Int64, Float, String and DateTime, including:

    • fieldName: { eq: value }: equal to
    • fieldName: { ge: value }: greater than or equal to
    • fieldName: { le: value }: less than or equal to
    • fieldName: { gt: value }: greater than
    • fieldName: { 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.)

2.5 Functions and filtering