Skip to content

Abstract ObjectTypes don't have a specific type. #84

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
Grmiade opened this issue Jan 21, 2016 · 15 comments
Closed

Abstract ObjectTypes don't have a specific type. #84

Grmiade opened this issue Jan 21, 2016 · 15 comments

Comments

@Grmiade
Copy link

Grmiade commented Jan 21, 2016

I have this error, when I add a second inheritance class in my main Query.

class Query(trainings.schema.Query, brainstormers.schema.Query):
    """This class will inherit from multiple Queries as we begin to add more apps to our project."""

    pass

schema = graphene.Schema(name='MTP Schema')
schema.query = Query
@syrusakbary
Copy link
Member

Are the inherited classes (trainings.schema.Query and brainstormers.schema.Query) abstract?

By abstract I meant this:

# In trainings/schema.py
class Query(graphene.ObjectType):
    class Meta:
        abstract = True

Check this comment in a related issue: #55 (comment)
;)

Going to close this issue, but feel free to reopen if is not working for you!

@Grmiade
Copy link
Author

Grmiade commented Jan 21, 2016

Yes my classes are abstracts like this.

class BrainstormerNode(DjangoNode):

    class Meta:
        model = Brainstormer
        filter_order_by = ['name']


class BrainstormerPropositionGroupNode(DjangoNode):

    class Meta:
        model = BrainstormerPropositionGroup
        filter_order_by = ['name']


class Query(ObjectType):

    class Meta:
        abstract = True

    brainstormer = relay.NodeField(BrainstormerNode)
    all_brainstormer = DjangoFilterConnectionField(BrainstormerNode)

    brainstormer_proposition_group = relay.NodeField(BrainstormerPropositionGroupNode)
    all_brainstormer_proposition_group = DjangoFilterConnectionField(BrainstormerPropositionGroupNode)

and

class TrainingSessionNode(DjangoNode):

    class Meta:
        model = TrainingSession


class Query(ObjectType):

    class Meta:
        abstract = True

    sessions = relay.NodeField(TrainingSessionNode)
    all_sessions = DjangoFilterConnectionField(TrainingSessionNode)

An idea ?

@syrusakbary
Copy link
Member

@Grmiade Can you copy the output of the error here?

@Grmiade
Copy link
Author

Grmiade commented Jan 21, 2016

Sure.

ERROR Internal Server Error: /graphql
Traceback (most recent call last):
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py", line 30, in inner
    return func(*args, **kwds)
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/django/views/generic/base.py", line 65, in view
    self = cls(**initkwargs)
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/contrib/django/views.py", line 10, in __init__
    schema=schema.schema,
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/core/schema.py", line 83, in schema
    query=self.T(self.query),
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/core/schema.py", line 58, in T
    internal_type = _type.internal_type(self)
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/core/classtypes/uniontype.py", line 37, in internal_type
    types=list(map(schema.T, cls._meta.types)),
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/core/schema.py", line 58, in T
    internal_type = _type.internal_type(self)
  File "/Users/jeremyfauvel/.virtualenvs/mtp/lib/python3.4/site-packages/graphene/core/classtypes/objecttype.py", line 91, in internal_type
    raise Exception("Abstract ObjectTypes don't have a specific type.")
Exception: Abstract ObjectTypes don't have a specific type.

@syrusakbary syrusakbary reopened this Jan 21, 2016
@syrusakbary
Copy link
Member

Reopening the issue as the previous fix #55 was invalidated by a major refactor.
This issue will be fixed very soon (few minutes).

@Grmiade
Copy link
Author

Grmiade commented Jan 21, 2016

Thanks.

@syrusakbary
Copy link
Member

@Grmiade A new version of graphene is uploaded to PyPI 0.6.1... use it and everything should be fine! ;)
https://pypi.python.org/pypi/graphene/0.6.1

@Grmiade
Copy link
Author

Grmiade commented Jan 21, 2016

It's work !
So fast ! Thank you so much ;)

@greenteamer
Copy link

Hello, i have the same 500 error in 0.7.3 version when trying
query { allNotes { edges { node { id, title } } } }

this is my schema

class NotesNode(DjangoNode):
    class Meta:
        model = Notes
        filter_fields = ['title',]
        filter_order_by = ['title']
class Query(ObjectType):
    note = relay.NodeField(NotesNode)
    all_notes = DjangoFilterConnectionField(NotesNode)

    class Meta:
        abstract = True
schema = graphene.Schema(name='Notes Schema')
schema.query = Query

and this is my model

class Notes(models.Model):
    title   = models.CharField(max_length=100)
    text    = models.TextField()

    def __str__(self):
        return self.title

@syrusakbary
Copy link
Member

@greenteamer could you detail a little bit more?

A stacktrace of the Exception or the output of the /graphql endpoint when querying would be useful :)

@greenteamer
Copy link

Traceback (most recent call last):
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/django/core/handlers/base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/django/core/handlers/base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/django/views/generic/base.py", line 62, in view
    self = cls(**initkwargs)
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/graphene/contrib/django/views.py", line 10, in __init__
    schema=schema.schema,
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/graphene/core/schema.py", line 86, in schema
    query=self.T(self.query),
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/graphene/core/schema.py", line 61, in T
    internal_type = _type.internal_type(self)
  File "/Users/greenteamer/Desktop/Django/env/monolit/lib/python2.7/site-packages/graphene/core/classtypes/objecttype.py", line 96, in internal_type
    raise Exception("Abstract ObjectTypes don't have a specific type.")
Exception: Abstract ObjectTypes don't have a specific type.

@syrusakbary
Copy link
Member

@greenteamer The final query type used in the schema should not be abstract.
Try with:

class Query(ObjectType):
    note = relay.NodeField(NotesNode)
    all_notes = DjangoFilterConnectionField(NotesNode)

(without the Meta)

@syrusakbary
Copy link
Member

The abstract queries bases should only be used when we inherit the final Query type from them.

Example:

class QueryNotes(ObjectType):
    note = relay.NodeField(NotesNode)
    all_notes = DjangoFilterConnectionField(NotesNode)
    class Meta:
         abstract = True

class QueryUsers(ObjectType):
    user = relay.NodeField(UserNote)
    all_users = DjangoFilterConnectionField(UserNote)
    class Meta:
         abstract = True

class Query(QueryNotes, QueryUsers):
    pass

schema = graphene.Schema(name='My Schema')
schema.query = Query

@greenteamer
Copy link

wow ... this is amasing!!! thank you !!! you did a great job

@jcouser
Copy link

jcouser commented Aug 16, 2017

Hi,

I wasn't sure where this comment was best placed. Which is also in:
#55

I'm attempting to create this level of abstraction as well. I'm using graphql-sqlalchemy and when I do something like:

class UserGroupMember(SQLAlchemyObjectType):
    class Meta:
        abstract = True
        model = UserGroupMemberModel
        interfaces = (CustomNode, )

I'm getting the following error:

TypeError: Invalid attributes: abstract

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

No branches or pull requests

4 participants