Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Support Union in DjangoFilterConnectionField and DjangoConnectionField #1537

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

that-one-arab
Copy link

@that-one-arab that-one-arab commented Nov 9, 2024

This issue was previously mentioned here

The purpose of this PR is to make Union types compatible with DjangoFilterConnectionFields so that we can query a root model that is resolved to other model types in runtime, supporting libraries like django-polymorphic

Here's an example of what this PR achieves:

    class AssessmentUnion(DjangoUnionType):
        class Meta:
            model = Assessment
            types = (HomeworkAssessmentNode, QuizAssessmentNode)
            interfaces = (graphene.relay.Node,)
            filter_fields = ("id", "title", "description")
        @classmethod
        def resolve_type(cls, instance, info):
            if isinstance(instance, HomeworkAssessment):
                return HomeworkAssessmentNode
            elif isinstance(instance, QuizAssessment):
                return QuizAssessmentNode


    class Query(graphene.ObjectType):
        all_assessments = DjangoFilterConnectionField(AssessmentUnion)       

Previously, DjangoFilterConnectionField only accepted DjangoObjectTypes and DjangoObjectTypes do not support unions.

Has this PR dependancy that needs merging for the feature to work

NOTE: Tests are failing because it depends on the aforementioned PR!

examples/cookbook/cookbook/urls.py Outdated Show resolved Hide resolved
@that-one-arab
Copy link
Author

@ulgens I made the changes as requested, can you please re-review when you can?

@that-one-arab
Copy link
Author

that-one-arab commented Nov 14, 2024

@ulgens @jaw9c @kiendang @mahdyhamad What are your opinions on this PR? Should I close it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants