我有一个查询,它遍历我的BookModel
表,并找到该特定book_id
的所有问题:
query {
allBooks {
edges {
node {
id,
questionMeta {
edges {
node {
bookId
}
}
}
}
}
}
}
BookModel:
class BookModel(db.base):
__tablename__ = 'books_book'
id = Column(Integer, primary_key=True)
question_meta = relationship(QuestionMetaModel)
QuestionMetaModal:
class QuestionMetaModel(db.base):
__tablename__ = 'questions_questionmeta'
id = Column(Integer, primary_key=True)
question_id = Column(ForeignKey('questions_question.id'))
book_id = Column(ForeignKey('books_book.id'))
查询的结果是这样的(压缩的):
{
"data": {
"allBooks": {
"edges": [
{
"node": {
"id": "1",
"questionMeta": {
"edges": [
{
"node": {
"bookId": 1
}
},
... (1000+ more)
]
}
},
{ ... }
]
}
}
此数据的问题在于,对于书中确定的每个问题,它在questionMeta
下返回一个大数组。我真正需要的只是数组的长度,或者是问题的数量。
问题:如何不返回大型数组,而仅返回整数值?
我想要什么(理想的输出):
{
"data": {
"allBooks": {
"edges": [
{
"node": {
"id": "1",
"questionCount": 1356
}
},
{
"node": {
"id": "2",
"questionCount": 649
}
}
]
}
}