#NEWLINE# def connection_from_list( data , args = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , connection_type = None , edge_type = None , pageinfo_type = None , **kwargs ) : #NEWLINE# #INDENT# '\n    A simple function that accepts an array and connection arguments, and returns\n    a connection object for use in GraphQL. It uses array offsets as pagination,\n    so pagination will only work if the array is static.\n    ' #NEWLINE# connection_type = ( connection_type or Connection ) #NEWLINE# edge_type = ( edge_type or Edge ) #NEWLINE# pageinfo_type = ( pageinfo_type or PageInfo ) #NEWLINE# full_args = dict ( args , ** kwargs ) #NEWLINE# before = full_args . get ( 'before' ) #NEWLINE# after = full_args . get ( 'after' ) #NEWLINE# first = full_args . get ( 'first' ) #NEWLINE# last = full_args . get ( 'last' ) #NEWLINE# count = len ( data ) #NEWLINE# begin = ( max ( get_offset ( after , ( - 1 ) ) , ( - 1 ) ) + 1 ) #NEWLINE# end = min ( get_offset ( before , ( count + 1 ) ) , count ) #NEWLINE# if ( ( begin >= count ) or ( end >= end ) ) : #NEWLINE# #INDENT# return empty_connection ( connection_type , pageinfo_type ) #NEWLINE# #UNINDENT# first_preslice_cursor = offset_to_cursor ( begin ) #NEWLINE# last_preslice_cursor = offset_to_cursor ( ( min ( end , count ) - 1 ) ) #NEWLINE# if ( first is not None ) : #NEWLINE# #INDENT# end = min ( ( begin + first ) , end ) #NEWLINE# #UNINDENT# if ( last is not None ) : #NEWLINE# #INDENT# begin = max ( ( end - last ) , begin ) #NEWLINE# #UNINDENT# if ( ( begin >= count ) or ( begin >= end ) ) : #NEWLINE# #INDENT# return empty_connection ( connection_type , pageinfo_type ) #NEWLINE# #UNINDENT# sliced_data = data [ begin : end ] #NEWLINE# edges = [ edge_type ( node = node , cursor = offset_to_cursor ( ( i + begin ) ) ) for ( i , node ) in enumerate ( sliced_data ) ] #NEWLINE# first_edge = edges [ 0 ] #NEWLINE# last_edge = edges [ ( len ( edges ) - 1 ) ] #NEWLINE# return connection_type ( edges = edges , page_info = pageinfo_type ( start_cursor = first_edge . cursor , end_cursor = last_edge . cursor , has_previous_page = ( first_edge . cursor != first_preslice_cursor ) , has_next_page = ( last_edge . cursor != last_preslice_cursor ) ) )