当前位置: 首页>>代码示例>>Python>>正文


Python graphene.Enum方法代码示例

本文整理汇总了Python中graphene.Enum方法的典型用法代码示例。如果您正苦于以下问题:Python graphene.Enum方法的具体用法?Python graphene.Enum怎么用?Python graphene.Enum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphene的用法示例。


在下文中一共展示了graphene.Enum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def create_enum(metaclass):
    class EnumRegisteringMetaclass(metaclass, EnumMeta):
        pass

    def from_enum(cls, enum, description=None, deprecation_reason=None):
        description = description or enum.__doc__
        meta_dict = {
            "enum": enum,
            "description": description,
            "deprecation_reason": deprecation_reason,
        }
        meta_class = type("Meta", (object,), meta_dict)
        return type(meta_class.enum.__name__, (cls,), {"Meta": meta_class})

    Enum = EnumRegisteringMetaclass('Enum', (graphene.Enum,), {'from_enum': classmethod(from_enum)})
    setattr(Enum, '__dauphinCoreType', True)
    return Enum 
开发者ID:dagster-io,项目名称:dagster,代码行数:19,代码来源:dauphin_registry.py

示例2: test_sort_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_sort_enum():
    class PetType(SQLAlchemyObjectType):
        class Meta:
            model = Pet

    sort_enum = PetType.sort_enum()
    assert isinstance(sort_enum, type(Enum))
    assert sort_enum._meta.name == "PetTypeSortEnum"
    assert list(sort_enum._meta.enum.__members__) == [
        "ID_ASC",
        "ID_DESC",
        "NAME_ASC",
        "NAME_DESC",
        "PET_KIND_ASC",
        "PET_KIND_DESC",
        "HAIR_KIND_ASC",
        "HAIR_KIND_DESC",
        "REPORTER_ID_ASC",
        "REPORTER_ID_DESC",
    ]
    assert str(sort_enum.ID_ASC.value.value) == "pets.id ASC"
    assert str(sort_enum.ID_DESC.value.value) == "pets.id DESC"
    assert str(sort_enum.HAIR_KIND_ASC.value.value) == "pets.hair_kind ASC"
    assert str(sort_enum.HAIR_KIND_DESC.value.value) == "pets.hair_kind DESC" 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:26,代码来源:test_sort_enums.py

示例3: test_should_enum_convert_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_should_enum_convert_enum():
    field = get_field(types.Enum(enum.Enum("TwoNumbers", ("one", "two"))))
    field_type = field.type()
    assert isinstance(field_type, graphene.Enum)
    assert field_type._meta.name == "TwoNumbers"
    assert hasattr(field_type, "ONE")
    assert not hasattr(field_type, "one")
    assert hasattr(field_type, "TWO")
    assert not hasattr(field_type, "two")

    field = get_field(types.Enum("one", "two", name="two_numbers"))
    field_type = field.type()
    assert isinstance(field_type, graphene.Enum)
    assert field_type._meta.name == "TwoNumbers"
    assert hasattr(field_type, "ONE")
    assert not hasattr(field_type, "one")
    assert hasattr(field_type, "TWO")
    assert not hasattr(field_type, "two") 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:20,代码来源:test_converter.py

示例4: test_register_sort_enum_incorrect_types

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_register_sort_enum_incorrect_types():
    reg = Registry()

    class PetType(SQLAlchemyObjectType):
        class Meta:
            model = Pet
            registry = reg

    sort_enum = GrapheneEnum(
        "PetSort",
        [("ID", EnumValue("id", Pet.id)), ("NAME", EnumValue("name", Pet.name))],
    )

    re_err = r"Expected SQLAlchemyObjectType, but got: .*PetSort.*"
    with pytest.raises(TypeError, match=re_err):
        reg.register_sort_enum(sort_enum, sort_enum)

    re_err = r"Expected Graphene Enum, but got: .*PetType.*"
    with pytest.raises(TypeError, match=re_err):
        reg.register_sort_enum(PetType, PetType) 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:22,代码来源:test_registry.py

示例5: test_field_with_choices_convert_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_field_with_choices_convert_enum():
    field = models.CharField(
        help_text="Language", choices=(("es", "Spanish"), ("en", "English"))
    )

    class TranslatedModel(models.Model):
        language = field

        class Meta:
            app_label = "test"

    graphene_type = convert_django_field_with_choices(field)
    assert isinstance(graphene_type, graphene.Enum)
    assert graphene_type._meta.name == "TranslatedModelLanguage"
    assert graphene_type._meta.enum.__members__["ES"].value == "es"
    assert graphene_type._meta.enum.__members__["ES"].description == "Spanish"
    assert graphene_type._meta.enum.__members__["EN"].value == "en"
    assert graphene_type._meta.enum.__members__["EN"].description == "English" 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:20,代码来源:test_converter.py

示例6: case_status_filter

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def case_status_filter(*args, **kwargs):
    case_status_descriptions = {
        s.upper(): d for s, d in models.Case.STATUS_CHOICE_TUPLE
    }

    class EnumWithDescriptionsType(object):
        @property
        def description(self):
            return case_status_descriptions[self.name]

    enum = graphene.Enum(
        "CaseStatusArgument",
        [(i.upper(), i) for i in models.Case.STATUS_CHOICES],
        type=EnumWithDescriptionsType,
    )
    return generate_list_filter_class(enum)(*args, **kwargs) 
开发者ID:projectcaluma,项目名称:caluma,代码行数:18,代码来源:filters.py

示例7: __call__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def __call__(cls, *args, **kwargs):  # noqa: N805
        if cls is Enum:
            description = kwargs.pop("description", None)
            deprecation_reason = kwargs.pop("deprecation_reason", None)
            return cls.from_enum(
                PyEnum(*args, **kwargs),
                description=description,
                deprecation_reason=deprecation_reason,
            )
        return super(EnumMeta, cls).__call__(*args, **kwargs)
        # return cls._meta.enum(*args, **kwargs) 
开发者ID:graphql-python,项目名称:graphene,代码行数:13,代码来源:enum.py

示例8: from_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def from_enum(cls, enum, description=None, deprecation_reason=None):  # noqa: N805
        description = description or enum.__doc__
        meta_dict = {
            "enum": enum,
            "description": description,
            "deprecation_reason": deprecation_reason,
        }
        meta_class = type("Meta", (object,), meta_dict)
        return type(meta_class.enum.__name__, (Enum,), {"Meta": meta_class}) 
开发者ID:graphql-python,项目名称:graphene,代码行数:11,代码来源:enum.py

示例9: __init_subclass_with_meta__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def __init_subclass_with_meta__(cls, enum=None, _meta=None, **options):
        if not _meta:
            _meta = EnumOptions(cls)
        _meta.enum = enum or cls.__enum__
        _meta.deprecation_reason = options.pop("deprecation_reason", None)
        for key, value in _meta.enum.__members__.items():
            setattr(cls, key, value)

        super(Enum, cls).__init_subclass_with_meta__(_meta=_meta, **options) 
开发者ID:graphql-python,项目名称:graphene,代码行数:11,代码来源:enum.py

示例10: get_type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def get_type(cls):
        """
        This function is called when the unmounted type (Enum instance)
        is mounted (as a Field, InputField or Argument)
        """
        return cls 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:enum.py

示例11: test_issue

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_issue():
    options = {"description": "This my enum", "deprecation_reason": "For the funs"}
    new_enum = graphene.Enum("MyEnum", [("some", "data")], **options)
    assert new_enum._meta.description == options["description"]
    assert new_enum._meta.deprecation_reason == options["deprecation_reason"] 
开发者ID:graphql-python,项目名称:graphene,代码行数:7,代码来源:test_956.py

示例12: _get_enum_from_field

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def _get_enum_from_field(
        enum: 'Union[Callable, graphene.Field]',
    ) -> graphene.Enum:
        """
        Get graphene enum.

        Args:
            enum: lambda or graphene.Field

        Returns:
            Graphene enum.

        """
        if gqls_version < (2, 2, 0):
            # AssertionError: Found different types
            # with the same name in the schema: ...
            raise AssertionError(
                'Enum is not supported. '
                'Requires graphene-sqlalchemy 2.2.0 or higher.'
            )
        elif gqls_version == (2, 2, 0):
            # https://github.com/graphql-python/graphene-sqlalchemy/compare/2.1.2...2.2.0#diff-9202780f6bf4790a0d960de553c086f1L155
            return enum._type()()
        else:
            # https://github.com/graphql-python/graphene-sqlalchemy/compare/2.2.0...2.2.1#diff-9202780f6bf4790a0d960de553c086f1L150
            return enum()() 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:28,代码来源:filters.py

示例13: __init__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def __init__(self):
        self._typeMap = {}
        self.Field = create_registry_field(self)
        self.Argument = create_registry_argument(self)
        self.List = create_registry_list(self)
        self.NonNull = create_registry_nonnull(self)
        registering_metaclass = create_registering_metaclass(self)
        self.Union = create_union(registering_metaclass, self)
        self.Enum = create_enum(registering_metaclass)
        self.Mutation = graphene.Mutation

        # Not looping over GRAPHENE_TYPES in order to not fool lint
        self.ObjectType = create_registering_class(graphene.ObjectType, registering_metaclass)
        self.InputObjectType = create_registering_class(
            graphene.InputObjectType, registering_metaclass
        )
        self.Interface = create_registering_class(graphene.Interface, registering_metaclass)
        self.Scalar = create_registering_class(graphene.Scalar, registering_metaclass)

        # Not looping over GRAPHENE_BUILTINS in order to not fool lint
        self.String = graphene.String
        self.addType(graphene.String)
        self.Int = graphene.Int
        self.addType(graphene.Int)
        self.Float = graphene.Float
        self.addType(graphene.Float)
        self.Boolean = graphene.Boolean
        self.addType(graphene.Boolean)
        self.ID = graphene.ID
        self.addType(graphene.ID)
        self.GenericScalar = GenericScalar
        self.addType(GenericScalar) 
开发者ID:dagster-io,项目名称:dagster,代码行数:34,代码来源:dauphin_registry.py

示例14: test_convert_sa_to_graphene_enum_bad_type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_convert_sa_to_graphene_enum_bad_type():
    re_err = "Expected sqlalchemy.types.Enum, but got: 'foo'"
    with pytest.raises(TypeError, match=re_err):
        _convert_sa_to_graphene_enum("foo") 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:6,代码来源:test_enums.py

示例15: test_convert_sa_to_graphene_enum_based_on_py_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Enum [as 别名]
def test_convert_sa_to_graphene_enum_based_on_py_enum():
    class Color(PyEnum):
        RED = 1
        GREEN = 2
        BLUE = 3

    sa_enum = SQLAlchemyEnumType(Color)
    graphene_enum = _convert_sa_to_graphene_enum(sa_enum, "FallbackName")
    assert isinstance(graphene_enum, type(Enum))
    assert graphene_enum._meta.name == "Color"
    assert graphene_enum._meta.enum is Color 
开发者ID:graphql-python,项目名称:graphene-sqlalchemy,代码行数:13,代码来源:test_enums.py


注:本文中的graphene.Enum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。