Skip to main content
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
queryPost(filter: { not: { title: { allofterms: "GraphQL"} } } ) { ... }
Example: β€œPosts that have β€œGraphQL” or β€œDgraph” in the title”
queryPost(filter: {
  title: { allofterms: "GraphQL"},
  or: { title: { allofterms: "Dgraph" } }
} ) { ... }
Example: β€œPosts that have β€œGraphQL” and β€œDgraph” in the title”
queryPost(filter: {
  title: { allofterms: "GraphQL"},
  and: { title: { allofterms: "Dgraph" } }
} ) { ... }
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.
queryPost(filter: {
  title: { allofterms: "GraphQL" },
  datePublished: { ge: "2020-06-15" }
} ) { ... }
Example: β€œPosts that have β€œGraphQL” in the title, or have the tag β€œGraphQL” and mention β€œDgraph” in the title”
queryPost(filter: {
  title: { allofterms: "GraphQL"},
  or: { title: { allofterms: "Dgraph" }, tags: { eq: "GraphQL" } }
} ) { ... }
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”
queryPost(filter: {
  or: [
    { and: [{ title: { allofterms: "GraphQL" } }, { not: { tags: { eq: "GraphQL" } } }] }
    { and: [{ title: { allofterms: "Dgraph" } }, { not: { tags: { eq: "Dgraph" } } }] }
  ]
} ) { ... }

Nesting

Nested logic with the same and/or conjunction can be simplified into a single list. For example, the following complex query:
queryPost(filter: {
  or: [
    { or: [ { foo: { eq: "A" } }, { bar: { eq: "B" } } ] },
    { or: [ { baz: { eq: "C" } }, { quz: { eq: "D" } } ] }
  ]
} ) { ... }
Can be simplified into the following simplified query syntax:
queryPost(filter: {
  or: [
    { foo: { eq: "A" } },
    { bar: { eq: "B" } },
    { baz: { eq: "C" } },
    { quz: { eq: "D" } }
  ]
} ) { ... }
⌘I