hasura / hasura/graphql-engine
Aliased fields with type object are dropped from Action response
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.12.0
CLI Version (for CLI related issue): v2.12.0
### Environment
OSS (docker)
### What is the current behaviour?
When aliasing property with type `object` (in mutation response), it is dropped.
Query:
```graphql
mutation GreetingMutation {
greetingResponse: greeting {
a_greeting {
fullName: full_name
nestedLevel: nested_level
b_greeting {
fullName: full_name
nestedLevel: nested_level
"""
⬇️Will be dropped. Same for level aboves
"""
cGreeting: c_greeting {
fullName: full_name
nestedLevel: nested_level
}
}
}
}
}
```
Response (from `/v1/graphql` endpoint running above mutation):
```json
{
"data": {
"greetingResponse": {
"a_greeting": {
"fullName": "object A",
"nestedLevel": 1,
"b_greeting": {
"fullName": "object B",
"nestedLevel": 2
}
}
}
}
}
```
### What is the expected behaviour?
Response should have the nested object `cGreeting`:
```json
{
"data": {
"greetingResponse": {
"a_greeting": {
"fullName": "object A",
"nestedLevel": 1,
"b_greeting": {
"fullName": "object B",
"nestedLevel": 2,
"cGreeting": {
"fullName": "object C",
"nestedLevel": 3
}
}
}
}
}
}
```
### How to reproduce the issue?
Here a sample repo to reproduce the issue: https://github.com/aminebeh/hasura-actions-alias-bug
- Start nodejs server:
```zsh
cd functions/nodejs-express
npm install
npm start
```
> Route for our action is /greet
- Start graphql server:
```zsh
docker-compose up -d
docker exec -it /bin/bash
cd /hasura
hasura-cli migrate apply
hasura-cli metadata apply
```
- Run action:
```zsh
curl --location --request POST 'localhost:8080/v1/graphql' \
--header 'Content-Type: application/json' \
--header 'Cookie: permission_variables=%7B%22user-id%22%3A%22964580a4-cc08-4adf-9e48-af17e5f58754%22%2C%22allowed-roles%22%3A%5B%22user%22%2C%22ads-manager_user%22%2C%22third-party_user%22%2C%22ikenga_user%22%2C%22ikenga_admin%22%5D%2C%22default-role%22%3A%22user%22%7D; refresh_token=f4a42085-b9ac-4a7e-b817-25b17ea6e542' \
--data-raw '{
"query": "\nmutation GreetingMutation {\n greetingResponse: greeting {\n a_greeting {\n fullName: full_name\n nestedLevel: nested_level\n b_greeting {\n fullName: full_name\n nestedLevel: nested_level\n cGreeting: c_greeting { \n fullName: full_name\n nestedLevel: nested_level\n }\n }\n }\n }\n}\n"
}'
```
> You can import the request above in Postman
### Screenshots or Screencast
- Without **aliasing**:

- With **aliasing**:

### Any possible solutions?
Related to: https://github.com/hasura/graphql-engine/issues/7056
Contributor guide
Research direction
Start with the reproduction repository's functions/nodejs-express service and the docker-compose setup, then run the supplied mutation against the /v1/graphql endpoint. Compare aliased and unaliased nested object fields in the response, using the Hasura CLI migration and metadata commands to reproduce the action configuration. Done means the cGreeting alias and its nested fields are preserved in the mutation response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker-compose, graphql, nodejs
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100