And, Or, and Not Operators in GraphQL
Every GraphQL search filter can use AND, OR, and NOT operators.
Weâre overhauling Dgraphâs docs to make them clearer and more approachable. If you notice any issues during this transition or have suggestions, please let us know.
Every GraphQL search filter can use and
, or
, and not
operators.
GraphQL syntax uses infix notation, so: âa and bâ is a, and: { b }
, âa or b or
câ is a, or: { b, or: c }
, and ânotâ is a prefix (not:
).
The following example queries demonstrate the use of and
, or
, and not
operators:
Example: posts that donât have âGraphQLâ in the title
Example: âPosts that have âGraphQLâ or âDgraphâ in the titleâ
Example: âPosts that have âGraphQLâ and âDgraphâ in the titleâ
The and
operator is implicit for a single filter object, if the fields donât
overlap. For example, the and
is required because title
is in both filters,
whereas in the query below and
isnât required.
Example: âPosts that have âGraphQLâ in the title, or have the tag âGraphQLâ and mention âDgraphâ in the titleâ
The and
and or
filter both accept a list of filters. Per the GraphQL
specification, non-list filters are coerced into a list. This provides
backwards-compatibility while allowing for more complex filters.
Example: âQuery for posts that have GraphQL
in the title but that lack the
GraphQL
tag, or that have Dgraph
in the title but lack the Dgraph
tagâ
Nesting
Nested logic with the same and
/or
conjunction can be simplified into a
single list.
For example, the following complex query:
Can be simplified into the following simplified query syntax: