首页 文章

Graphene-Django:在模式中组合Query-objects(只接受第一个参数)

提问于
浏览
0

我试图在Django 2.1中组合位于不同应用程序中的多个Query模式 . 使用石墨烯-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中的类?石墨烯教程说这将继承多个......

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 relay一起使用 . 我确实从登陆页面找到了我的对象“集合”查询模式(3.变量) . 接力回报:

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

Relay读取我的schema.json是一个问题吗?

1 回答

  • 0

    写完这篇文章后,我设法解决了这个问题 . 我的问题是我在每个应用程序中都有一个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)
    

相关问题