// Paginate executes the query and returns a relay based cursor connection to LocationType.
Paginate executes the query and returns a relay based cursor connection to LocationType.
// Paginate executes the query and returns a relay based cursor connection to LocationType .
func (lt *LocationTypeQuery) Paginate(ctx context.Context, after *Cursor, first *int, before *Cursor, last *int) (*LocationTypeConnection, error) {
	if first != nil && last != nil {
		return nil, ErrInvalidPagination
	}
	if first != nil {
		if *first == 0 {
			return &LocationTypeConnection{
				Edges: []*LocationTypeEdge{},
			}, nil
		} else if *first < 0 {
			return nil, ErrInvalidPagination
		}
	}
	if last != nil {
		if *last == 0 {
			return &LocationTypeConnection{
				Edges: []*LocationTypeEdge{},
			}, nil
		} else if *last < 0 {
			return nil, ErrInvalidPagination
		}
	}
	if after != nil {
		lt = lt.Where(locationtype.IDGT(after.ID))
	}
	if before != nil {
		lt = lt.Where(locationtype.IDLT(before.ID))
	}
	if first != nil {
		lt = lt.Order(Asc(locationtype.FieldID)).Limit(*first + 1)
	}
	if last != nil {
		lt = lt.Order(Desc(locationtype.FieldID)).Limit(*last + 1)
	}
	lt = lt.collectConnectionFields(ctx)
	nodes, err := lt.All(ctx)
	if err != nil || len(nodes) == 0 {
		return &LocationTypeConnection{
			Edges: []*LocationTypeEdge{},
		}, err
	}
	if last != nil {
		for left, right := 0, len(nodes)-1; left < right; left, right = left+1, right-1 {
			nodes[left], nodes[right] = nodes[right], nodes[left]
		}
	}
	var conn LocationTypeConnection
	if first != nil && len(nodes) > *first {
		conn.PageInfo.HasNextPage = true
		nodes = nodes[:len(nodes)-1]
	} else if last != nil && len(nodes) > *last {
		conn.PageInfo.HasPreviousPage = true
		nodes = nodes[1:]
	}
	conn.Edges = make([]*LocationTypeEdge, len(nodes))
	for i, node := range nodes {
		conn.Edges[i] = &LocationTypeEdge{
			Node: node,
			Cursor: Cursor{
				ID: node.ID,
			},
		}
	}
	conn.PageInfo.StartCursor = &conn.Edges[0].Cursor
	conn.PageInfo.EndCursor = &conn.Edges[len(conn.Edges)-1].Cursor
	return &conn, nil
}
func ( lt * LocationTypeQuery ) Paginate ( ctx context . Context , after * Cursor , first * int , before * Cursor , last * int ) ( * LocationTypeConnection , error ) { if first != nil && last != nil { return nil , ErrInvalidPagination } if first != nil { if * first == 0 { return & LocationTypeConnection { Edges : [ ] * LocationTypeEdge { } , } , nil } else if * first < 0 { return nil , ErrInvalidPagination } } if last != nil { if * last == 0 { return & LocationTypeConnection { Edges : [ ] * LocationTypeEdge { } , } , nil } else if * last < 0 { return nil , ErrInvalidPagination } } if after != nil { lt = lt . Where ( locationtype . IDGT ( after . ID ) ) } if before != nil { lt = lt . Where ( locationtype . IDLT ( before . ID ) ) } if first != nil { lt = lt . Order ( Asc ( locationtype . FieldID ) ) . Limit ( * first + 1 ) } if last != nil { lt = lt . Order ( Desc ( locationtype . FieldID ) ) . Limit ( * last + 1 ) } lt = lt . collectConnectionFields ( ctx ) nodes , err := lt . All ( ctx ) if err != nil || len ( nodes ) == 0 { return & LocationTypeConnection { Edges : [ ] * LocationTypeEdge { } , } , err } if last != nil { for left , right := 0 , len ( nodes ) - 1 ; left < right ; left , right = left + 1 , right - 1 { nodes [ left ] , nodes [ right ] = nodes [ right ] , nodes [ left ] } } var conn LocationTypeConnection if first != nil && len ( nodes ) > * first { conn . PageInfo . HasNextPage = true nodes = nodes [ : len ( nodes ) - 1 ] } else if last != nil && len ( nodes ) > * last { conn . PageInfo . HasPreviousPage = true nodes = nodes [ 1 : ] } conn . Edges = make ( [ ] * LocationTypeEdge , len ( nodes ) ) for i , node := range nodes { conn . Edges [ i ] = & LocationTypeEdge { Node : node , Cursor : Cursor { ID : node . ID , } , } } conn . PageInfo . StartCursor = & conn . Edges [ 0 ] . Cursor conn . PageInfo . EndCursor = & conn . Edges [ len ( conn . Edges ) - 1 ] . Cursor return & conn , nil }
Paginate executes the query and returns a relay based cursor connection to LocationType.
Paginate executes the query and returns a relay based cursor connection to LocationType .