hasura / hasura/graphql-engine
Mutation action returns arrays as string instead of plain array, if relation exists
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
I've created the following schema and action:
```sql
CREATE TABLE users (
id serial primary key,
name text not null
);
INSERT INTO users (name) VALUES ('Max Mustermann');
```
* Action definition
```gql
type Mutation {
arrayTest : [SampleOutput]
}
```
* Custom types
```gql
type ArrayTestOutput {
user_id : ID!
tool_ids : [ID!]!
}
```
* query
```gql
mutation array_test {
arrayTest {
user_id
tool_ids
}
}
```
The action redirects to the following express app:
```js
const express = require('express')
const app = express()
app.set("host", "0.0.0.0");
const port = 3000
app.post("/array_test", async (req, res) => {
console.log('array test started')
res.json([{
user_id: 1,
tool_ids: [1, 2, 3]
}]);
});
app.listen(port, () => {
console.log(`Example app listening at http://0.0.0.0:${port}`)
})
```
If the action has no (object) relationship with `users` defined, the mutations results into:
```json
{
"data": {
"arrayTest": [
{
"user_id": 1,
"tool_ids": [
1,
2,
3
]
}
]
}
}
```
if an (object) relationship exists, the `tool_ids` are returned as json string instead of an array:
```json
{
"data": {
"arrayTest": [
{
"user_id": 1,
"tool_ids": "[1, 2, 3]"
}
]
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.