@@ -8,11 +8,12 @@ import (
88 "strings"
99 "time"
1010
11- shopify "github.com/bold-commerce/go-shopify/v3 "
11+ shopify "github.com/bold-commerce/go-shopify/v4 "
1212 "github.com/screenstaring/shopify_id_export/exportformat"
13+ "github.com/screenstaring/shopify_id_export/gql"
1314)
1415
15- const version = "v0.0.7 "
16+ const version = "v0.1.0 "
1617const shopifyFields = "id,title,product_type,handle,variants"
1718
1819const usage = `shopify_id_export [hjv] [-k key] [-p password] [-r root-property] [-t token] shop
@@ -35,7 +36,7 @@ Valid properties for the --json-root option are: %s
3536`
3637
3738type dumper interface {
38- Dump (shopify .Product ) error
39+ Dump (gql .Product ) error
3940 Close () error
4041}
4142
@@ -45,34 +46,32 @@ func exitFailure(error string, code int) {
4546}
4647
4748func dumpProducts (client * shopify.Client , dumper dumper , pageSize int ) error {
48- listOptions := shopify.ListOptions {
49- Fields : shopifyFields ,
50- Limit : pageSize ,
49+ listOptions := map [string ]interface {}{
50+ "after" : nil ,
5151 }
5252
5353 for {
54- products , pages , err := client .Product .ListWithPagination (
55- shopify.ProductListOptions {
56- ListOptions : listOptions ,
57- },
58- )
59-
54+ products , err := gql .FindProducts (client , listOptions )
6055 if err != nil {
6156 return fmt .Errorf ("Failed retrieve products: " + err .Error ())
6257 }
6358
64- for _ , product := range products {
59+ page := products .PageInfo
60+
61+ for _ , edge := range (products .Edges ) {
62+ product := edge .Node
63+
6564 err = dumper .Dump (product )
6665 if err != nil {
6766 return fmt .Errorf ("Failed saving products: " + err .Error ())
6867 }
6968 }
7069
71- if pages . NextPageOptions == nil {
70+ if ! page . HasNextPage {
7271 break
7372 }
7473
75- listOptions . PageInfo = pages . NextPageOptions . PageInfo
74+ listOptions [ "after" ] = page . Cursor
7675 }
7776
7877 return nil
@@ -86,7 +85,12 @@ func main() {
8685 var pageSize int
8786 var client * shopify.Client
8887
89- options := []shopify.Option {shopify .WithRetry (5 )}
88+ options := []shopify.Option {
89+ shopify .WithRetry (5 ),
90+ // Bug forces us to specify version
91+ // https://github.com/bold-commerce/go-shopify/issues/314
92+ shopify .WithVersion ("2024-10" ),
93+ }
9094
9195 flag .Usage = func () {
9296 exitFailure (fmt .Sprintf (usage , strings .Join (exportformat .JSONRootProperties , ", " )), 2 )
@@ -141,6 +145,7 @@ func main() {
141145 if timeout > - 1 {
142146 options = append (
143147 options ,
148+ // FIXME: update for GQL
144149 shopify .WithHTTPClient (
145150 & http.Client {
146151 Timeout : time .Second * time .Duration (timeout ),
@@ -153,7 +158,10 @@ func main() {
153158 options = append (options , shopify .WithLogger (& shopify.LeveledLogger {Level : shopify .LevelDebug }))
154159 }
155160
156- client = shopify .NewClient (app , argv [0 ], token , options ... )
161+ client , err = shopify .NewClient (app , argv [0 ], token , options ... )
162+ if err != nil {
163+ exitFailure (err .Error (), 2 )
164+ }
157165
158166 err = dumpProducts (client , dumper , pageSize )
159167 dumpErr := dumper .Close ()
0 commit comments