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

Some clarity on how to define abstract types #1039

Closed
fhennig opened this issue Jul 19, 2019 · 3 comments
Closed

Some clarity on how to define abstract types #1039

fhennig opened this issue Jul 19, 2019 · 3 comments
Labels

Comments

@fhennig
Copy link

fhennig commented Jul 19, 2019

I have different entities in my project, and want to split up my Query ObjectType into multiple classes.

How should I do that?

There seem to be three ways of doing it:

  1. Just use inheritance as usual:
class UserQueries(graphene.ObjectType):
    ...

class OtherQueries(graphene.ObjectType):
    ...

class Queries(UserQueries, OtherQueries):
    pass
  1. Using the AbstractType:
class UserQueries(graphene.AbstractType):
    ...

class OtherQueries(graphene.AbstractType):
    ...

class Queries(graphene.ObjectType, UserQueries, OtherQueries):
    pass
  1. Using the abstract = True attribute:
class UserQueries(graphene.ObjectType):
    class Meta:
        abstract = True
    ...

class OtherQueries(graphene.ObjectType):
    class Meta:
        abstract = True
    ...

class Queries(UserQueries, OtherQueries):
    pass

And this can apparently also be given as a class argument like so:

class UserQueries(graphene.ObjectType, abstract=True):
    ...

The documentation says to use 2., but in the v2 release notes it says that AbstractType is deprecated. In the same document it uses method 3., but I couldn't find any documentation for that.

I started to just use normal inheritance and it seems to work.

How should it be done?

Probably related to #823

@KaySackey
Copy link

If you are on Python3, you can use abstract=True without any problems. I believe AbstractType is your only option on Python2.

@stale
Copy link

stale bot commented Oct 9, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Oct 9, 2019
@stale stale bot closed this as completed Oct 16, 2019
@odigity
Copy link

odigity commented Jun 28, 2022

I'm confused. "abstract = True" isn't mentioned anywhere in the Graphene docs. Is that an official object option, and what behavior does it result in?

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

No branches or pull requests

3 participants