英文:
Graphql multiple queries and mutation using Graphene
问题
我选择处理发送多个查询和突变的方式如下,
首先我在schema.py中定义了一个“Schema”:
# schema.py 代码
from graphene import Schema, Field, ObjectType
from .basic_objects.queries import BasicQuery
from .basic_objects.mutations import BasicMutation
schema = Schema(query=BasicQuery, mutation=BasicMutation)
然后我更新了“schema.py”文件:
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)
但是在尝试发送以下GraphQL请求时:
query MyQuery {
BasicQueryData {
oneNode(id: 1) {
comment
coordinateY
}
}
}
从查询中直接使用oneNode有效,并且graphene找到该方法并且它起作用。
我如何使查询首先进入BasicQueryData,然后调用oneNode方法?
英文:
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
得分: 0
类 Query 继承自 BasicQuery:
Field 继承自 BasicQuery
类 Mutation 继承自 BasicMutation:
Field 继承自 BasicMutation
schema = Schema(query=Query, mutation=Mutation)
我修复了如下:
英文:
class Query(BasicQuery):
Field(BasicQuery)
class Mutation(BasicMutation):
Field(BasicMutation)
schema = Schema(query=Query, mutation=Mutation)
I fixed like this
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论