Update Auction GQL schema type

This commit is contained in:
Prathamesh Musale 2024-09-19 09:30:38 +05:30
parent 7bc108fd7f
commit fec82eb2f8
5 changed files with 89 additions and 78 deletions

View File

@ -13,7 +13,7 @@ On having some change in the GQL schema (for example: adding a new query) update
go get github.com/99designs/gqlgen@v0.17.22
# Generate bindings
# In gql
cd gql
go run github.com/99designs/gqlgen generate
```

View File

@ -168,13 +168,13 @@ type Auction {
commitFee: Coin! # Fee required to bid/participate in the auction.
revealFee: Coin! # Reveal fee (paid back to bidders only if they unseal/reveal the bid).
minimumBid: Coin! # Minimum bid amount.
winnerAddresses: [String]! # Winner address.
winnerBids: [Coin]! # The winning bid amount.
winnerAddresses: [String!]! # Winner address.
winnerBids: [Coin!]! # The winning bid amount.
winnerPrice: Coin! # The price that the winner actually pays (2nd highest bid).
maxPrice: Coin! # Max bid amount for service provider auction.
kind: String! # Auction kind.
numProviders: Int # Number of service providers
bids: [AuctionBid] # Bids make in the auction.
bids: [AuctionBid!]! # Bids made in the auction.
}
# Record defines the basic properties of an entity in the graph database.

View File

@ -2197,9 +2197,9 @@ func (ec *executionContext) _Auction_winnerAddresses(ctx context.Context, field
}
return graphql.Null
}
res := resTmp.([]*string)
res := resTmp.([]string)
fc.Result = res
return ec.marshalNString2ᚕstring(ctx, field.Selections, res)
return ec.marshalNString2ᚕstring(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Auction_winnerAddresses(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2243,7 +2243,7 @@ func (ec *executionContext) _Auction_winnerBids(ctx context.Context, field graph
}
res := resTmp.([]*Coin)
fc.Result = res
return ec.marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx, field.Selections, res)
return ec.marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Auction_winnerBids(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -2471,11 +2471,14 @@ func (ec *executionContext) _Auction_bids(ctx context.Context, field graphql.Col
return graphql.Null
}
if resTmp == nil {
if !graphql.HasFieldError(ctx, fc) {
ec.Errorf(ctx, "must not be null")
}
return graphql.Null
}
res := resTmp.([]*AuctionBid)
fc.Result = res
return ec.marshalOAuctionBid2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx, field.Selections, res)
return ec.marshalNAuctionBid2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx, field.Selections, res)
}
func (ec *executionContext) fieldContext_Auction_bids(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
@ -8924,6 +8927,9 @@ func (ec *executionContext) _Auction(ctx context.Context, sel ast.SelectionSet,
out.Values[i] = ec._Auction_bids(ctx, field, obj)
if out.Values[i] == graphql.Null {
invalids++
}
default:
panic("unknown field " + strconv.Quote(field.Name))
}
@ -10578,6 +10584,60 @@ func (ec *executionContext) marshalNAttribute2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋla
return ec._Attribute(ctx, sel, v)
}
func (ec *executionContext) marshalNAuctionBid2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBidᚄ(ctx context.Context, sel ast.SelectionSet, v []*AuctionBid) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
fc := &graphql.FieldContext{
Index: &i,
Result: &v[i],
}
ctx := graphql.WithFieldContext(ctx, fc)
f := func(i int) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = nil
}
}()
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalNAuctionBid2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx, sel, v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
func (ec *executionContext) marshalNAuctionBid2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx context.Context, sel ast.SelectionSet, v *AuctionBid) graphql.Marshaler {
if v == nil {
if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) {
ec.Errorf(ctx, "the requested element is null which the schema does not allow")
}
return graphql.Null
}
return ec._AuctionBid(ctx, sel, v)
}
func (ec *executionContext) marshalNAuthority2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuthority(ctx context.Context, sel ast.SelectionSet, v []*Authority) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
@ -10689,7 +10749,7 @@ func (ec *executionContext) marshalNBoolean2bool(ctx context.Context, sel ast.Se
return res
}
func (ec *executionContext) marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx context.Context, sel ast.SelectionSet, v []*Coin) graphql.Marshaler {
func (ec *executionContext) marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx context.Context, sel ast.SelectionSet, v []*Coin) graphql.Marshaler {
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
@ -10713,7 +10773,7 @@ func (ec *executionContext) marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaco
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalOCoin2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx, sel, v[i])
ret[i] = ec.marshalNCoin2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx, sel, v[i])
}
if isLen1 {
f(i)
@ -10724,6 +10784,12 @@ func (ec *executionContext) marshalNCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaco
}
wg.Wait()
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
}
@ -10959,16 +11025,16 @@ func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.S
return res
}
func (ec *executionContext) unmarshalNString2ᚕstring(ctx context.Context, v interface{}) ([]*string, error) {
func (ec *executionContext) unmarshalNString2ᚕstring(ctx context.Context, v interface{}) ([]string, error) {
var vSlice []interface{}
if v != nil {
vSlice = graphql.CoerceList(v)
}
var err error
res := make([]*string, len(vSlice))
res := make([]string, len(vSlice))
for i := range vSlice {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithIndex(i))
res[i], err = ec.unmarshalOString2ᚖstring(ctx, vSlice[i])
res[i], err = ec.unmarshalNString2string(ctx, vSlice[i])
if err != nil {
return nil, err
}
@ -10976,10 +11042,16 @@ func (ec *executionContext) unmarshalNString2ᚕᚖstring(ctx context.Context, v
return res, nil
}
func (ec *executionContext) marshalNString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []*string) graphql.Marshaler {
func (ec *executionContext) marshalNString2ᚕstring(ctx context.Context, sel ast.SelectionSet, v []string) graphql.Marshaler {
ret := make(graphql.Array, len(v))
for i := range v {
ret[i] = ec.marshalOString2ᚖstring(ctx, sel, v[i])
ret[i] = ec.marshalNString2string(ctx, sel, v[i])
}
for _, e := range ret {
if e == graphql.Null {
return graphql.Null
}
}
return ret
@ -11467,54 +11539,6 @@ func (ec *executionContext) marshalOAuction2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaco
return ec._Auction(ctx, sel, v)
}
func (ec *executionContext) marshalOAuctionBid2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx context.Context, sel ast.SelectionSet, v []*AuctionBid) graphql.Marshaler {
if v == nil {
return graphql.Null
}
ret := make(graphql.Array, len(v))
var wg sync.WaitGroup
isLen1 := len(v) == 1
if !isLen1 {
wg.Add(len(v))
}
for i := range v {
i := i
fc := &graphql.FieldContext{
Index: &i,
Result: &v[i],
}
ctx := graphql.WithFieldContext(ctx, fc)
f := func(i int) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = nil
}
}()
if !isLen1 {
defer wg.Done()
}
ret[i] = ec.marshalOAuctionBid2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx, sel, v[i])
}
if isLen1 {
f(i)
} else {
go f(i)
}
}
wg.Wait()
return ret
}
func (ec *executionContext) marshalOAuctionBid2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuctionBid(ctx context.Context, sel ast.SelectionSet, v *AuctionBid) graphql.Marshaler {
if v == nil {
return graphql.Null
}
return ec._AuctionBid(ctx, sel, v)
}
func (ec *executionContext) marshalOAuthority2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐAuthority(ctx context.Context, sel ast.SelectionSet, v *Authority) graphql.Marshaler {
if v == nil {
return graphql.Null
@ -11697,13 +11721,6 @@ func (ec *executionContext) marshalOCoin2ᚕᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaco
return ret
}
func (ec *executionContext) marshalOCoin2ᚖgitᚗvdbᚗtoᚋcercᚑioᚋlaconicdᚋgqlᚐCoin(ctx context.Context, sel ast.SelectionSet, v *Coin) graphql.Marshaler {
if v == nil {
return graphql.Null
}
return ec._Coin(ctx, sel, v)
}
func (ec *executionContext) unmarshalOFloat2ᚖfloat64(ctx context.Context, v interface{}) (*float64, error) {
if v == nil {
return nil, nil

View File

@ -35,7 +35,7 @@ type Auction struct {
CommitFee *Coin `json:"commitFee"`
RevealFee *Coin `json:"revealFee"`
MinimumBid *Coin `json:"minimumBid"`
WinnerAddresses []*string `json:"winnerAddresses"`
WinnerAddresses []string `json:"winnerAddresses"`
WinnerBids []*Coin `json:"winnerBids"`
WinnerPrice *Coin `json:"winnerPrice"`
MaxPrice *Coin `json:"maxPrice"`

View File

@ -232,12 +232,6 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
return nil, nil
}
winnerAddresses := make([]*string, len(auction.WinnerAddresses))
for i, winnerAddress := range auction.WinnerAddresses {
address := winnerAddress
winnerAddresses[i] = &address
}
numProviders := int(auction.NumProviders)
gqlAuction := Auction{
@ -250,7 +244,7 @@ func GetGQLAuction(auction *auctiontypes.Auction, bids []*auctiontypes.Bid) (*Au
CommitFee: getGQLCoin(auction.CommitFee),
RevealFee: getGQLCoin(auction.RevealFee),
MinimumBid: getGQLCoin(auction.MinimumBid),
WinnerAddresses: winnerAddresses,
WinnerAddresses: auction.WinnerAddresses,
WinnerBids: getGQLCoins(auction.WinningBids),
WinnerPrice: getGQLCoin(auction.WinningPrice),
MaxPrice: getGQLCoin(auction.MaxPrice),