hasura / hasura/graphql-engine

Hasura action return type defined as string, but returning an object

Open
#10,206 0 comments 0 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version:
v2.35.1

### Environment
Hasura console, working on docker container

### What is the current behaviour?
We have defined a Hasura action return type like this:
```
type MyReturnData {
id: String!
result: String!
}
```
As you can see that `result` is defined as a type String! but in our backend code which is in nestjs, we are returning result as an object. Hasura action instead of complaining of type mismatch or failing, it is return us result as an object. Even though we have clearly defined result as a string.
To clearify, what we receive back from Hasura is this:
```
{
"data": {
"my_action": {
"mydata": {
"id": "WzEsICJtYWluIiwgImFwcHRfZ3JvdXBfbGF5b3V0IiwgNzdd",
"result": {
"d1": 2,
"d2": {
"d32": [],
"d4": [
{
"records": [],
"uuid": "4b862a88-aa4b-4c25-afe8-7067348fd30c"
},
{
"records": [],
"uuid": "ecbff9e3-02fc-4318-a761-b5ffdbfbf994"
}
]
}
}
}
}
}
}
```
Instead of this:
```
{
"data": {
"my_action": {
"mydata": {
"id": "WzEsICJtYWluIiwgImFwcHRfZ3JvdXBfbGF5b3V0IiwgNzdd",
"result": "{\"d1\":2,\"d2\":{\"d32\":[],\"d4\":[{\"records\":[],\"uuid\":\"4b862a88-aa4b-4c25-afe8-7067348fd30c\"},{\"records\":[],\"uuid\":\"ecbff9e3-02fc-4318-a761-b5ffdbfbf994\"}]}}"
}
}
}
}
```

### What is the expected behaviour?
In this case expected behavior would be one of the following things:
- Either Hasura action don't return result node at all
- Or hasura action returns result node as a stringify object

### How to reproduce the issue?

1. create a Hasura action that have a return type with a variable as a string
2. from backend code preferably javascript backend, return result to Hasura as an object for variable which is defined as a string in Hasura action
3. You will notice that Hasura action return type variable which was defined as a string is returning object as it received from backend

### Any possible solutions/workarounds you're aware of?

We would like to know that is this expected behavior or this is just a bug. Because if this is a bug and we implement our code based on assumption that this is expected behavior. Then in future when this bug is fixed our entire codebase will break. If this is expected behavior then even though this is not right but this will work in our use-case so we may decide to go with this solution.

### Keywords
Hasura action

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the Hasura action described in the issue with a String! return field and a NestJS or JavaScript backend that sends an object. Trace the action response handling and GraphQL type validation, then confirm whether the result should be rejected, omitted, or serialized as a string; add or update coverage for the demonstrated response shape if the relevant test location is found.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, javascript, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.