Allow fragments for models with inheritance
See original GitHub issueThe library appears to currently be lacking the ability to use fragments when using models that have subclasses.
models.py
class MyModel(models.Model):
name = models.CharField(max_length=50)
class ModelA(MyModel):
extra = models.IntegerField()
class ModelB(MyModel):
text = models.TextField()
fields.py
class ModelType(DjangoObjectType):
class Meta:
model = MyModel
class ModelAType(DjangoObjectType):
class Meta:
model = ModelA
class ModelBType(DjangoObjectType):
class Meta:
model = ModelB
query
query {
all_models {
__typename,
name,
... on ModelAType {
extra
},
... on ModelBType {
text
}
}
}
Suggestion: Modify DjangoObjectType to also act like a Union, or create a DjangoUnionType, with the ability to resolve type based on subclass and using the registered type for the subclass if applicable.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:8 (1 by maintainers)
Top Results From Across the Web
android - Fragment Inheritance with ViewModel Inheritance
FragmentA and FragmentB both inherit from FragmentParent. ViewModel(A) and ViewModelB both inherit from ViewModelParent. On one side, both ...
Read more >Content Fragment Models | Adobe Experience Manager
Learn how Content Fragment Models serve as a foundation for your headless content in AEM and how to create Content Fragments with structured...
Read more >Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. Here's the declaration of a NameParts...
Read more >Inheritance Basics - Visual Basic | Microsoft Learn
Overriding Properties and Methods in Derived Classes · Overridable — Allows a property or method in a class to be overridden in a...
Read more >Abstract Models and Multi-Table Inheritance - YouTube
This video will dive into 2 methods of model inheritance in Django.1. Abstract Classes2. Multi-Table InheritanceBoth approaches will be ...
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
Any new progress on this? I’m also getting this error when using Django polymorphic.
@japrogramer When I do the above, the type checks for each of those unioned models resolves to the root type or abstract type, at least when using
django-typed-models
and then graphene complains that I have multiple models of the same type.