ManyToMany relation with wrong type
See original GitHub issueI got into an issue with DjangoObjectType
to convert a Django model into a GraphQL type ; On many to many relationships I get a list of the model owning the relation instead of the related model.
Here are the models to reproduce the issue
from django.db import models
class Child(models.Model):
pass
class Parent(models.Model):
children = models.ManyToManyField(Child)
and the schema definition
import graphene
from graphene_django import DjangoObjectType
from . import models
class Child(DjangoObjectType):
class Meta:
model = models.Child
class Parent(DjangoObjectType):
class Meta:
model = models.Parent
class Query(graphene.ObjectType):
parents = graphene.List(Parent)
def resolve_parents(self, args, context, info):
return models.Parent.objects.all()
schema = graphene.Schema(query=Query)
And the test file
import graphene
from django.test import TestCase
from graphene_django.fields import DjangoListField
from . import schema
class M2MTestCase(TestCase):
def setUp(self):
schema.schema.build_typemap()
# get the graphql type for the field related to the children
self.field_type = schema.Parent._meta.fields['children'].get_type()
def test_graphql_types(self):
# we must get a django list field
self.assertEquals(isinstance(self.field_type, DjangoListField), True)
# behind it we've a graphql list
self.assertEquals(isinstance(self.field_type.type, graphene.List), True)
# it must be a list of Child
self.assertEquals(self.field_type.type.of_type, schema.Child)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Wrong column type in jpa many to many relationship
I found my mistake : The wrong type was because of a field type in my database.
Read more >Many-to-many relationships - Django documentation
Many-to-many relationships¶. To define a many-to-many relationship, use ManyToManyField . ... Adding an object of the wrong type raises TypeError :.
Read more >Many-to-many relationships in Power BI Desktop
It's now possible to set the relationship cardinality to many-to-many. This setting indicates that neither table contains unique values. For ...
Read more >Many-to-Many Relationships - Knowing and Avoiding Them
Denormalizing data will require extensive data duplication, row duplication, and result in exponential growth of the database size. For example: ...
Read more >Hibernate Tips: How to map a bidirectional many-to-many ...
Multiple Authors can write multiple books and a book can be written by one or more authors. That's a typical many-to-many association, and...
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 FreeTop 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
Top GitHub Comments
So far the only workaround I got is to override the definition myself
But I believe we should not have to do that to make it works.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.