shopify

package module
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2023 License: MIT Imports: 23 Imported by: 0

README

go-shopify-graphql

Preface: This is a fork from https://github.com/r0busta/go-shopify-graphql which extended features (retry capability, optionally set timeout, transport)

A simple client using the Shopify GraphQL Admin API.

Getting started

Hello World example

0. Setup
export STORE_API_KEY=<private_app_api_key>
export STORE_PASSWORD=<private_app_access_token>
export STORE_NAME=<store_name>
1. Program
package main

import (
	"context"
	"fmt"
	"os"

	shopify "github.com/vinhluan/go-shopify-graphql"
)

func main() {
	// Create client
	client := shopify.NewDefaultClient()

	// Or if you are a fan of options
	client = shopify.NewClient(os.Getenv("STORE_NAME"),
		shopify.WithToken(os.Getenv("STORE_PASSWORD")),
		shopify.WithVersion("2023-07"),
		shopify.WithRetries(5))

	// Get all collections
	collections, err := client.Collection.ListAll(context.Background())
	if err != nil {
		panic(err)
	}

	// Print out the result
	for _, c := range collections {
		fmt.Println(c.Handle)
	}
}
3. Run
go run .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateWaitTime

func CalculateWaitTime(respExt map[string]any) time.Duration

CalculateWaitTime returns a duration needed to wait in order to avoid reaching rate limit. respExt is the data of the “extensions“ field in Shopify GraphQL response:

"cost": {
  "requestedQueryCost": 101,
  "actualQueryCost": 46,
  "throttleStatus": {
    "maximumAvailable": 1000,
    "currentlyAvailable": 954,
    "restoreRate": 50
  }
}

func IsConnectionError

func IsConnectionError(err error) bool

Types

type BulkOperationService

type BulkOperationService interface {
	BulkQuery(ctx context.Context, query string, v interface{}) error

	PostBulkQuery(ctx context.Context, query string) (*string, error)
	GetCurrentBulkQuery(ctx context.Context) (*model.BulkOperation, error)
	GetCurrentBulkQueryResultURL(ctx context.Context) (*string, error)
	WaitForCurrentBulkQuery(ctx context.Context, interval time.Duration) (*model.BulkOperation, error)
	ShouldGetBulkQueryResultURL(ctx context.Context, id *string) (*string, error)
	CancelRunningBulkQuery(ctx context.Context) error
}

type BulkOperationServiceOp

type BulkOperationServiceOp struct {
	// contains filtered or unexported fields
}

func (*BulkOperationServiceOp) BulkQuery

func (s *BulkOperationServiceOp) BulkQuery(ctx context.Context, query string, out interface{}) error

func (*BulkOperationServiceOp) CancelRunningBulkQuery

func (s *BulkOperationServiceOp) CancelRunningBulkQuery(ctx context.Context) error

func (*BulkOperationServiceOp) GetCurrentBulkQuery

func (s *BulkOperationServiceOp) GetCurrentBulkQuery(ctx context.Context) (*model.BulkOperation, error)

func (*BulkOperationServiceOp) GetCurrentBulkQueryResultURL

func (s *BulkOperationServiceOp) GetCurrentBulkQueryResultURL(ctx context.Context) (*string, error)

func (*BulkOperationServiceOp) PostBulkQuery

func (s *BulkOperationServiceOp) PostBulkQuery(ctx context.Context, query string) (*string, error)

func (*BulkOperationServiceOp) ShouldGetBulkQueryResultURL

func (s *BulkOperationServiceOp) ShouldGetBulkQueryResultURL(ctx context.Context, id *string) (*string, error)

func (*BulkOperationServiceOp) WaitForCurrentBulkQuery

func (s *BulkOperationServiceOp) WaitForCurrentBulkQuery(ctx context.Context, interval time.Duration) (*model.BulkOperation, error)

type Client

type Client struct {
	Product       ProductService
	Variant       VariantService
	Inventory     InventoryService
	Collection    CollectionService
	Order         OrderService
	Fulfillment   FulfillmentService
	Location      LocationService
	Metafield     MetafieldService
	BulkOperation BulkOperationService
	Webhook       WebhookService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(shopName string, opts ...Option) *Client

func NewClientWithToken

func NewClientWithToken(accessToken string, storeName string) *Client

func NewDefaultClient

func NewDefaultClient() *Client

func (*Client) GraphQLClient

func (c *Client) GraphQLClient() graphql.GraphQL

func (*Client) Mutate

func (c *Client) Mutate(ctx context.Context, m interface{}, variables map[string]interface{}) error

func (*Client) Query

func (c *Client) Query(ctx context.Context, q interface{}, variables map[string]interface{}) error

func (*Client) QueryString

func (c *Client) QueryString(ctx context.Context, q string, variables map[string]interface{}, out interface{}) error

type CollectionService

type CollectionService interface {
	ListAll(ctx context.Context) ([]*model.Collection, error)

	Get(ctx context.Context, id string) (*model.Collection, error)

	Create(ctx context.Context, collection model.CollectionInput) (*string, error)
	CreateBulk(ctx context.Context, collections []model.CollectionInput) error

	Update(ctx context.Context, collection model.CollectionInput) error
}

type CollectionServiceOp

type CollectionServiceOp struct {
	// contains filtered or unexported fields
}

func (*CollectionServiceOp) Create

func (s *CollectionServiceOp) Create(ctx context.Context, collection model.CollectionInput) (*string, error)

func (*CollectionServiceOp) CreateBulk

func (s *CollectionServiceOp) CreateBulk(ctx context.Context, collections []model.CollectionInput) error

func (*CollectionServiceOp) Get

func (*CollectionServiceOp) ListAll

func (s *CollectionServiceOp) ListAll(ctx context.Context) ([]*model.Collection, error)

func (*CollectionServiceOp) Update

func (s *CollectionServiceOp) Update(ctx context.Context, collection model.CollectionInput) error

type FulfillmentService

type FulfillmentService interface {
	Create(ctx context.Context, input model.FulfillmentV2Input) error
}

type FulfillmentServiceOp

type FulfillmentServiceOp struct {
	// contains filtered or unexported fields
}

func (*FulfillmentServiceOp) Create

func (s *FulfillmentServiceOp) Create(ctx context.Context, fulfillment model.FulfillmentV2Input) error

type InventoryService

type InventoryService interface {
	Update(ctx context.Context, id string, input model.InventoryItemUpdateInput) error
	Adjust(ctx context.Context, locationID string, input []model.InventoryAdjustItemInput) error
	ActivateInventory(ctx context.Context, locationID string, id string) error
}

type InventoryServiceOp

type InventoryServiceOp struct {
	// contains filtered or unexported fields
}

func (*InventoryServiceOp) ActivateInventory

func (s *InventoryServiceOp) ActivateInventory(ctx context.Context, locationID string, id string) error

func (*InventoryServiceOp) Adjust

func (s *InventoryServiceOp) Adjust(ctx context.Context, locationID string, input []model.InventoryAdjustItemInput) error

func (*InventoryServiceOp) Update

type ListOptions

type ListOptions struct {
	Query   string
	First   int
	Last    int
	After   string
	Before  string
	Reverse bool
}

type LocationService

type LocationService interface {
	Get(ctx context.Context, id string) (*model.Location, error)
}

type LocationServiceOp

type LocationServiceOp struct {
	// contains filtered or unexported fields
}

func (*LocationServiceOp) Get

type MetafieldService

type MetafieldService interface {
	ListAllShopMetafields(ctx context.Context) ([]*model.Metafield, error)
	ListShopMetafieldsByNamespace(ctx context.Context, namespace string) ([]*model.Metafield, error)

	GetShopMetafieldByKey(ctx context.Context, namespace, key string) (*model.Metafield, error)

	Delete(ctx context.Context, metafield model.MetafieldDeleteInput) error
	DeleteBulk(ctx context.Context, metafield []model.MetafieldDeleteInput) error
}

type MetafieldServiceOp

type MetafieldServiceOp struct {
	// contains filtered or unexported fields
}

func (*MetafieldServiceOp) Delete

func (*MetafieldServiceOp) DeleteBulk

func (s *MetafieldServiceOp) DeleteBulk(ctx context.Context, metafields []model.MetafieldDeleteInput) error

func (*MetafieldServiceOp) GetShopMetafieldByKey

func (s *MetafieldServiceOp) GetShopMetafieldByKey(ctx context.Context, namespace, key string) (*model.Metafield, error)

func (*MetafieldServiceOp) ListAllShopMetafields

func (s *MetafieldServiceOp) ListAllShopMetafields(ctx context.Context) ([]*model.Metafield, error)

func (*MetafieldServiceOp) ListShopMetafieldsByNamespace

func (s *MetafieldServiceOp) ListShopMetafieldsByNamespace(ctx context.Context, namespace string) ([]*model.Metafield, error)

type Option

type Option func(shopClient *Client)

func WithGraphQLClient

func WithGraphQLClient(gql graphql.GraphQL) Option

func WithPrivateAppAuth

func WithPrivateAppAuth(apiKey string, accessToken string) Option

WithPrivateAppAuth optionally sets private app credentials (API key and access token).

func WithRetries

func WithRetries(retries int) Option

WithRetries optionally sets maximum retry count for an API call.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout optionally sets timeout for each HTTP requests made.

func WithToken

func WithToken(token string) Option

WithToken optionally sets access token.

func WithTransport

func WithTransport(transport http.RoundTripper) Option

WithTransport optionally sets transport for HTTP client.

func WithVersion

func WithVersion(apiVersion string) Option

WithVersion optionally sets the API version if the passed string is valid.

type OrderService

type OrderService interface {
	Get(ctx context.Context, id graphql.ID) (*model.Order, error)

	List(ctx context.Context, opts ListOptions) ([]*model.Order, error)
	ListAll(ctx context.Context) ([]*model.Order, error)

	ListAfterCursor(ctx context.Context, opts ListOptions) ([]*model.Order, *string, *string, error)

	Update(ctx context.Context, input model.OrderInput) error
}

type OrderServiceOp

type OrderServiceOp struct {
	// contains filtered or unexported fields
}

func (*OrderServiceOp) Get

func (s *OrderServiceOp) Get(ctx context.Context, id graphql.ID) (*model.Order, error)

func (*OrderServiceOp) List

func (s *OrderServiceOp) List(ctx context.Context, opts ListOptions) ([]*model.Order, error)

func (*OrderServiceOp) ListAfterCursor

func (s *OrderServiceOp) ListAfterCursor(ctx context.Context, opts ListOptions) ([]*model.Order, *string, *string, error)

func (*OrderServiceOp) ListAll

func (s *OrderServiceOp) ListAll(ctx context.Context) ([]*model.Order, error)

func (*OrderServiceOp) Update

func (s *OrderServiceOp) Update(ctx context.Context, input model.OrderInput) error

type ProductService

type ProductService interface {
	List(ctx context.Context, query string) ([]*model.Product, error)
	ListAll(ctx context.Context) ([]*model.Product, error)

	Get(ctx context.Context, id string) (*model.Product, error)

	Create(ctx context.Context, product model.ProductInput, media []model.CreateMediaInput) (*model.Product, error)
	Update(ctx context.Context, product model.ProductInput) (*model.Product, error)
	Delete(ctx context.Context, product model.ProductDeleteInput) error

	VariantsBulkCreate(ctx context.Context, id string, input []model.ProductVariantsBulkInput) error
	VariantsBulkUpdate(ctx context.Context, id string, input []model.ProductVariantsBulkInput) error
	VariantsBulkReorder(ctx context.Context, id string, input []model.ProductVariantPositionInput) error
}

type ProductServiceOp

type ProductServiceOp struct {
	// contains filtered or unexported fields
}

func (*ProductServiceOp) Create

func (*ProductServiceOp) Delete

func (*ProductServiceOp) Get

func (*ProductServiceOp) List

func (s *ProductServiceOp) List(ctx context.Context, query string) ([]*model.Product, error)

func (*ProductServiceOp) ListAll

func (s *ProductServiceOp) ListAll(ctx context.Context) ([]*model.Product, error)

func (*ProductServiceOp) Update

func (s *ProductServiceOp) Update(ctx context.Context, product model.ProductInput) (*model.Product, error)

func (*ProductServiceOp) VariantsBulkCreate

func (s *ProductServiceOp) VariantsBulkCreate(ctx context.Context, id string, input []model.ProductVariantsBulkInput) error

func (*ProductServiceOp) VariantsBulkReorder

func (s *ProductServiceOp) VariantsBulkReorder(ctx context.Context, id string, input []model.ProductVariantPositionInput) error

func (*ProductServiceOp) VariantsBulkUpdate

func (s *ProductServiceOp) VariantsBulkUpdate(ctx context.Context, id string, input []model.ProductVariantsBulkInput) error

type VariantService

type VariantService interface {
	Update(ctx context.Context, variant model.ProductVariantInput) error
}

type VariantServiceOp

type VariantServiceOp struct {
	// contains filtered or unexported fields
}

func (*VariantServiceOp) Update

type WebhookService added in v1.0.2

type WebhookService interface {
	CreateWebhookSubscription(ctx context.Context, topic model.WebhookSubscriptionTopic, input model.WebhookSubscriptionInput) (*model.WebhookSubscription, error)
	CreateEventBridgeWebhookSubscription(ctx context.Context, topic model.WebhookSubscriptionTopic, input model.EventBridgeWebhookSubscriptionInput) (*model.WebhookSubscription, error)
	ListWebhookSubscriptions(ctx context.Context, topics []model.WebhookSubscriptionTopic) ([]*model.WebhookSubscription, error)
	DeleteWebhook(ctx context.Context, webhookID string) (deletedID *string, err error)
	UpdateWebhookSubscription(ctx context.Context, webhookID string, input model.WebhookSubscriptionInput) (*model.WebhookSubscription, error)
}

type WebhookServiceOp added in v1.0.2

type WebhookServiceOp struct {
	// contains filtered or unexported fields
}

func (WebhookServiceOp) CreateEventBridgeWebhookSubscription added in v1.0.2

func (WebhookServiceOp) CreateWebhookSubscription added in v1.0.2

func (WebhookServiceOp) DeleteWebhook added in v1.0.2

func (s WebhookServiceOp) DeleteWebhook(ctx context.Context, webhookID string) (*string, error)

func (WebhookServiceOp) ListWebhookSubscriptions added in v1.0.2

func (s WebhookServiceOp) ListWebhookSubscriptions(ctx context.Context, topics []model.WebhookSubscriptionTopic) ([]*model.WebhookSubscription, error)

func (WebhookServiceOp) UpdateWebhookSubscription added in v1.0.2

func (s WebhookServiceOp) UpdateWebhookSubscription(ctx context.Context, webhookID string, input model.WebhookSubscriptionInput) (*model.WebhookSubscription, error)

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL