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


Python graphene.types方法代码示例

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


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

示例1: _add_handler_resolves

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import types [as 别名]
def _add_handler_resolves(dict_params):
    to_add = {}
    for k, v in dict_params.items():
        if k == 'field':    # pragma: no cover
            raise ValueError("StructBlocks cannot have fields named 'field'")
        if isinstance(v, tuple):
            val = v[0]
            to_add['resolve_' + k] = v[1]
        elif issubclass(v, (graphene.types.DateTime, graphene.types.Date)):
            val = v
            to_add['resolve_' + k] = _resolve_datetime
        elif issubclass(v, graphene.types.Time):
            val = v
            to_add['resolve_' + k] = _resolve_time
        elif not issubclass(v, Scalar):
            val = v
            to_add['resolve_' + k] = _resolve
        else:
            val = v
        dict_params[k] = graphene.Field(val)
    dict_params.update(to_add) 
开发者ID:tr11,项目名称:wagtail-graphql,代码行数:23,代码来源:streamfield.py

示例2: type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import types [as 别名]
def type(self):
		# this is to bypass the one from
		# graphene_sqlalchemy.SQLAlchemyConnectionField which breaks
		return graphene.types.utils.get_type(self._type) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:6,代码来源:database.py

示例3: stream_field_handler

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import types [as 别名]
def stream_field_handler(stream_field_name: str, field_name: str, block_type_handlers: dict) -> StreamFieldHandlerType:
    # add Generic Scalars (default)
    if settings.LOAD_GENERIC_SCALARS:
        _scalar_block(GenericScalar)

    # Unions must reference NamedTypes, so for scalar types we need to create a new type to
    # encapsulate scalars, page links, images, snippets
    _create_root_blocks(block_type_handlers)

    types_ = list(block_type_handlers.values())
    for i, t in enumerate(types_):
        if isinstance(t, tuple):
            types_[i] = t[0]

    class Meta:
        types = tuple(set(types_))

    stream_field_type = type(
        stream_field_name + "Type",
        (graphene.Union, ),
        {
            'Meta': Meta,
            'resolve_type': _resolve_type
        }
    )

    def resolve_field(self, info: ResolveInfo):
        field = getattr(self, field_name)
        return [convert_block(block, block_type_handlers, info, field.is_lazy) for block in field.stream_data]

    return graphene.List(stream_field_type), resolve_field 
开发者ID:tr11,项目名称:wagtail-graphql,代码行数:33,代码来源:streamfield.py

示例4: block_handler

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import types [as 别名]
def block_handler(block: Block, app, prefix=''):
    cls = block.__class__
    handler = registry.blocks.get(cls)

    if handler is None:
        if _is_custom_type(block):
            target_block_type = block.__graphql_type__()
            this_handler = block_handler(target_block_type, app, prefix)
            if isinstance(this_handler, tuple):
                raise NotImplementedError()
            if hasattr(block, '__graphql_resolve__'):
                resolver = _resolve_custom(block, this_handler)
            elif issubclass(target_block_type, Scalar):
                resolver = _resolve_generic_scalar
            else:
                raise TypeError("Non Scalar custom types need an explicit __graphql_resolve__ method.")
            handler = (lambda x: this_handler, resolver)
        elif _is_compound_block(block):
            node = prefix + cls.__name__
            dict_params = dict(
                (n, block_handler(block_type, app, prefix))
                for n, block_type in block.child_blocks.items()
            )
            _add_handler_resolves(dict_params)
            dict_params.update({  # add the field name
                'field': graphene.Field(graphene.String),
                'resolve_field': lambda *x: block.name,
            })
            tp = type(node, (graphene.ObjectType,), dict_params)
            handler = tp
            registry.blocks[cls] = handler
        elif _is_list_block(block):
            this_handler = block_handler(block.child_block, app, prefix)
            if isinstance(this_handler, tuple):
                handler = List(this_handler[0]), _resolve_list(*this_handler)
            else:
                handler = List(this_handler), _resolve_simple_list
        else:
            handler = GenericScalar

    if cls == wagtail.snippets.blocks.SnippetChooserBlock:
        handler = (handler[0](block), handler[1])   # type: ignore

    return handler 
开发者ID:tr11,项目名称:wagtail-graphql,代码行数:46,代码来源:streamfield.py


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