graphql-python / graphql-python/graphene-django

Proxied models dont have associated many to many relationship access

Open
#1,379 0 comments 0 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

This issue is loosely related to https://github.com/graphql-python/graphene-django/issues/319 to provide further support for proxy models

* **What is the current behavior?**

Currently, django models that are a proxy of another model don't include their many to many relationships that you get by default without proxy

So if my models.py looks like this

```python
# models.py

from django.db import models

class Publication(models.Model):
...

class SciencePublication(Publication):
class Meta:
proxy = True

class Article(models.Model):
publications = models.ManyToManyField(
Publication,
related_name="articles"
)
```

and my graphene types in types.py

```python
# types.py

import graphene_django
from .models import (
Publication as PublicationModel,
SciencePublication as SciencePublicationModel
)

class Publication(graphene_django.DjangoObjectType):
class Meta:
model = PublicationModel

class SciencePublication(graphene_django.DjangoObjectType):
class Meta:
model = SciencePublicationModel
```

When attempting to access the `articles` relationship through the publication type in the graphql query I can only access it via the Publication graphql type but not through the SciencePublication type

this is fine...
```gql
query {
getPublications() {
articles {
id
}
}
}
```
this is errors
```gql
query {
getSciencePublications() {
articles { <<<< cannot query field "articles" on type "SciencePublication"
id
}
}
}
```

* **What is the expected behavior?**

many to many relationships persist with proxy models so that this query doesn't error
```gql
query {
getSciencePublications() {
articles { # no errors, just smiles :)
id
}
}
}
```

* **Please tell us about your environment:**

- Version: 3.0.0b7

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.