Im using Django with graphene to build an API but i want to combine two models in one query, all the fields of the models are the same.
Example schema.py
import graphene
from graphene_django import DjangoObjectType
from .models import Post, Post2
class PostType(DjangoObjectType):
class Meta:
model = Post
class Post2Type(DjangoObjectType):
class Meta:
model = Post2
class Query(graphene.ObjectType):
post = graphene.List(PostType)
post2 = graphene.List(Post2Type)
def resolve_post(self, info):
return Post.objects.all()
def resolve_post2(self, info):
return Post2.objects.all()
I get this response:
{
"data": {
"post": [
{
"title": "post 1"
}
],
"post2": [
{
"title": "post test"
}
]
}
}
What i want to get is:
{
"data": {
"allPost": [
{
"title": "post 1"
},
{
"title": "post test"
}
}
}