def query_route(request):
"""
Query database based on Facebook's GraphQL Library.
Parameters must be coded into a "q" GET parameter, e.g.
`curl "localhost:4284/api/v2/query?q=query\{statements\{uid,isStartpoint\}\}"`
:return: JSON containing queried data
"""
q = request.params.get("q")
if q:
schema = graphene.Schema(query=Query)
result = schema.execute(q, context_value={'session': DBDiscussionSession})
if result.errors:
return {"errors": {"message": "Not all requested parameters could be queried. Some fields are not "
"allowed, e.g. the password.",
"exception": str(result.errors)}}
return result.data
return {"errors": {"message": "No valid query provided."}}
评论列表
文章目录