1234567891011121314151617181920212223242526272829303132333435 |
- package helper
- import (
- "github.com/gshopify/service-wrapper/fun"
- "github.com/gshopify/service-wrapper/interfaces"
- "github.com/gshopify/service-wrapper/model"
- "gshopper.com/gshopify/products/graphql/generated"
- )
- func NewStringConnection[T interfaces.Node](src []T,
- first *int, last *int, reverse *bool) (*generated.StringConnection, error) {
- var connection = &generated.StringConnection{}
- if len(src) == 0 {
- return connection, nil
- }
- if reverse != nil && *reverse {
- src = fun.Reverse(src)
- }
- src = fun.First(src, first)
- src = fun.Last(src, last)
- connection.PageInfo = model.NewPageInfo(src, "", src[0], src[len(src)-1])
- // Edges
- for i := range src {
- connection.Edges = append(connection.Edges, &generated.StringEdge{
- Cursor: *model.NewSimpleCursor(src[i].GetID()).String(),
- Node: src[i].GetID(),
- })
- }
- return connection, nil
- }
|