Observation in my app:
I have a contacts page where contacts can have tags and the same tag is shown shown multiple times.
I checked the dev api and saw that it only happens when using the "related type" (TagListConnection via contact tags field.)
Using a tags query directly works. (not via related type)
Using no filter yields duplicate nodes.
Using the related one while a filter is active does work.
Using the DISTINCT filter does not work. (also shows the duplicates)
Example:
This is the SQL for the following query:
query ContactsTags {
contacts(last: 1) {
totalCount
edges {
node {
id
name
tags(filters: {DISTINCT: true}) {
totalCount
edges {
node {
id
name
}
}
}
}
}
}
}
The result shoes 8 duplicate tags.
{
"data": {
"contacts": {
"totalCount": 63,
"edges": [
{
"node": {
"id": "SOMEID==",
"name": "Carmen",
"tags": {
"totalCount": 8,
"edges": [
{
"node": {
"id": "VGFnOjYy",
"name": "target"
}
},
{
"node": {
"id": "VGFnOjYy",
"name": "target"
}
},
... // 5 more here
{
"node": {
"id": "VGFnOjYy",
"name": "target"
}
}
]
}
}
}
]
}
}
}
Using the django debug toolbar while running the query shows the following SQL information:
strawberry-graphql-django = "^0.49.1"
strawberry-graphql = "^0.247.0"
According to @bellini666 the general underlying issue of duplicates due to SQL is known.
Conversation snipet for context:
Basically, if you try to filter the relation through the original model, the join will generate spurious tuples. What you need to do in this case is to filter through a subquery with exists
BUT, having said that, I see that you used DISTINCT, which should also work
Can you check in the generated SQL if the distinct was not applied there? If not, then you just found a bug π
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too