如何使用SQLAlchemy从graphQL获取已编译的原始sql?

时间:2017-12-07 14:45:46

标签: python sqlalchemy graphql

如何使用graphQLSQLAlchemy获取已编译的原始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])

1 个答案:

答案 0 :(得分:0)

好吧,我刚刚找到了方法,参考了https://stackoverflow.com/a/36141722/9041712

query = RecordType.get_query(info)
print(query.statement.compile(compile_kwargs={"literal_binds": True}))