hasura / hasura/graphql-engine

Adding relations to action payloads breaks scalar arrays

Open
#7,581 0 comments 0 reactions 0 assignees View on GitHub
c/actions c/server k/bug p/high
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)

![image](https://user-images.githubusercontent.com/25712958/134077059-4ff34527-88bd-496a-844a-11b24ba46718.png)

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
![image](https://user-images.githubusercontent.com/25712958/134077461-5ad84bee-39b9-4b21-be48-b05848e4d5c1.png)

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

![image](https://user-images.githubusercontent.com/25712958/134077899-37735167-b4c1-4e42-8235-53d311ca62c1.png)
Note the `roles` field is now an escaped json string. This is unexpected.
![image](https://user-images.githubusercontent.com/25712958/134077934-1df1f06c-fbc3-42c5-a233-034323572234.png)

This is very niche behavior, but I thought it best it be documented.

Contributor guide

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.