當前位置: 首頁>>代碼示例>>Python>>正文


Python graphql_relay.from_global_id方法代碼示例

本文整理匯總了Python中graphql_relay.from_global_id方法的典型用法代碼示例。如果您正苦於以下問題:Python graphql_relay.from_global_id方法的具體用法?Python graphql_relay.from_global_id怎麽用?Python graphql_relay.from_global_id使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在graphql_relay的用法示例。


在下文中一共展示了graphql_relay.from_global_id方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: clean

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def clean(self, value):
        if not value and not self.required:
            return None

        try:
            _type, _id = from_global_id(value)
        except (TypeError, ValueError, UnicodeDecodeError, binascii.Error):
            raise ValidationError(self.error_messages["invalid"])

        try:
            CharField().clean(_id)
            CharField().clean(_type)
        except ValidationError:
            raise ValidationError(self.error_messages["invalid"])

        return value 
開發者ID:graphql-python,項目名稱:graphene-django,代碼行數:18,代碼來源:forms.py

示例2: describe_convert_global_ids

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def describe_convert_global_ids():
    def to_global_id_converts_unicode_strings_correctly():
        my_unicode_id = "ûñö"
        g_id = to_global_id("MyType", my_unicode_id)
        assert g_id == "TXlUeXBlOsO7w7HDtg=="

        my_unicode_id = "\u06ED"
        g_id = to_global_id("MyType", my_unicode_id)
        assert g_id == "TXlUeXBlOtut"

    def from_global_id_converts_unicode_strings_correctly():
        my_unicode_id = "ûñö"
        my_type, my_id = from_global_id("TXlUeXBlOsO7w7HDtg==")
        assert my_type == "MyType"
        assert my_id == my_unicode_id

        my_unicode_id = "\u06ED"
        my_type, my_id = from_global_id("TXlUeXBlOtut")
        assert my_type == "MyType"
        assert my_id == my_unicode_id 
開發者ID:graphql-python,項目名稱:graphql-relay-py,代碼行數:22,代碼來源:test_node.py

示例3: get_node_from_global_id

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def get_node_from_global_id(cls, info, global_id, only_type=None):
        try:
            _type, _id = cls.from_global_id(global_id)
        except Exception as e:
            raise Exception(
                (
                    f'Unable to parse global ID "{global_id}". '
                    'Make sure it is a base64 encoded string in the format: "TypeName:id". '
                    f"Exception message: {str(e)}"
                )
            )

        graphene_type = info.schema.get_type(_type)
        if graphene_type is None:
            raise Exception(f'Relay Node "{_type}" not found in schema')

        graphene_type = graphene_type.graphene_type

        if only_type:
            assert (
                graphene_type == only_type
            ), f"Must receive a {only_type._meta.name} id."

        # We make sure the ObjectType implements the "Node" interface
        if cls not in graphene_type._meta.interfaces:
            raise Exception(
                f'ObjectType "{_type}" does not implement the "{cls}" interface.'
            )

        get_node = getattr(graphene_type, "get_node", None)
        if get_node:
            return get_node(info, _id) 
開發者ID:graphql-python,項目名稱:graphene,代碼行數:34,代碼來源:node.py

示例4: from_global_id

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def from_global_id(cls, global_id):
        return from_global_id(global_id) 
開發者ID:graphql-python,項目名稱:graphene,代碼行數:4,代碼來源:node.py

示例5: mutate_and_get_payload

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def mutate_and_get_payload(cls, root, info, **input):
        if cls.has_permission(root, info, input):
            owner = User.objects.get(pk=from_global_id(input['owner'])[1])
            pet = Pet.objects.create(name=input['name'], race=input['race'], owner=owner)
            return SuperUserAddPet(pet=pet, status=HTTPStatus.CREATED)
        return SuperUserAddPet(pet=None, status=HTTPStatus.BAD_REQUEST) 
開發者ID:redzej,項目名稱:graphene-permissions,代碼行數:8,代碼來源:schema.py

示例6: default_resolver

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def default_resolver(self, _root, info, **args):
        args = args or {}

        if _root is not None:
            args["pk__in"] = [r.pk for r in getattr(_root, info.field_name, [])]

        connection_args = {
            "first": args.pop("first", None),
            "last": args.pop("last", None),
            "before": args.pop("before", None),
            "after": args.pop("after", None),
        }

        _id = args.pop('id', None)

        if _id is not None:
            args['pk'] = from_global_id(_id)[-1]

        if callable(getattr(self.model, "objects", None)):
            iterables = self.get_queryset(self.model, info, **args)
            list_length = iterables.count()
        else:
            iterables = []
            list_length = 0

        connection = connection_from_list_slice(
            list_slice=iterables,
            args=connection_args,
            list_length=list_length,
            list_slice_length=list_length,
            connection_type=self.type,
            edge_type=self.type.Edge,
            pageinfo_type=graphene.PageInfo,
        )
        connection.iterable = iterables
        connection.list_length = list_length
        return connection 
開發者ID:graphql-python,項目名稱:graphene-mongo,代碼行數:39,代碼來源:fields.py

示例7: _resolve_nodes

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def _resolve_nodes(ids, graphene_type=None):
    pks = []
    invalid_ids = []
    used_type = graphene_type

    for graphql_id in ids:
        if not graphql_id:
            continue

        try:
            node_type, _id = from_global_id(graphql_id)
        except Exception:
            invalid_ids.append(graphql_id)
            continue

        if used_type:
            if str(used_type) != node_type:
                raise AssertionError(
                    "Must receive a {} id.".format(str(used_type))
                )

        used_type = node_type
        pks.append(_id)

    if invalid_ids:  # pragma: no cover
        raise GraphQLError(
            "Could not resolve to a node with the id list of '{}'.".format(
                invalid_ids,
            ),
        )

    return used_type, pks 
開發者ID:0soft,項目名稱:graphene-django-plus,代碼行數:34,代碼來源:utils.py

示例8: get_node

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def get_node(id, graphene_type=None):
    """Get a node given the relay id."""
    node_type, _id = from_global_id(id)
    if not graphene_type:
        graphene_type = _resolve_graphene_type(node_type)

    return graphene_type._meta.model.objects.get(pk=_id) 
開發者ID:0soft,項目名稱:graphene-django-plus,代碼行數:9,代碼來源:utils.py

示例9: parse_value

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def parse_value(cls, value):
        try:
            _type, _id = from_global_id(value)
        except (TypeError, ValueError):
            raise exceptions.ValidationError(_('ID cannot be resolved'))
        return int(_id) 
開發者ID:flavors,項目名稱:django-graphql-extensions,代碼行數:8,代碼來源:types.py

示例10: extract_global_id

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def extract_global_id(id):
    """
    Extract id from global id throwing away type.

    In case it is not a base64 encoded value it will return id as is.
    This way it can be used as input type by simply defining id without its specific type.
    """

    try:
        _, result = from_global_id(id)
    except ValueError:
        result = id

    return result 
開發者ID:projectcaluma,項目名稱:caluma,代碼行數:16,代碼來源:relay.py

示例11: connection_resolver

# 需要導入模塊: import graphql_relay [as 別名]
# 或者: from graphql_relay import from_global_id [as 別名]
def connection_resolver(cls, resolver, connection, model, root, info, **args):
        iterable = resolver(root, info, **args)

        first = args.get('first')
        last = args.get('last')
        (_, after) = from_global_id(args.get('after')) if args.get('after') else (None, None)
        (_, before) = from_global_id(args.get('before')) if args.get('before') else (None, None)
        has_previous_page = bool(after)
        page_size = first if first else last if last else None

        # get a full scan query since we have no resolved iterable from relationship or resolver function
        if not iterable and not root:
            query = cls.get_query(model, info, **args)
            iterable = query()
            if first or last or after or before:
                raise NotImplementedError(
                    "DynamoDB scan operations have no predictable sort. Arguments first, last, after " +
                    "and before will have unpredictable results")

        iterable = iterable if isinstance(iterable, list) else list(iterable) if iterable else []
        if last:
            iterable = iterable[-last:]

        (has_next, edges) = cls.get_edges_from_iterable(iterable, model, info, edge_type=connection.Edge, after=after,
                                                        page_size=page_size)

        key_name = get_key_name(model)
        try:
            start_cursor = getattr(edges[0].node, key_name)
            end_cursor = getattr(edges[-1].node, key_name)
        except IndexError:
            start_cursor = None
            end_cursor = None

        optional_args = {}
        total_count = len(iterable)
        if 'total_count' in connection._meta.fields:
            optional_args["total_count"] = total_count

        # Construct the connection
        return connection(
            edges=edges,
            page_info=PageInfo(
                start_cursor=start_cursor if start_cursor else '',
                end_cursor=end_cursor if end_cursor else '',
                has_previous_page=has_previous_page,
                has_next_page=has_next
            ),
            **optional_args
        ) 
開發者ID:yfilali,項目名稱:graphql-pynamodb,代碼行數:52,代碼來源:fields.py


注:本文中的graphql_relay.from_global_id方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。