Fragments - Query language

fragment keyword allows you to define new fragments that can be referenced in a query, as per GraphQL specification. The point is that if there are multiple parts which query the same set of fields, you can define a fragment and refer to it multiple times instead. Fragments can be nested inside fragments, but no cycles are allowed. Here is one contrived example.

curl -H "Content-Type: application/graphql+-" localhost:8080/query -XPOST -d $'
query {
  debug(func: uid(1)) {
    [email protected]
    ...TestFrag
  }
}
fragment TestFrag {
  initial_release_date
  ...TestFragB
}
fragment TestFragB {
  country
}' | python -m json.tool | less

This is a companion discussion topic for the original entry at https://dgraph.io/docs/query-language/fragments/