Skip to content

using interface with polymorphic models #313

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

Closed
kimutaiRop opened this issue Jul 19, 2021 · 2 comments
Closed

using interface with polymorphic models #313

kimutaiRop opened this issue Jul 19, 2021 · 2 comments

Comments

@kimutaiRop
Copy link

kimutaiRop commented Jul 19, 2021

I have some polymorphic models


class A(Base):
    name = Column()


class B(A):
    for_b = Column()


class C(A):
    for_c = Column()

I then made graphql object for them like this

class Ainterface(Interface):
    name = String()
   
    class Meta:
        interfaces = (Node,)

class AType(SQLAlchemyObjectType):
    class Meta:
        interfaces = (Ainterface)
        model = A


class BType(SQLAlchemyObjectType):
    class Meta:
        interfaces = (Ainterface)
        model = B


class CType(SQLAlchemyObjectType):
    class Meta:
        interfaces = (Ainterface)
        model = C

class AllObjects(Union):

    @classmethod
    def resolve_type(cls, instance, info):
        if isinstance(instance, A):
            return AType
        if isinstance(instance, B):
            return BType
        if isinstance(instance, C):
            return CType
    class Meta:
       types = (AType, BType,CType)

what hurts is the fact that even though name is shared in all the children of class A
i cannot do something like this

{
    objects: {
            name
        ... on BType {
            for_b
        }
        ... on CType {
            for_c
        }
    }
}

to query the data, is there a way that I can work this to be able to query

@erikwrede
Copy link
Member

This was implemented in #365 thanks to @polgfred! Please check out the new documentation 🙂

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants