Django graphql query reverse set is listing all available models of that type in my database
See original GitHub issueHey guys, love what you’re working on! I’ve run into an issue that I’m seems like a bug.
I have two models address and building
class Address(models.Model):
street_number = models.TextField(default='')
route = models.TextField(default='')
class Building(models.Model):
address = models.ForeignKey(Address)
And when I query to see what buildings are pointing to my addresses, I get every building in my database returned when I’m only expecting one. (theres a reason i’m not using a 1-to-1 field)
This doesn’t happen when I use the example project. And I’m following it closely so I have no idea what could be the issue.
this is what my nodes and query object look like
class AddressNode(DjangoNode):
class Meta:
model = Address
# Allow for some more advanced filtering here
fields = {
'route': ['exact', 'icontains'],
'street_number': ['exact', 'icontains'],
'buildings': ['exact']
}
class BuildingNode(DjangoNode):
class Meta:
model = Buildings
# Allow for some more advanced filtering here
filter_fields = {
'address__route': ['exact', 'icontains'],
'address__street_number': ['exact', 'icontains'],
'address': ['exact'],
}
class Query(ObjectType):
building = relay.NodeField(BuildingNode)
all_buildings = DjangoFilterConnectionField(BuildingNode)
addresses = relay.NodeField(AddressNode)
all_addresses = DjangoFilterConnectionField(AddressNode)
class Meta:
abstract = True
And this is what my query looks like on http://localhost:8000/graphiql
query{
allAddresses(route: "Sansome St", first:1 ) {
edges {
node {
streetNumber
route,
buildings {
edges {
node {
id
}
}
},
}
}
}
}
I should be getting back exactly one building, but I’m getting all 200 in my database. Am I missing something, or is there something wrong?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
How to build GraphQL schema for reverse lookup from ...
Each profile has its own url, so I use ContentType as a central place of mappring urls<->profiles. # profiles/models.py class Sport(models.Model): ...
Read more >Django + Graphene: From REST to GraphQL - FullStack Labs
This walk-through demonstrates the power of using Graphene with Django by covering the basics, testing, and more advanced features.
Read more >Queries & ObjectTypes - Graphene-Python
DjangoObjectType will present all fields on a Model through GraphQL. If you only want a subset of fields to be present, you can...
Read more >Making queries | Documentation de Django
A QuerySet represents a collection of objects from your database. It can have zero, one or many filters. Filters narrow down the query...
Read more >Search and Filtering - GraphQL - Dgraph
Queries generated for a GraphQL type allow you to generate a single list of ... The in filter is supported for all data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I still see this problem with the latest version. I have to explicitly specify the
related_name
.This should be fixed in the
master
branch in graphene-django! 😃(feel free to open the issue there if this problem still occur).