Ver Fonte

PageInfo

- reimplementations
Alexey Kim há 2 anos atrás
pai
commit
e34d3ad980

+ 2 - 0
graphql/gqlgen.yml

@@ -23,6 +23,8 @@ models:
     model: github.com/gshopify/service-wrapper/model.CountryCode
   UnsignedInt64:
     model: github.com/gshopify/service-wrapper/model.UInt
+  PageInfo:
+    model: github.com/gshopify/service-wrapper/model.PageInfo
   HTML:
     model: github.com/gshopify/service-wrapper/scalar.Html
   JSON:

+ 1 - 1
graphql/helper/collection.go

@@ -34,7 +34,7 @@ func NewCollectionConnection(src []*generated.Collection,
 		return nil, fmt.Errorf("illegal cursor: %s", *before)
 	}
 
-	connection.PageInfo = NewPageInfo(connection.Nodes, model.GidCollection, src[0], src[len(src)-1])
+	connection.PageInfo = model.NewPageInfo(connection.Nodes, model.GidCollection, src[0], src[len(src)-1])
 
 	// Edges
 	for i := range connection.Nodes {

+ 0 - 30
graphql/helper/page_info.go

@@ -1,30 +0,0 @@
-package helper
-
-import (
-	"github.com/gshopify/service-wrapper/interfaces"
-	"github.com/gshopify/service-wrapper/model"
-	"gshopper.com/gshopify/products/graphql/generated"
-)
-
-func NewPageInfo[T interfaces.Node](src []T, namespace model.Gid, first T, last T) *generated.PageInfo {
-	var (
-		size = len(src)
-		info = &generated.PageInfo{}
-	)
-
-	if size == 0 {
-		return info
-	}
-
-	if c, err := model.NewSimpleCursor(src[0].GetID(), namespace); err == nil {
-		info.StartCursor = c.String()
-	}
-
-	if c, err := model.NewSimpleCursor(src[size-1].GetID(), namespace); err == nil {
-		info.EndCursor = c.String()
-	}
-
-	info.HasPreviousPage = first.GetID() != src[0].GetID()
-	info.HasNextPage = info.StartCursor == info.EndCursor || last.GetID() != src[size-1].GetID()
-	return info
-}

+ 1 - 1
graphql/helper/product.go

@@ -36,7 +36,7 @@ func NewProductConnection(src []*generated.Product,
 		return nil, fmt.Errorf("illegal cursor: %s", *before)
 	}
 
-	connection.PageInfo = NewPageInfo(connection.Nodes, model.GidProduct, src[0], src[len(src)-1])
+	connection.PageInfo = model.NewPageInfo(connection.Nodes, model.GidProduct, src[0], src[len(src)-1])
 
 	// Edges
 	for i := range connection.Nodes {