From 9de6e9ee28709841dd2b3d4c5a349f95153f7fb0 Mon Sep 17 00:00:00 2001 From: changeling Date: Tue, 14 May 2019 17:40:29 -0500 Subject: [PATCH] Initial page creation. --- Aliasing-(rename-query-elements).md | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Aliasing-(rename-query-elements).md diff --git a/Aliasing-(rename-query-elements).md b/Aliasing-(rename-query-elements).md new file mode 100644 index 0000000..1a0b619 --- /dev/null +++ b/Aliasing-(rename-query-elements).md @@ -0,0 +1,37 @@ +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" + } + } + ] + } + } +} +``` \ No newline at end of file