我正在尝试组合位于 Django 2.1 中不同应用程序中的多个查询模式。使用 graphene-django 2.2(已经尝试过 2.1 有同样的问题)。 python 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中的类有什么改变吗? Graphite 烯教程说这将继承多个......
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 中继一起使用。我确实从登陆页面(3. 变量)中找到了我的对象“集合”查询模式。继电器返回:
ERROR: GraphQLParser: Unknown field
collection
on typeViewer
. Source: documentAppQuery
file:containers/App/index.js
.
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)
关于django - Graphite 烯-Django : In schema combine Query-objects (only takes first argument),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52210104/