[英]Graphene-Django: In schema combine Query-objects (only takes first argument)
我正在尝试组合位于 Django 2.1 中不同应用程序中的多个查询模式。 使用 graphene-django 2.2(已经尝试过 2.1 有同样的问题)。 蟒蛇 3.7。
Query 类只注册第一个变量。 例如 shop.schema.Query。
import graphene
import graphql_jwt
from django.conf import settings
import about.schema
import shop.schema
import landingpage.schema
class Query(about.schema.Query, shop.schema.Query, landingpage.schema.Query, graphene.ObjectType):
pass
class Mutation(shop.schema.Mutation, graphene.ObjectType):
token_auth = graphql_jwt.ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
refresh_token = graphql_jwt.Refresh.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
为什么会这样? python 3.7中的类有什么改变吗? 石墨烯教程说这将继承多个......
class Query(cookbook.ingredients.schema.Query, graphene.ObjectType):
# This class will inherit from multiple Queries
# as we begin to add more apps to our project
pass
schema = graphene.Schema(query=Query)
我正在将我的架构导出到 schema.json 以便将它与反应中继一起使用。 我确实从登陆页面(3. 变量)中找到了我的对象“集合”查询模式。 继电器返回:
错误:GraphQLParser:类型
Viewer
上的未知字段collection
。 来源:文档AppQuery
文件:containers/App/index.js
AppQuery
。
Relay 读取我的 schema.json 有问题吗?
我写完这篇后不久就解决了。 我的问题是每个应用程序中都有一个Viewer对象。 因为我发现拥有一个viewer-graphql-root很有用,例如:
graphql'
viewer {
collection {
somestuff
}
}
'
我将Viewer对象移动到根schema.py,如下所示:
class Viewer(about.schema.Query, landingpage.schema.Query, shop.schema.Query, graphene.ObjectType):
class Meta:
interfaces = [relay.Node, ]
class Query(graphene.ObjectType):
viewer = graphene.Field(Viewer)
def resolve_viewer(self, info, **kwargs):
return Viewer()
class Mutation(shop.schema.Mutation, graphene.ObjectType):
token_auth = graphql_jwt.ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
refresh_token = graphql_jwt.Refresh.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
在setting.py 中添加您的所有应用程序,如下所示:
GRAPHENE = {
"SCHEMA": "about.schema.schema",
"SCHEMA": "shop.schema.schema",
"SCHEMA": "landingpage.schema.schema",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.