|
@@ -98,8 +98,56 @@ func (r *productResolver) Options(ctx context.Context, product *generated.Produc
|
|
|
}
|
|
|
|
|
|
func (r *productResolver) Variants(ctx context.Context, product *generated.Product,
|
|
|
- first *int, after *string, last *int, before *string, reverse *bool, sortKey *generated.ProductVariantSortKeys) (*generated.ProductVariantConnection, error) {
|
|
|
- panic("not implemented")
|
|
|
+ first *int, after *string, last *int, before *string, reverse *bool, sort *generated.ProductVariantSortKeys) (*generated.ProductVariantConnection, error) {
|
|
|
+ var (
|
|
|
+ inContext *middleware.GShopifyContext
|
|
|
+ variants []*generated.ProductVariant
|
|
|
+ err error
|
|
|
+ )
|
|
|
+
|
|
|
+ inContext, err = middleware.InContext(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ rawId, err := model.ParseId(model.GidProduct, product.ID)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ variants, err = r.db.ProductVariants(inContext, rawId)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return helper.NewProductVariantConnection(variants, after, before, first, last, reverse, sort)
|
|
|
+}
|
|
|
+
|
|
|
+func (r *productVariantResolver) Product(ctx context.Context, variant *generated.ProductVariant) (*generated.Product, error) {
|
|
|
+ var (
|
|
|
+ inContext *middleware.GShopifyContext
|
|
|
+ product *generated.Product
|
|
|
+ err error
|
|
|
+ )
|
|
|
+
|
|
|
+ if inContext, err = middleware.InContext(ctx); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if variant.Product == nil {
|
|
|
+ return nil, fmt.Errorf("unknown product.ID for variant: `%s`", variant.ID)
|
|
|
+ }
|
|
|
+
|
|
|
+ rawId, err := model.ParseId(model.GidProduct, variant.Product.ID)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ if product, err = r.db.Product(inContext.Language, nil, &rawId); err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return product, nil
|
|
|
}
|
|
|
|
|
|
func (r *productVariantResolver) StoreAvailability(ctx context.Context, variant *generated.ProductVariant,
|