如何使用graphQL
从SQLAlchemy
获取已编译的原始sql命令?我做了搜索,但没有运气:(
schema.py
class RecordType(SQLAlchemyObjectType):
class Meta:
model = Record
interfaces = (graphene.relay.Node, )
class Query(graphene.ObjectType):
node = graphene.relay.Node.Field()
record = graphene.Field(RecordType, id=graphene.Int())
def resolve_record(self, info, **args):
id = args.get('id')
return RecordType.get_query(info).get(id)
schema = graphene.Schema(query=Query, types=[RecordType])
答案 0 :(得分:0)
好吧,我刚刚找到了方法,参考了https://stackoverflow.com/a/36141722/9041712
query = RecordType.get_query(info)
print(query.statement.compile(compile_kwargs={"literal_binds": True}))