當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。