-
Notifications
You must be signed in to change notification settings - Fork 30
/
location.go
42 lines (33 loc) · 819 Bytes
/
location.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
package shopify
import (
"context"
"fmt"
"github.com/r0busta/go-shopify-graphql-model/v3/graph/model"
)
//go:generate mockgen -destination=./mock/location_service.go -package=mock . LocationService
type LocationService interface {
Get(ctx context.Context, id string) (*model.Location, error)
}
type LocationServiceOp struct {
client *Client
}
var _ LocationService = &LocationServiceOp{}
func (s *LocationServiceOp) Get(ctx context.Context, id string) (*model.Location, error) {
q := `query location($id: ID!) {
location(id: $id){
id
name
}
}`
vars := map[string]interface{}{
"id": id,
}
var out struct {
*model.Location `json:"location"`
}
err := s.client.gql.QueryString(ctx, q, vars, &out)
if err != nil {
return nil, fmt.Errorf("query: %w", err)
}
return out.Location, nil
}