__init__.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:graphene-mongo 作者: joaovitorsilvestre 项目源码 文件源码
def convert_fields(attrs_mongo_doc):
    """ Return a tuple od dicts,
    @param attrs_mongo_doc: dict of attributes of the mongoengine.Document, that is accessible by Document._fields     
    fields: is the pure fields, key is the name of field, and values is the repective graphene field
    fields_mutation: is the fields that is used in mutation, that will go direct in args of mutation
    operators_mutation: is the fields that user set values to be saved on document
    operators_single: is the fields with operators that will be in the query for a single result
    operators_list: same of operators single, but these are avaliable only for query of lists
    """

    fields, fields_mutation, operators_mutation, operators_single = {}, {}, {}, {}

    for f_name, mongo_field in attrs_mongo_doc.items():
        field = RelationMongoGraphene(name=f_name, mongo_field=mongo_field)

        fields[f_name] = field.graphene
        operators_single.update(field.operators)
        fields_mutation[f_name] = field.mutation
        if not isinstance(mongo_field, ObjectIdField):
            operators_mutation[f_name] = field.mutation

    operators_list = operators_single.copy()
    operators_single['skip'] = graphene.Int()

    operators_list.update({p: graphene.Int() for p in special_query_parameters})

    return fields, fields_mutation, operators_mutation, operators_single, operators_list
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号