hasura / hasura/graphql-engine
Adding relations to action payloads breaks scalar arrays
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 2.0.7
### Environment
Tested on locally hosted container, OSS
### What is the expected behaviour?
When defining payload types for actions, it is possible to define scalar arrays as part of the payload (object types are not allowed)

I can then populate this field with an array of scalar values, and it will work as expected
```js
// Request Handler
app.post('/authenticate', async (req, res) => {
// get request input
const { username, password } = req.body.input;
// run some business logic
/*
// In case of errors:
return res.status(400).json({
message: "error happened"
})
*/
// success
return res.json({
token: "",
user_id: 1,
username: "admin",
roles: ["admin", "user"] // note the array
})
});
```
Note how the `roles` field is an array of strings

Up to now this is all expected behavior.
### Keywords
Scalar Array Action Payload Relation
### What is the current behaviour?
When a relation is added to the action payload, the scalar arrays will be converted json strings.
This happens even if the relation itself is not being queried

Note the `roles` field is now an escaped json string. This is unexpected.

This is very niche behavior, but I thought it best it be documented.
Contributor guide
Research direction
Start at the action payload and relation behavior described in the issue, reproducing it through the shown request handler with a scalar array such as roles. Compare responses before and after adding a relation, including when the relation is not queried; done means scalar arrays remain arrays rather than becoming escaped JSON strings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100