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


Python graphene.Field方法代码示例

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


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

示例1: convert_local_structured_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_local_structured_property(ndb_structured_property, registry=None):
    is_required = ndb_structured_property._required
    is_repeated = ndb_structured_property._repeated
    model = ndb_structured_property._modelclass
    name = ndb_structured_property._code_name

    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return None

        if is_repeated:
            _type = List(_type)

        if is_required:
            _type = NonNull(_type)

        return Field(_type)

    field = Dynamic(dynamic_type)
    return ConversionResult(name=name, field=field) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:23,代码来源:converter.py

示例2: get_service_query

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def get_service_query(schema):
    sdl_str = get_sdl(schema, custom_entities)

    class _Service(ObjectType):
        sdl = String()

        def resolve_sdl(parent, _):
            return sdl_str

    class ServiceQuery(ObjectType):
        _service = Field(_Service, name="_service")

        def resolve__service(parent, info):
            return _Service()

    return ServiceQuery 
开发者ID:preply,项目名称:graphene-federation,代码行数:18,代码来源:service.py

示例3: _is_graphene_enum

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def _is_graphene_enum(obj: 'Any') -> bool:
        """
        Return whether 'obj' is a enum.

        Args:
            obj: lambda or graphene.Field

        Returns:
            boolean

        """
        if gqls_version < (2, 2, 0):
            # https://github.com/graphql-python/graphene-sqlalchemy/blob/v2.1.2/graphene_sqlalchemy/converter.py#L147
            return isinstance(obj, graphene.Field) and isinstance(
                obj._type, graphene.types.enum.EnumMeta
            )
        elif gqls_version == (2, 2, 0):
            # https://github.com/graphql-python/graphene-sqlalchemy/blob/db3e9f4c3baad3e62c113d4a9ddd2e3983d324f2/graphene_sqlalchemy/converter.py#L150
            return isinstance(obj, graphene.Field) and callable(obj._type)
        else:
            # https://github.com/graphql-python/graphene-sqlalchemy/blob/17d535efba03070cbc505d915673e0f24d9ca60c/graphene_sqlalchemy/converter.py#L216
            return callable(obj) and obj.__name__ == '<lambda>' 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:24,代码来源:filters.py

示例4: convert_lazy_field_to_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_lazy_field_to_dynamic(field, registry=None):
    model = field.document_type

    def lazy_resolver(root, *args, **kwargs):
        if getattr(root, field.name or field.db_name):
            return getattr(root, field.name or field.db_name).fetch()

    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return None
        return graphene.Field(
            _type,
            resolver=lazy_resolver,
            description=get_field_description(field, registry),
        )

    return graphene.Dynamic(dynamic_type) 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:20,代码来源:converter.py

示例5: test_should_self_reference_convert_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def test_should_self_reference_convert_dynamic():
    class P(MongoengineObjectType):
        class Meta:
            model = Player
            interfaces = (graphene.Node,)

    dynamic_field = convert_mongoengine_field(
        Player._fields["opponent"], P._meta.registry
    )
    assert isinstance(dynamic_field, graphene.Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == P

    graphene_field = convert_mongoengine_field(
        Player._fields["players"], P._meta.registry
    )
    assert isinstance(graphene_field, MongoengineConnectionField) 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:20,代码来源:test_converter.py

示例6: test_should_generic_reference_convert_union

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def test_should_generic_reference_convert_union():
    class A(MongoengineObjectType):
        class Meta:
            model = Article

    class E(MongoengineObjectType):
        class Meta:
            model = Editor

    class R(MongoengineObjectType):
        class Meta:
            model = Reporter

    generic_reference_field = convert_mongoengine_field(
        Reporter._fields["generic_reference"], registry.get_global_registry()
    )
    assert isinstance(generic_reference_field, graphene.Field)
    assert isinstance(generic_reference_field.type(), graphene.Union)
    assert generic_reference_field.type()._meta.types == (A, E) 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:21,代码来源:test_converter.py

示例7: test_should_filter_by_id

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def test_should_filter_by_id(fixtures):
    # Notes: https://goo.gl/hMNRgs
    class Query(graphene.ObjectType):
        reporter = Node.Field(nodes.ReporterNode)

    query = """
        query ReporterQuery {
            reporter (id: "UmVwb3J0ZXJOb2RlOjE=") {
                id,
                firstName,
                awards
            }
        }
    """
    expected = {
        "reporter": {
            "id": "UmVwb3J0ZXJOb2RlOjE=",
            "firstName": "Allen",
            "awards": ["2010-mvp"],
        }
    }
    schema = graphene.Schema(query=Query)
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:27,代码来源:test_relay_query.py

示例8: convert_ndb_scalar_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_ndb_scalar_property(graphene_type, ndb_prop, registry=None, **kwargs):
    kwargs['description'] = "%s %s property" % (ndb_prop._name, graphene_type)
    _type = graphene_type

    if ndb_prop._repeated:
        _type = List(_type)

    if ndb_prop._required:
        _type = NonNull(_type)

    return Field(_type, **kwargs) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:13,代码来源:converter.py

示例9: convert_ndb_json_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_ndb_json_property(ndb_prop, registry=None):
    return Field(JSONString, description=ndb_prop._name) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:4,代码来源:converter.py

示例10: convert_ndb_time_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_ndb_time_property(ndb_prop, registry=None):
    return Field(Time, description=ndb_prop._name) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:4,代码来源:converter.py

示例11: convert_ndb_datetime_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def convert_ndb_datetime_property(ndb_prop, registry=None):
    return Field(DateTime, description=ndb_prop._name) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:4,代码来源:converter.py

示例12: Field

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def Field(  # pylint: disable=invalid-name
        cls, name=None, description=None, deprecation_reason=None, required=False
    ):
        """Represent subscription as a field to "deploy" it."""
        return graphene.Field(
            cls._meta.output,
            args=cls._meta.arguments,
            resolver=cls._meta.resolver,
            name=name,
            description=description,
            deprecation_reason=deprecation_reason,
            required=required,
        )

    # ------------------------------------------------------------------- IMPLEMENTATION 
开发者ID:datadvance,项目名称:DjangoChannelsGraphqlWs,代码行数:17,代码来源:subscription.py

示例13: __new__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def __new__(cls, name_, bases, namespace, **options):
        # Note: it's safe to pass options as keyword arguments as they are still type-checked by ObjectTypeOptions.

        # We create this type, to then overload it with the dataclass attrs
        class InterObjectType:
            pass

        base_cls = super().__new__(
            cls, name_, (InterObjectType,) + bases, namespace, **options,
        )
        if base_cls._meta:
            fields = [
                (
                    key,
                    "typing.Any",
                    field(
                        default=field_value.default_value
                        if isinstance(field_value, Field)
                        else None
                    ),
                )
                for key, field_value in base_cls._meta.fields.items()
            ]
            dataclass = make_dataclass(name_, fields, bases=())
            InterObjectType.__init__ = dataclass.__init__
            InterObjectType.__eq__ = dataclass.__eq__
            InterObjectType.__repr__ = dataclass.__repr__
        return base_cls 
开发者ID:graphql-python,项目名称:graphene,代码行数:30,代码来源:objecttype.py

示例14: __init_subclass_with_meta__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def __init_subclass_with_meta__(
        cls,
        interfaces=(),
        possible_types=(),
        default_resolver=None,
        _meta=None,
        **options,
    ):
        if not _meta:
            _meta = ObjectTypeOptions(cls)

        fields = {}

        for interface in interfaces:
            assert issubclass(
                interface, Interface
            ), f'All interfaces of {cls.__name__} must be a subclass of Interface. Received "{interface}".'
            fields.update(interface._meta.fields)

        for base in reversed(cls.__mro__):
            fields.update(yank_fields_from_attrs(base.__dict__, _as=Field))

        assert not (possible_types and cls.is_type_of), (
            f"{cls.__name__}.Meta.possible_types will cause type collision with {cls.__name__}.is_type_of. "
            "Please use one or other."
        )

        if _meta.fields:
            _meta.fields.update(fields)
        else:
            _meta.fields = fields

        if not _meta.interfaces:
            _meta.interfaces = interfaces
        _meta.possible_types = possible_types
        _meta.default_resolver = default_resolver

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

示例15: Field

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Field [as 别名]
def Field(
        cls, name=None, description=None, deprecation_reason=None, required=False
    ):
        """ Mount instance of mutation Field. """
        return Field(
            cls._meta.output,
            args=cls._meta.arguments,
            resolver=cls._meta.resolver,
            name=name,
            description=description or cls._meta.description,
            deprecation_reason=deprecation_reason,
            required=required,
        ) 
开发者ID:graphql-python,项目名称:graphene,代码行数:15,代码来源:mutation.py


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