Mocca should support GraphQL fields alias for queries.
The biggest advantage of this feature is to support multiple GraphQL queries inside a single request. That is only possible when field alias are used, so the data set in the response can differentiate the returned value for each query.
Supported use cases
All use cases described in the next sections should be supported as part of the scope of this issue.
Using Field Alias to send multiple queries inside the same request
Notice that the biggest advantage of this feature is to support multiple GraphQL queries inside a single request. That is only possible when field alias are used, so the data set in the response can differentiate the returned value for each query.
Request:
{
zuck: user(id: 4) {
id
name
}
jdoe: user(id: 5) {
id
name
}
}
When sending multiple queries inside the same request (using file alias), the user can leave one, and only one, query still named with the default query name, as seen in the example below.
Request:
{
user(id: 4) {
id
name
}
jdoe: user(id: 5) {
id
name
}
}
Even when the user just wants to send one single query (as in the example below), still Mocca should supports field alias.
Request:
{
zuck: user(id: 4) {
id
name
}
}
Response:
{
"jdoe": {
"id": 5,
"name": "John Doe"
}
}
Using Field Alias with mutations
As part of this issue, research if GraphQL also supports Field Alias for mutations (allowing multiple mutations in the same request) and even hybrid requests (containing multiple mutations and queries making use of field alias). If GraphQL does support one or both of these scenarios, then they also have to be implemented as part of this issue.
Use cases NOT in the scope of this story
Using Field Alias inside of Selection Sets
In the supported use cases described previously, GraphQL field alias are used only to the queries (as queries are also considered fields in GraphQL). However, it is important to notice that in GraphQL field alias can also be applied to the fields set inside of the selection sets (as seen example below). This particular use case is NOT covered in this issue, it will covered in a separated issue.
{
user(id: 4) {
id
name
smallPic: profilePic(size: 64)
bigPic: profilePic(size: 1024)
}
}
Introduction
Mocca should support GraphQL fields alias for queries. The biggest advantage of this feature is to support multiple GraphQL queries inside a single request. That is only possible when field alias are used, so the data set in the response can differentiate the returned value for each query.
Supported use cases
All use cases described in the next sections should be supported as part of the scope of this issue.
Using Field Alias to send multiple queries inside the same request
Notice that the biggest advantage of this feature is to support multiple GraphQL queries inside a single request. That is only possible when field alias are used, so the data set in the response can differentiate the returned value for each query.
Request:
Response:
Using Field Alias to all but one query
When sending multiple queries inside the same request (using file alias), the user can leave one, and only one, query still named with the default query name, as seen in the example below.
Request:
Response:
Using Field Alias to send only one query
Even when the user just wants to send one single query (as in the example below), still Mocca should supports field alias.
Request:
Response:
Using Field Alias with mutations
As part of this issue, research if GraphQL also supports Field Alias for mutations (allowing multiple mutations in the same request) and even hybrid requests (containing multiple mutations and queries making use of field alias). If GraphQL does support one or both of these scenarios, then they also have to be implemented as part of this issue.
Use cases NOT in the scope of this story
Using Field Alias inside of Selection Sets
In the supported use cases described previously, GraphQL field alias are used only to the queries (as queries are also considered fields in GraphQL). However, it is important to notice that in GraphQL field alias can also be applied to the fields set inside of the selection sets (as seen example below). This particular use case is NOT covered in this issue, it will covered in a separated issue.