我试图结合Django 2.1中不同应用程序中的多个查询模式。使用石墨烯-django 2.2 (已经尝试了2.1与同样的问题)。Python 3.7
查询类只注册第一个变量。举个例子,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,以便与react继电器一起使用它。我确实从landingpage( 3变量)中找到了我的对象“集合”查询模式。继电器返回:
错误: GraphQLParser:类型
Viewer
上的未知字段collection
。资料来源: documentAppQuery
文件:containers/App/index.js
。
这是继电器阅读我的schema.json的问题吗?
发布于 2018-09-06 20:16:17
写完这篇文章后不久,我就解决了这个问题。我的问题是我在每个应用程序中都有一个Viewer对象。因为我发现有一个查看器-graphql很有用,如下所示:
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)
发布于 2021-12-01 09:51:11
进口石墨烯 导入about.schema 导入shop.schema作为项目 导入landingpage.schema作为项目
然后添加:
class Query(about.schema.Query, shop.schema.Query, landingpage.schema.Query, graphene.ObjectType):
pass
class Mutation(about.schema.Mutation, shop.schema.Mutation, landingpage.schema.Mutation, graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)
https://stackoverflow.com/questions/52210104
复制相似问题