Skip to content

Feature: Support Union in DjangoFilterConnectionField and DjangoConnectionField #1537

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

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!

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

@waema
Copy link

waema commented Apr 16, 2025

this feature would be really helpful. any chance we can get some sort of update on this.
@ulgens @jaw9c @kiendang @mahdyhamad

@ulgens
Copy link
Collaborator

ulgens commented Apr 16, 2025

@that-one-arab @waema I don't have my maintainer rights anymore and I can't help to move this forward.

That being told, I wouldn't recommend spending time on graphene anymore. The project was dead ~6 years ago, I tried to keep it alive for a brief of period of time and it didn't work. Not having the repo archived is just misleading at this point.

Another related discussion can be found here: #1394 (comment)

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.

None yet

3 participants