Python graphene 模块,ID 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用graphene.ID

项目:graphene-mongo    作者:joaovitorsilvestre    | 项目源码 | 文件源码
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)
项目:graphql-pynamodb    作者:yfilali    | 项目源码 | 文件源码
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)))
项目:graphql-pynamodb    作者:yfilali    | 项目源码 | 文件源码
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)
项目:graphene-mongo    作者:joaovitorsilvestre    | 项目源码 | 文件源码
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
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def convert_form_field_to_list(field):
    return List(ID, required=field.required)
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def convert_form_field_to_id(field):
    return ID(required=field.required)
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_should_auto_convert_id():
    assert_conversion(models.AutoField, graphene.ID, primary_key=True)
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_should_manytoone_convert_connectionorlist():
    field = forms.ModelChoiceField(Reporter.objects.all())
    graphene_type = convert_form_field(field)
    assert isinstance(graphene_type, graphene.ID)