def gen_operators_of_field(f_name, mongo_field, r_graphene, operators_list):
""" Return a dict with keys as the name of the field with operator and value is the required type, for instance:
@param f_name: string name of the field
@param mongo_field: object instance of mongoengine field, e.g: mongoengine.StringField()
@param r_graphene: object instance of graphene field, e.g: graphene.String():
{
name: graphene.String()
name__nin: graphene.List(graphene.String) ...
}
"""
field_with_operators = {
f_name: field_to_id(mongo_field, r_graphene)
}
for op_name in operators_list:
field_with_operators[f_name + '__' + op_name] = operators[op_name](mongo_field, r_graphene)
if isinstance(mongo_field, fields_string_operators):
for op in string_operators:
field_with_operators[f_name + '__' + op] = graphene.String()
return field_with_operators
评论列表
文章目录