From 4488fb8fa00f9d4fc61ad5f204c37995da9886f6 Mon Sep 17 00:00:00 2001 From: Marco Perberschlager Date: Mon, 4 Nov 2024 10:42:54 +0100 Subject: [PATCH] Added documentation for aliases --- doc/10_GraphQL/04_Query/06_Operators.md | 3 +- doc/10_GraphQL/04_Query/11_Using_Aliases.md | 37 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 doc/10_GraphQL/04_Query/11_Using_Aliases.md diff --git a/doc/10_GraphQL/04_Query/06_Operators.md b/doc/10_GraphQL/04_Query/06_Operators.md index 9f5397ba..9f940a5b 100644 --- a/doc/10_GraphQL/04_Query/06_Operators.md +++ b/doc/10_GraphQL/04_Query/06_Operators.md @@ -6,7 +6,8 @@ Operators allow to modify and transform the data before it is delivered to the e #### Alias -Simply gives the child node a different name. +Simply gives the child node a different name. +See also [Using Aliases](./11_Using_Aliases.md) for more information on how to use aliases. #### Date Formatter diff --git a/doc/10_GraphQL/04_Query/11_Using_Aliases.md b/doc/10_GraphQL/04_Query/11_Using_Aliases.md new file mode 100644 index 00000000..a3939b97 --- /dev/null +++ b/doc/10_GraphQL/04_Query/11_Using_Aliases.md @@ -0,0 +1,37 @@ +# Using Aliases + +Aliases are used to rename the result of a field. +This is useful when you want to return multiple fields with the same name. + +There are two ways to use aliases: + +## Alias Operator + +See [06_Operators.md](06_Operators.md) for more information. + +## Alias in the Query + +Get a `Car` with id 82 and return the number of doors. +The first value is the alias, the second value is the field name. + +#### Request +```graphql +{ + getCar(id: 82) { + doors: numberOfDoors + } +} +``` + +#### Response +```json +{ + "data": { + "getCar": { + "doors": 2 + } + } +} +``` + +