def test_returns_all_elements_if_cursors_are_on_the_outside(): check( 'before: "{}" after: "{}"'.format( base64( 'arrayconnection:%s' % 6), base64( 'arrayconnection:%s' % -1)), 'ABCDE')
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]]
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]]
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] ]
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))
def test_returns_no_elements_if_cursors_cross(): check('before: "{}" after: "{}"'.format(base64('arrayconnection:%s' % 2), base64('arrayconnection:%s' % 4)), '')
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)]))
def cursor_for(ltr): l = letters[ltr] return base64('arrayconnection:%s' % l.id)
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)]))
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", )
def offsetToCursor(offset): ''' Creates the cursor string from an offset. ''' return base64(PREFIX + str(offset))
def converts_from_unicode_to_base64(): assert base64(example_unicode) == example_base64
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))
async def test_returns_no_elements_if_cursors_cross(): await check( 'before: "{}" after: "{}"'.format(base64("arrayconnection:%s" % 2), base64("arrayconnection:%s" % 4)), "", )
def cursor_for(ltr): letter = letters[ltr] return base64("arrayconnection:%s" % letter.id)
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