Graphene: Is it possible to combine schema objects?

Created on 26 Jan 2017  路  4Comments  路  Source: graphql-python/graphene

Let's say I have several Django "apps", if I define as per-app schema object available, for example at app_name.schema.SCHEMA is there some kind of utility function that lets me merge those schema objects?

Most helpful comment

Unfortunately this isn't appearing to work. I am only yielding __debug in my queries though I get only my Challenge schema as expected if set SCHEMA to challenge.schema.game.schema.

class Query(challenge.schema.game.GameQuery, graphene.ObjectType):
    debug = graphene.Field(DjangoDebug, name='__debug')


schema = graphene.Schema(query=Query)

GameQuery is a graphene.ObjectType. I am not using Relay in my architecture so I have it configured as in the basic tutorials.


SOLVED: Queries must be named the class of Query. Trying to name it GameQuery was incorrect.

class Query(challenge.schema.game.Query, graphene.ObjectType):
    debug = graphene.Field(DjangoDebug, name='__debug')


schema = graphene.Schema(query=Query)

All 4 comments

You can create parent query classes that inherit from all the query classes, and likewise for mutations then add the parent query/mutation classes to a schema:
https://github.com/graphql-python/graphene-django/blob/master/examples/cookbook/cookbook/schema.py

class SuperQuery(App1Query, App2Query, graphene.ObjectType):
    pass

schema = graphene.Schema(query=SuperQuery)

Unfortunately this isn't appearing to work. I am only yielding __debug in my queries though I get only my Challenge schema as expected if set SCHEMA to challenge.schema.game.schema.

class Query(challenge.schema.game.GameQuery, graphene.ObjectType):
    debug = graphene.Field(DjangoDebug, name='__debug')


schema = graphene.Schema(query=Query)

GameQuery is a graphene.ObjectType. I am not using Relay in my architecture so I have it configured as in the basic tutorials.


SOLVED: Queries must be named the class of Query. Trying to name it GameQuery was incorrect.

class Query(challenge.schema.game.Query, graphene.ObjectType):
    debug = graphene.Field(DjangoDebug, name='__debug')


schema = graphene.Schema(query=Query)

It looks like this issue has been solved. Closing the issue.

Hello, Is still possible to do a superquery ?
I'm using the structure of the code like on the example but it gives me this error:
AssertionError: Type <function SuperQuery at 0x7f4a3707ec80> is not a valid ObjectType.
The codes example are here:

class Query(AbstractType):
    # find data of a sensor; of a day; of both
    search_data = List(Data, input=i_data())
    # find a sensor with id
    search_sensors = List(Sensors, input=i_sensor())

    all_data = List(Data, input = i_User_Token())
    all_sensors = List(Sensors, input = i_User_Token())
    [ omitted resolvers ]

def SuperQuery(Query, ObjectType):
    pass

I know that AbstractType is deprecated since 2.0 so I've tried to use the 'object' type but got the same error.
Is there a possibility to combine multiples Query objects from different locations?

I'm using last graphene
---SOLVED
I wrote bad my code.

class SuperQuery(Query, ObjectType):
    pass

This is working just fine

Was this page helpful?
0 / 5 - 0 ratings