Dgraph GraphQL Tour
Basic
Logical Connectives (and, or, & not)
The logical connectives and
, or
and not
combine multiple functions in a
filter.
When you provide multiple parameters in a filter argument they are combined
with and
logic by default, as in the following example:
{
getPerson(xid: "alice") {
xid
friends(filter: {
xid: { eq: "dave" }
age: { eq: 35 }
}) {
xid
age
}
}
}
With GraphQL, each parameter of an argument object must be unique. You can wrap
arguments in logical lists using and
and or
, as follows:
{
getPerson(xid: "alice") {
xid
friends(filter: {
and: [
{ age: { ge: 30 } },
{ age: { lt: 40 } }
]
}) {
xid
age
}
}
}
Dgraph generates another GraphQL syntax for joining multiple filter functions
together with inline and
and or
filter parameters. When combining more than two
filter functions, or using more than a single logical combinator, users might find
that logical lists provide more easily readable queries.
{
getPerson(xid: "alice") {
xid
friends(filter: {
age: { ge: 35 }, or: { xid: { eq: "frank" } }
}) {
xid
age
}
}
}
You can also add inequality filters using the not
logical combinator, as follows:
{
queryPerson(filter: { not: { age: { le: 30 } } }) {
id
name
ownsPets {
id
name
}
}
}
The not
logical wrapper cannot contain a list of
arguments not: [{ age: ... }, ...]
. But it can contain multiple arguments and
other logical combinators, e.g.: not: { and: [{ age: ... }, ...] }