A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.hypermode.com/dgraph/graphql/query/variables below:

GraphQL Variables - Dgraph

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. Syntax Examples (using default values): Variables can be defined and used in queries which helps in query reuse and avoids costly string building in clients at runtime by passing a separate variable map. A variable starts with a $ symbol. For HTTP requests with GraphQL Variables, we must use Content-Type: application/json header and pass data with a JSON object containing query and variables.
curl -H "Content-Type: application/json" localhost:8080/query -XPOST -d $'{
  "query": "query test($a: string) { test(func: eq(name, $a)) { \n uid \n name \n } }",
  "variables": { "$a": "Alice" }
}' | python -m json.tool | less
$a: "5",
$b: "10",
$name: "Steven Spielberg"

query {
  test($a: int, $b: int, $name: string) {
    me(func: allofterms(name@en, $name)) {
      name@en
      director.film (first: $a, offset: $b) {
        name @en genre(first: $a) { name@en }
      }
    }
  }
}
$b: "10",
$name: "Steven Spielberg"

query {
  test($a: int = 2, $b: int!, $name: string) {
    me(func: allofterms(name@en, $name)) {
      director.film (first: $a, offset: $b) { genre(first: $a) { name@en } }
    }
  }
}
You can also use array with GraphQL Variables.
$b: "10",
$aName: "Steven Spielberg",
$bName: "Quentin Tarantino"

query {
  test($a: int = 2, $b: int!, $aName: string, $bName: string) {
    me(func: eq(name@en, [$aName, $bName])) {
      director.film (first: $a, offset: $b) { genre(first: $a) { name@en } }
    }
  }
}
We also support variable substitution in facets.
$name: "Alice",
$IsClose: "true"

query {
  test($name: string = "Alice", $IsClose: string = "true") {
    data(func: eq(name, $name)) {
      friend @facets(eq(close, $IsClose)) { name }
      colleague : friend @facets(eq(close, false)) { name }
    }
  }
}

If you want to input a list of UIDs as a GraphQL variable value, you can have the variable as string type and have the value surrounded by square brackets like ["13", "14"].


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4