sorare/mutations/buy_shop_item.go

51 lines
1.1 KiB
Go
Raw Normal View History

2024-04-16 11:00:33 +00:00
package mutations
import (
"context"
gql "github.com/llehouerou/go-graphql-client"
"github.com/pkg/errors"
"git.lehouerou.net/laurent/sorare/graphql"
)
type buyShopItemInput struct {
2024-04-16 11:11:11 +00:00
ClientMutationId string `json:"clientMutationId"`
ShopItemId gql.ID `json:"shopItemId"`
2024-04-16 11:00:33 +00:00
}
type BuyShopItemParams struct {
Input buyDeliverableShopItemInput `graphql:"input"`
}
func (m *Mutations) newBuyShopItemMutation() *graphql.Mutation[BaseMutationPayload, BuyShopItemParams] {
return graphql.NewMutation[BaseMutationPayload, BuyShopItemParams](
m.c,
"buyShopItem",
)
}
func (m *Mutations) BuyShopItem(
ctx context.Context,
shopItemId string,
) error {
res, err := m.newBuyShopItemMutation().Execute(ctx, BuyShopItemParams{
Input: buyShopItemInput{
ClientMutationId: GetRandomId(),
ShopItemId: gql.ID(shopItemId),
},
})
if err != nil {
return errors.Wrap(err, "executing buyShopItem mutation")
}
if res.Errors != nil {
return errors.Wrap(
errors.New(res.Errors[0].Message),
"executing buyShopItem mutation",
)
}
return nil
}