graphql-python / graphql-python/graphene-django
DjangoFilterConnectionField does not use source arg
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
Using the [starwars example app](https://github.com/graphql-python/graphene-django/tree/master/examples/starwars) for explanation.
* **What is the current behavior?**
The `DjangoFilterConnectionField` does not use `source` arg, it only works on field name.
* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem**
Add a `DjangoFilterConnectionField` `factions` to `schema.Query`:
```
class Query(graphene.ObjectType):
factions = DjangoFilterConnectionField(Faction)
```
Add a `DjangoFilterConnectionField` `our_ships` to `schema.Faction` with its `related_name` in `source`:
```
class Faction(DjangoObjectType):
our_ships = DjangoFilterConnectionField(Ship, source="ships")
```
Insert two Factions with one ship each to the db, e.g.:
```
dummy = Character.objects.create(name="dummy")
rebels = Faction.objects.create(name="Rebels", hero=dummy)
empire = Faction.objects.create(name="Empire", hero=dummy)
Ship.objects.create(name="X-Wing", faction=rebels)
Ship.objects.create(name="Death Star", faction=empire)
```
The following query will return both ships, instead of only the X-Wing:
```
{
factions(name: "Rebels") {
edges {
nodes {
name
ships {
edges {
nodes {
name
}
}
}
}
}
}
}
```
* **What is the expected behavior?**
The query should only return the X-Wing ship.
* **What is the motivation / use case for changing the behavior?**
If you add field `ships` to `schema.Faction` instead of using `source`, it works as intended:
```
class Faction(DjangoObjectType):
ships = DjangoFilterConnectionField(Ship)
```
* **Please tell us about your environment:**
- Version: graphene 2.1.8, graphene-django 2.9.1, graphql-core 2.3.1, graphql-relay 2.0.1
- Platform: python 3.6.7 on WSL, python 3.7.4 on Windows
* **Other information**
Contributor guide
Assessment
This issue has not been assessed yet.