forked from r0busta/go-shopify-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variant.go
43 lines (33 loc) · 1.01 KB
/
variant.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package shopify
import (
"context"
"fmt"
"github.com/r0busta/go-shopify-graphql-model/v3/graph/model"
)
//go:generate mockgen -destination=./mock/variant_service.go -package=mock . VariantService
type VariantService interface {
Update(variant model.ProductVariantInput) error
}
type VariantServiceOp struct {
client *Client
}
var _ VariantService = &VariantServiceOp{}
type mutationProductVariantUpdate struct {
ProductVariantUpdateResult struct {
UserErrors []model.UserError `json:"userErrors,omitempty"`
} `graphql:"productVariantUpdate(input: $input)" json:"productVariantUpdate"`
}
func (s *VariantServiceOp) Update(variant model.ProductVariantInput) error {
m := mutationProductVariantUpdate{}
vars := map[string]interface{}{
"input": variant,
}
err := s.client.gql.Mutate(context.Background(), &m, vars)
if err != nil {
return fmt.Errorf("mutation: %w", err)
}
if len(m.ProductVariantUpdateResult.UserErrors) > 0 {
return fmt.Errorf("%+v", m.ProductVariantUpdateResult.UserErrors)
}
return nil
}