我收到关于为成功字段返回 null 的错误,但它包含在我的返回有效负载中。返回有效载荷看起来像这样
{'success': True, 'GeneratedKeywords': [{'id': 1, 'file_id': 1, 'keywords': 'keyword', 'generated_date': '11-01-2021'}, {'id': 2, 'file_id': 1, 'keywords': 'keyword', 'generated_date': '11-01-2021'}]}
图式
type DocumentKeywords {
id: ID!
file_id: Int!
keywords: String!
generated_date: String!
}
type GetAllKeyowrdsResult {
success: Boolean
errors: [String]
GeneratedKeywords: [DocumentKeywords]
}
type Query {
GetAllKeywords: [GetAllKeyowrdsResult]
}
解析器代码
def resolve_AllKeywords(obj, info):
try:
#print(GeneratedKeywords.query.all(), file=sys.stderr)
#GKs = [genKeys.to_dict() for genKeys in GeneratedKeywords.query.all()]
GKs = []
for genKeys in GeneratedKeywords.query.all():
print(genKeys, file=sys.stderr)
GKs.append(genKeys.to_dict())
print(GKs, file=sys.stderr)
payload = {
"success": True,
"GeneratedKeywords": GKs
}
print(payload, file=sys.stderr)
except Exception as error:
payload = {
"success": False,
"errors": [str(error)]
}
return payload
```