python类ID的实例源码

test_operators.py 文件源码 项目:graphene-mongo 作者: joaovitorsilvestre 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_add_operators_to_field_reference_field():
    from mongoengine import ReferenceField, Document, StringField
    from graphene_mongo.operators import gen_operators_of_field, allowed_operators
    from graphene_mongo.fields import respective_special_fields

    class Other(Document):
        name = StringField()

    class Test(Document):
        test = ReferenceField(Other)

    field = Test.test
    r_graphene = respective_special_fields[type(field)]
    applied_operators = gen_operators_of_field('test', field, r_graphene('test', field), allowed_operators(field))

    assert sorted(list(applied_operators.keys())) == format_fields(['in', 'nin', 'ne'])

    assert isinstance(applied_operators['test__in'], graphene.List)
    assert isinstance(applied_operators['test__nin'], graphene.List)
    assert isinstance(applied_operators['test__ne'], graphene.ID)
converter.py 文件源码 项目:graphql-pynamodb 作者: yfilali 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def convert_column_to_string(type, attribute, registry=None):
    if attribute.is_hash_key:
        return ID(description=attribute.attr_name, required=not attribute.null)

    return String(description=getattr(attribute, 'attr_name'),
                  required=not (getattr(attribute, 'null', True)))
converter.py 文件源码 项目:graphql-pynamodb 作者: yfilali 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def convert_column_to_int_or_id(type, attribute, registry=None):
    if attribute.is_hash_key:
        return ID(description=attribute.attr_name, required=not attribute.null)

    return Int(description=attribute.attr_name, required=not attribute.null)
respective.py 文件源码 项目:graphene-mongo 作者: joaovitorsilvestre 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def field_to_id(m_field, g_field):
    """ We need this because if we want to do a query using the id, we will pass a string to args with the id of the 
    document that we want, but graphene needs a ID field, instead of Field. This function convert to right thing."""

    if isinstance(m_field, ReferenceField):
        return graphene.ID()
    elif (isinstance(m_field, ListField) or isinstance(m_field, SortedListField)) and \
            isinstance(m_field.field, ReferenceField):
        """ Pass here if it is a ListField or SortedListField of ReferenceField """
        return graphene.List(graphene.ID)
    else:
        return g_field
form_converter.py 文件源码 项目:graphene-django 作者: graphql-python 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def convert_form_field_to_list(field):
    return List(ID, required=field.required)
form_converter.py 文件源码 项目:graphene-django 作者: graphql-python 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def convert_form_field_to_id(field):
    return ID(required=field.required)
test_converter.py 文件源码 项目:graphene-django 作者: graphql-python 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_should_auto_convert_id():
    assert_conversion(models.AutoField, graphene.ID, primary_key=True)
test_form_converter.py 文件源码 项目:graphene-django 作者: graphql-python 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_should_manytoone_convert_connectionorlist():
    field = forms.ModelChoiceField(Reporter.objects.all())
    graphene_type = convert_form_field(field)
    assert isinstance(graphene_type, graphene.ID)


问题


面经


文章

微信
公众号

扫码关注公众号