hasura / hasura/graphql-engine

Fetching object relationships in alias gives non deterministic return

Open
#9,547 1 comment 4 reactions 0 assignees View on GitHub
k/bug t/native-dbs
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: 2.17.0

### Environment

OSS

### What is the current behaviour?

When fetching an object relationship using both the column name and an alias, Hasura uses the first one specified and ignore the second one:
```graphql
query ($id: uuid!) {
user_by_pk(id: $id) {
todo_items {
created_by {
id
}
}
__test: todo_items {
created_by {
name
}
}
}
}
```
Will return:
```json
{
"data": {
"user_by_pk": {
"todo_items": [
{
"created_by": {
"id": "00000000-0000-0000-0000-000000000000"
}
}
],
"__test": [
{
"created_by": {
"id": "00000000-0000-0000-0000-000000000000"
}
}
]
}
}
}
```

### What is the expected behaviour?

The query from above to return:
```json
{
"data": {
"user_by_pk": {
"todo_items": [
{
"created_by": {
"id": "00000000-0000-0000-0000-000000000000"
}
}
],
"__test": [
{
"created_by": {
"name": "John"
}
}
]
}
}
}
```

### How to reproduce the issue?

See above.

Extra info:
- If `created_by` would be an array relationship it does work correctly and you get:

```json
{
"data": {
"user_by_pk": {
"todo_items": [
{
"created_by": [{
"id": "00000000-0000-0000-0000-000000000000"
}]
}
],
"__test": [
{
"created_by": [{
"name": "John"
}]
}
]
}
}
}
```

- If you then fetch more relations in the `created_by` relation Hasura fully crashes with a `FatalError: "column reference \"relevant_for\" is ambiguous"`:
```graphql
query ($id: uuid!) {
user_by_pk(id: $id) {
todo_items {
created_by {
id
relevant_for {
id
}
}
}
__test: todo_items {
created_by {
name
relevant_for {
name
}
}
}
}
}
```

Potential related issue: https://github.com/hasura/graphql-engine/issues/9009

### Keywords

Alias

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.