2
0

query_collections.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package graphql
  2. import (
  3. "context"
  4. "github.com/gshopify/service-wrapper/fun"
  5. "github.com/gshopify/service-wrapper/model"
  6. "github.com/gshopify/service-wrapper/server/middleware"
  7. "github.com/microcosm-cc/bluemonday"
  8. "gshopper.com/gshopify/products/graphql/generated"
  9. "gshopper.com/gshopify/products/graphql/helper"
  10. )
  11. func (r *queryResolver) Collections(ctx context.Context, after *string, before *string, first *int, last *int, query *string, reverse *bool, sort *generated.CollectionSortKeys) (*generated.CollectionConnection, error) {
  12. panic("not implemented")
  13. }
  14. func (r *productResolver) Collections(ctx context.Context, product *generated.Product,
  15. after *string, before *string, first *int, last *int, reverse *bool) (*generated.CollectionConnection, error) {
  16. var (
  17. inContext *middleware.GShopifyContext
  18. collections []*generated.Collection
  19. err error
  20. )
  21. if inContext, err = middleware.InContext(ctx); err != nil {
  22. return nil, err
  23. }
  24. rawId, err := model.ParseId(model.GidProduct, product.ID)
  25. if err != nil {
  26. return nil, err
  27. }
  28. if collections, err = r.db.ProductCollections(inContext.Language, rawId); err != nil {
  29. return nil, err
  30. }
  31. return helper.NewCollectionConnection(collections, after, before, first, last, reverse)
  32. }
  33. func (r *collectionResolver) Description(_ context.Context, collection *generated.Collection, truncateAt *int) (string, error) {
  34. return fun.TruncateAt(
  35. bluemonday.StrictPolicy().Sanitize(string(collection.DescriptionHTML)),
  36. truncateAt)
  37. }