|
@@ -0,0 +1,39 @@
|
|
|
+package helper
|
|
|
+
|
|
|
+import (
|
|
|
+ "github.com/gshopify/service-wrapper/fun"
|
|
|
+ "github.com/gshopify/service-wrapper/model"
|
|
|
+ "gshopper.com/gshopify/products/graphql/generated"
|
|
|
+)
|
|
|
+
|
|
|
+func NewProductTagConnection(src []model.ProductTag,
|
|
|
+ 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 {
|
|
|
+ e := &generated.StringEdge{
|
|
|
+ Node: src[i].Tag,
|
|
|
+ }
|
|
|
+
|
|
|
+ if c, err := model.NewSimpleCursor(src[i].Tag, ""); err == nil {
|
|
|
+ e.Cursor = *c.String()
|
|
|
+ }
|
|
|
+
|
|
|
+ connection.Edges = append(connection.Edges, e)
|
|
|
+ }
|
|
|
+
|
|
|
+ return connection, nil
|
|
|
+}
|