Graphql multiple queries and mutation using Graphene

148 views Asked by At

I chose to handle sending multiple Queries and Mutations as follow,

First I defined a Schema defined in schema.py:

# schema.py code
from graphene import Schema, Field, ObjectType
from .basic_objects.queries import BasicQuery
from .basic_objects.mutations import BasicMutation

schema = Schema(query=BasicQuery, mutation=BasicMutation)

Then I have updated the schema.py file:

from graphene import Schema, Field, ObjectType
from .basic_objects.queries import BasicQuery
from .basic_objects.mutations import BasicMutation


class Query(ObjectType):
    BasicQuery = Field(BasicQuery)
    #otherQuery

class Mutation(ObjectType):
    BasicMutation = Field(BasicMutation)


schema = Schema(query=Query, mutation=Mutation)

But while trying to send the following GraphQL request:

query MyQuery {
  BasicQueryData {
    oneNode(id: 1) {
      comment
      coordinateY
    }
  }
}

from query oneNode directly working and graphene find the method and it is working.

How can I make that this time from query first go to BasicQueryData and then call oneNode method?

1

There are 1 answers

0
Kamran Teymurov On BEST ANSWER
class Query(BasicQuery):
    Field(BasicQuery)


class Mutation(BasicMutation):
    Field(BasicMutation)


schema = Schema(query=Query, mutation=Mutation)

I fixed like this