add buyShopItem mutation
This commit is contained in:
parent
546d610e4e
commit
be3f38e715
52
mutations/buy_shop_item.go
Normal file
52
mutations/buy_shop_item.go
Normal file
@ -0,0 +1,52 @@
|
||||
package mutations
|
||||
|
||||
package mutations
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
gql "github.com/llehouerou/go-graphql-client"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"git.lehouerou.net/laurent/sorare/graphql"
|
||||
)
|
||||
|
||||
type buyShopItemInput struct {
|
||||
ClientMutationId string `json:"clientMutationId"`
|
||||
ShopItemId gql.ID `json:"shopItemId"`
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user