コード例 #1
0
def test_returns_all_elements_if_cursors_are_on_the_outside():
    check(
        'before: "{}" after: "{}"'.format(
            base64(
                'arrayconnection:%s' % 6),
            base64(
                'arrayconnection:%s' % -1)),
        'ABCDE')
コード例 #2
0
def edges(selected_letters):
    return [{
        "node": {
            "id": base64("Letter:%s" % l.id),
            "letter": l.letter
        },
        "cursor": base64("arrayconnection:%s" % l.id),
    } for l in [letters[i] for i in selected_letters]]
コード例 #3
0
def edges(selected_letters):
    return [{
        'node': {
            'id': base64('Letter:%s' % l.id),
            'letter': l.letter
        },
        'cursor': base64('arrayconnection:%s' % l.id)
    } for l in [letters[i] for i in selected_letters]]
コード例 #4
0
def test_returns_all_elements_if_cursors_are_on_the_outside():
    check(
        'before: "{}" after: "{}"'.format(
            base64(
                'arrayconnection:%s' % 6),
            base64(
                'arrayconnection:%s' % -1)),
        'ABCDE')
コード例 #5
0
def edges(selected_letters):
    return [
        {
            'node': {
                'id': base64('Letter:%s' % l.id),
                'letter': l.letter
            },
            'cursor': base64('arrayconnection:%s' % l.id)
        }
        for l in [letters[i] for i in selected_letters]
    ]
コード例 #6
0
    def resolve_ranking(cls, root, info, **input) -> RankConnection:
        # Pagination
        page = input.get("page") if "page" in input else 1
        count_for_rows = input.get(
            "count_for_rows") if "count_for_rows" in input else 10
        order = input.get("order") if "order" in input else list()
        skip = (page - 1) * count_for_rows

        # Mongo Object Parse to Edge
        conn_type = cls.ranking.type
        node_name = conn_type._meta.node._meta.name
        datas = RankModel.objects(mode=root.mode).all()
        nodes = datas.order_by(*order).skip(skip).limit(count_for_rows)
        edges = [
            conn_type.Edge(node=node,
                           cursor=base64(f"{ node_name }:{ str(node.id) }"))
            for node in nodes
        ]

        # Create new RankConnection Object
        return conn_type(edges=edges,
                         page_info=relay.PageInfo(has_previous_page=True,
                                                  has_next_page=True),
                         total_count=len(datas))
コード例 #7
0
def test_returns_no_elements_if_cursors_cross():
    check('before: "{}" after: "{}"'.format(base64('arrayconnection:%s' % 2), base64('arrayconnection:%s' % 4)), '')
コード例 #8
0
ファイル: node.py プロジェクト: jhgg/graphql-relay-py
def toGlobalId(type, id):
    '''
    Takes a type name and an ID specific to that type name, and returns a
    "global ID" that is unique among all types.
    '''
    return base64(':'.join([type, str(id)]))
コード例 #9
0
def cursor_for(ltr):
    l = letters[ltr]
    return base64('arrayconnection:%s' % l.id)
コード例 #10
0
def test_returns_no_elements_if_cursors_cross():
    check('before: "{}" after: "{}"'.format(base64('arrayconnection:%s' % 2), base64('arrayconnection:%s' % 4)), '')
コード例 #11
0
ファイル: node.py プロジェクト: sjhewitt/graphql-relay-py
def to_global_id(type, id):
    '''
    Takes a type name and an ID specific to that type name, and returns a
    "global ID" that is unique among all types.
    '''
    return base64(':'.join([type, str(id)]))
コード例 #12
0
async def test_returns_all_elements_if_cursors_are_on_the_outside():
    await check(
        'before: "{}" after: "{}"'.format(base64("arrayconnection:%s" % 6),
                                          base64("arrayconnection:%s" % -1)),
        "ABCDE",
    )
コード例 #13
0
def offsetToCursor(offset):
    '''
    Creates the cursor string from an offset.
    '''
    return base64(PREFIX + str(offset))
コード例 #14
0
 def converts_from_unicode_to_base64():
     assert base64(example_unicode) == example_base64
コード例 #15
0
def cursor_for(ltr):
    l = letters[ltr]
    return base64('arrayconnection:%s' % l.id)
コード例 #16
0
def to_global_cursor(values):
    if not isinstance(values, Iterable):
        values = [values]
    values = [value if value is None else str(value) for value in values]
    return base64(json.dumps(values))
コード例 #17
0
async def test_returns_no_elements_if_cursors_cross():
    await check(
        'before: "{}" after: "{}"'.format(base64("arrayconnection:%s" % 2),
                                          base64("arrayconnection:%s" % 4)),
        "",
    )
コード例 #18
0
def cursor_for(ltr):
    letter = letters[ltr]
    return base64("arrayconnection:%s" % letter.id)
コード例 #19
0
 def converts_from_unicode_as_bytes_to_base64():
     bytes_example_code = example_unicode.encode("utf-8")
     assert base64(bytes_example_code) == example_base64  # type: ignore
     bytearray_example_code = bytearray(bytes_example_code)
     assert base64(bytearray_example_code) == example_base64  # type: ignore