Graphene-Django:在模式中组合查询对象(仅采用第一个参数)

Esp*_*and 5 django reactjs graphql graphene-python react-relay

我正在尝试组合位于 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)
Run Code Online (Sandbox Code Playgroud)

为什么会这样?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)
Run Code Online (Sandbox Code Playgroud)

我正在将我的架构导出到 schema.json 以便将它与反应中继一起使用。我确实从登陆页面(3. 变量)中找到了我的对象“集合”查询模式。继电器返回:

错误:GraphQLParser:collection类型上的未知字段Viewer。来源:文档AppQuery文件:containers/App/index.js.

Relay 读取我的 schema.json 有问题吗?

Esp*_*and 0

写完这篇文章后不久我就设法解决了这个问题。我的问题是我在每个应用程序中都有一个 Viewer 对象。因为我发现拥有一个viewer-graphql-root很有用,如下所示:

graphql'
  viewer {
    collection {
      somestuff
    }
  }
'
Run Code Online (Sandbox Code Playgroud)

我将 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)
Run Code Online (Sandbox Code Playgroud)