space-cloud
space-cloud copied to clipboard
Return object instead of array in case of object links while using the new join syntax
Describe the bug
I have the following schema:
type users {
id: ID! @primary
name: String
email: String
address: address @link(table: address, from: id, to: user_id)
}
type address {
id: ID! @primary
address: String
user_id: ID @foreign(table: users, field: id)
}
On executing this query:
{
users(join: [{type: "LEFT", table: "address", on: {users__id: "address__user_id"}}]) @db {
id
name
address {
address
}
}
}
I get this result:
{
"data": {
"users": [
{
"address": [
{
"address": "Jayesh's address"
}
],
"id": "1",
"name": "Jayesh"
},
{
"address": [
{
"address": "Noorain's address"
}
],
"id": "2",
"name": "Noorain"
}
]
}
}
I was expecting the address
to be an object rather than an array since it was an object link and not an array link.
Interestingly this problem arises only when using the new join
argument. If we simply use the links, then this probklem doesn't arise.
Expected behaviour
The address
field should have been an object in the result
How can we solve it?
In the post process, access the link with the corresponding name from the schema and as per that either keep the field as array or object.
Your environment
- Space Cloud version:
v0.19.6
- Database: Postgres
If this bug restricts your use of space-cloud, give it a thumbs up reaction, so that we can determine which bugs need to be fixed immediately. 👍