graphene icon indicating copy to clipboard operation
graphene copied to clipboard

Is it possible to combine schema objects?

Open mandx opened this issue 9 years ago • 4 comments

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?

mandx avatar Jan 26 '17 20:01 mandx

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)

yfilali avatar Feb 27 '17 23:02 yfilali

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)

blorenz avatar May 12 '17 02:05 blorenz

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

jkimbo avatar Feb 17 '18 22:02 jkimbo

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

yeboster avatar Jun 01 '18 16:06 yeboster