hasura / hasura/graphql-engine
HGE 1.1 -- simple join and sort not working as expected
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
THE SETUP
----------
The basic idea is I have a products table (with a studycategory_id field) and a studycategories table.
And the studycategories is keyed on sc_id and language. Each product has ONE studycategory.
And below I am asking hasura to show me just the products matching:
1-- one user (user_id=1)
2-- one studycategory (sc_id=3)
3-- one language for the category selected ... language=es)
I purposely use an object relationship 'join_studycategory' because I want to sort the products that match by category
(And BTW, this is in HGE v1.1.0, in the console, as admin not a user.)
MY QUERY
-----------
```
query {
ts_myproducts(
order_by:{join_studycategory:{category:asc}}
where:{
_and:[
{user_id:{_eq:1}},
{study_category_id:{_eq:3}},
{join_studycategory:{language:{_eq: "es"}}}
]}
) {
id
user_id
join_studycategory{
id
sc_id
language
category
subcategory
}
}
}
```
MY RESULTS (close, but ???)
---------------------------
I correctly get just the products for one user in that one category (there is only one product -- id 41), but I (incorrectly) get 2 languages! en and es even though I asked for just es.
```
{
"data": {
"ts_myproducts": [
{
"id": 41,
"user_id": 1,
"join_studycategory": {
"id": 4,
"sc_id": 3,
"language": "en",
"category": "Cosmetics",
"subcategory": "Eye liner"
}
},
{
"id": 41,
"user_id": 1,
"join_studycategory": {
"id": 90,
"sc_id": 3,
"language": "es",
"category": "Cosméticos",
"subcategory": "Delineador de ojos"
}
}
]
}
}
```
BUG?
-------
This seems like a bug and that hasura is not translating my graphQL properly.
I am just doing the equivalent of a simple join which works fine in postgres:
```
SELECT p.id, p.user_id, sc.sc_id, sc.language, sc.category, sc.subcategory
FROM ts_products p
LEFT JOIN studycategories c ON p.studycategory_id = c.sc_id
WHERE p.user_id=1 AND sc.sc_id = 3 AND sc.language = 'es'
ORDER BY sc.category ASC
```
AND BTW
------------
as you probably already know, if I change the graphQL to an array relationship and remove the order by, the problem remains -- I still get en and es results -- now just together in a json array instead of the flatter result I get above with the object relationship
```
{
"data": {
"ts_myproducts": [
{
"id": 41,
"user_id": 1,
"join_studycategories": [
{
"id": 4,
"sc_id": 3,
"language": "en",
"category": "Cosmetics",
"subcategory": "Eye liner"
},
{
"id": 90,
"sc_id": 3,
"language": "es",
"category": "Cosméticos",
"subcategory": "Delineador de ojos"
}
]
}
]
}
}
```
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.