forked from r0busta/go-shopify-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fulfillment.go
43 lines (33 loc) · 1.09 KB
/
fulfillment.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/fulfillment_service.go -package=mock . FulfillmentService
type FulfillmentService interface {
Create(ctx context.Context, input model.FulfillmentV2Input) error
}
type FulfillmentServiceOp struct {
client *Client
}
var _ FulfillmentService = &FulfillmentServiceOp{}
type mutationFulfillmentCreateV2 struct {
FulfillmentCreateV2Result struct {
UserErrors []model.UserError `json:"userErrors,omitempty"`
} `graphql:"fulfillmentCreateV2(fulfillment: $fulfillment)" json:"fulfillmentCreateV2"`
}
func (s *FulfillmentServiceOp) Create(ctx context.Context, fulfillment model.FulfillmentV2Input) error {
m := mutationFulfillmentCreateV2{}
vars := map[string]interface{}{
"fulfillment": fulfillment,
}
err := s.client.gql.Mutate(ctx, &m, vars)
if err != nil {
return fmt.Errorf("mutation: %w", err)
}
if len(m.FulfillmentCreateV2Result.UserErrors) > 0 {
return fmt.Errorf("UserErrors: %+v", m.FulfillmentCreateV2Result.UserErrors)
}
return nil
}