我是graphql的新手,我发现在 django-graphql 中使用来自两个不同应用程序的模式有困难?
app1 英雄 schema.py
import graphene
from graphene_django import DjangoObjectType
from .models import Hero
class HeroType(DjangoObjectType):
class Meta:
model = Hero
class Query(graphene.ObjectType):
heroes = graphene.List(HeroType)
def resolve_heroes(self, info, **kwargs):
return Hero.objects.all()
app2 产品 schema.py
class ProductType(DjangoObjectType):
class Meta:
model = Product
class Query(object):
allproducts = graphene.List(ProductType, search=graphene.String(),limit=graphene.Int(),skip=graphene.Int(), offset=graphene.Int())
def resolve_allproducts(self, info, search=None, limit=None, skip=None, offset=None, **kwargs):
# Querying a list of products
qs = Product.objects.all()
data = []
if search:
filter = (
Q(name__icontains=search)|
Q(price__icontains=search)
)
qs = qs.filter(filter)
if skip:
qs = qs[skip:]
if limit:
# qs = qs[:limit]
qs = qs[int(offset):(int(offset) + int(limit))]
return qs
我的问题:
在主项目 schema.py 中,如何从 app1-hero 和 app2-product 调用架构?