Skip to content

Queries do not support multiple inheritance #55

Closed
@adamcharnock

Description

@adamcharnock

Use Case: splitting out query definition logic into smaller and more manageable files (e.g. in Django app directories)

Something like this will not currently work:

schema = graphene.Schema(name='Swiftwind Schema')


class Query1(ObjectType):
    all_accounts = relay.ConnectionField(accounts_nodes.Account)
    account = relay.NodeField(accounts_nodes.Account)


class Query2(ObjectType):
    all_transactions = relay.ConnectionField(accounts_nodes.Transaction)
    transaction = relay.NodeField(accounts_nodes.Transaction)


class Query3(ObjectType):
    all_users = relay.ConnectionField(accounts_nodes.User)
    resolve_all_users = ConnectionResolver(accounts_nodes.User)


class Query(Query1, Query2, Query3):
    pass


schema.query = Query

It dies with the following error:

  File "/Users/adam/Envs/swiftwind/src/graphql-core/graphql/core/type/schema.py", line 30, in __init__
    assert isinstance(query, GraphQLObjectType), 'Schema query must be Object Type but got: {}.'.format(query)

I have also tried:

schema = graphene.Schema(name='Swiftwind Schema')


class Query1(object):
    all_accounts = relay.ConnectionField(accounts_nodes.Account)
    account = relay.NodeField(accounts_nodes.Account)


class Query2(object):
    all_transactions = relay.ConnectionField(accounts_nodes.Transaction)
    transaction = relay.NodeField(accounts_nodes.Transaction)


class Query3(object):
    all_users = relay.ConnectionField(accounts_nodes.User)
    resolve_all_users = ConnectionResolver(accounts_nodes.User)


class Query(Query1, Query2, Query3, ObjectType):
    pass


schema.query = Query

Which dies with the error:

  File "/Users/adam/Envs/swiftwind/src/graphql-core/graphql/core/type/definition.py", line 211, in define_field_map
    ).format(type)
AssertionError: Query fields must be a mapping (dict / OrderedDict) with field names as keys or a function which returns such a mapping.

Presumably because the fields never get initialised?

Anyway, if this is possible I'd love to know how.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions