question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django graphql query reverse set is listing all available models of that type in my database

See original GitHub issue

Hey 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:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nlhkhcommented, Nov 12, 2016

I think I still see this problem with the latest version. I have to explicitly specify the related_name.

0reactions
syrusakbarycommented, Sep 25, 2016

This should be fixed in the master branch in graphene-django! 😃

(feel free to open the issue there if this problem still occur).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found