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.

Allow fragments for models with inheritance

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
cfarvidsoncommented, Mar 20, 2018

Any new progress on this? I’m also getting this error when using Django polymorphic.

1reaction
MichaelrMentelecommented, Sep 25, 2017

@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.

image

Read more comments on GitHub >

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

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