- 
                Notifications
    You must be signed in to change notification settings 
- Fork 820
Aliasing (rename query elements)
        changeling edited this page May 14, 2019 
        ·
        1 revision
      
    GraphQL allows you to alias, or rename, elements of your queries. This is built-in and trivial, but a powerful feature that is often overlooked.
To alias, simply prefix the elements you wish to rename with the desired string followed by :, like so:
{
  imaginarium:places(
    id:"UGxhY2VUeXBlOjUxOA==, UGxhY2VUeXBlOjU0Nw==")
  {
    menagerie:edges {
      dogs:node {
        dogtag:id
        place:name
        favoritePizzaPlace:name
      }
    }
  }
}
Which results in:
{
  "data": {
    "imaginarium": {
      "menagerie": [
        {
          "dogs": {
            "dogtag": "UGxhY2VUeXBlOjUxOA==",
            "place": "Dallas, Dallas, Texas, United States",
            "favoritePizzaPlace": "Dallas, Dallas, Texas, United States"
          }
        }
      ]
    }
  }
}