diff --git a/cmd/graphql.ethereum/graph/generated.go b/cmd/graphql.ethereum/graph/generated.go index 5a9ada2..1002c73 100644 --- a/cmd/graphql.ethereum/graph/generated.go +++ b/cmd/graphql.ethereum/graph/generated.go @@ -133,7 +133,7 @@ type CampaignResolver interface { Telegram(ctx context.Context, obj *types.Campaign) (*string, error) Web(ctx context.Context, obj *types.Campaign) (*string, error) - InvestmentAmounts(ctx context.Context, obj *types.Campaign) ([]types.InvestmentAmounts, error) + InvestmentAmounts(ctx context.Context, obj *types.Campaign) ([]*types.InvestmentAmounts, error) } type ChangelogResolver interface { ID(ctx context.Context, obj *changelog.Changelog) (string, error) @@ -1732,11 +1732,14 @@ func (ec *executionContext) _Campaign_investmentAmounts(ctx context.Context, fie return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.([]types.InvestmentAmounts) + res := resTmp.([]*types.InvestmentAmounts) fc.Result = res - return ec.marshalOInvestmentAmounts2ᚕgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmountsᚄ(ctx, field.Selections, res) + return ec.marshalNInvestmentAmounts2ᚕᚖgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Campaign_investmentAmounts(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -5315,13 +5318,16 @@ func (ec *executionContext) _Campaign(ctx context.Context, sel ast.SelectionSet, case "investmentAmounts": field := field - innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) { + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) } }() res = ec._Campaign_investmentAmounts(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } return res } @@ -6342,8 +6348,42 @@ func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.Selecti return res } -func (ec *executionContext) marshalNInvestmentAmounts2githubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(ctx context.Context, sel ast.SelectionSet, v types.InvestmentAmounts) graphql.Marshaler { - return ec._InvestmentAmounts(ctx, sel, &v) +func (ec *executionContext) marshalNInvestmentAmounts2ᚕᚖgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(ctx context.Context, sel ast.SelectionSet, v []*types.InvestmentAmounts) 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.marshalOInvestmentAmounts2ᚖgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + + return ret } func (ec *executionContext) unmarshalNModification2githubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋcmdᚋgraphqlᚗethereumᚋgraphᚋmodelᚐModification(ctx context.Context, v interface{}) (model.Modification, error) { @@ -6800,51 +6840,11 @@ func (ec *executionContext) marshalOChangelog2ᚖgithubᚗcomᚋfluidityᚑmoney return ec._Changelog(ctx, sel, v) } -func (ec *executionContext) marshalOInvestmentAmounts2ᚕgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmountsᚄ(ctx context.Context, sel ast.SelectionSet, v []types.InvestmentAmounts) graphql.Marshaler { +func (ec *executionContext) marshalOInvestmentAmounts2ᚖgithubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(ctx context.Context, sel ast.SelectionSet, v *types.InvestmentAmounts) 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.marshalNInvestmentAmounts2githubᚗcomᚋfluidityᚑmoneyᚋ9livesᚗsoᚋlibᚋtypesᚐInvestmentAmounts(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 + return ec._InvestmentAmounts(ctx, sel, v) } func (ec *executionContext) unmarshalOString2string(ctx context.Context, v interface{}) (string, error) { diff --git a/cmd/graphql.ethereum/graph/schema.graphqls b/cmd/graphql.ethereum/graph/schema.graphqls index b5d84d9..75fbc41 100644 --- a/cmd/graphql.ethereum/graph/schema.graphqls +++ b/cmd/graphql.ethereum/graph/schema.graphqls @@ -319,7 +319,7 @@ type Campaign { """ Represents investment results bytes8 ids to amounts. """ - investmentAmounts: [InvestmentAmounts!] + investmentAmounts: [InvestmentAmounts]! } type InvestmentAmounts { diff --git a/cmd/graphql.ethereum/graph/schema.resolvers.go b/cmd/graphql.ethereum/graph/schema.resolvers.go index b918535..02cdb3e 100644 --- a/cmd/graphql.ethereum/graph/schema.resolvers.go +++ b/cmd/graphql.ethereum/graph/schema.resolvers.go @@ -150,11 +150,11 @@ func (r *campaignResolver) Web(ctx context.Context, obj *types.Campaign) (*strin } // InvestmentAmounts is the resolver for the investmentAmounts field. -func (r *campaignResolver) InvestmentAmounts(ctx context.Context, obj *types.Campaign) ([]types.InvestmentAmounts, error) { +func (r *campaignResolver) InvestmentAmounts(ctx context.Context, obj *types.Campaign) ([]*types.InvestmentAmounts, error) { if obj == nil { return nil, fmt.Errorf("campaign is nil") } - return obj.Content.InvestmentAmounts, nil + return obj.InvestmentAmounts, nil } // ID is the resolver for the id field. diff --git a/lib/types/types.go b/lib/types/types.go index 4829f5e..41810da 100644 --- a/lib/types/types.go +++ b/lib/types/types.go @@ -9,12 +9,13 @@ import ( type ( Campaign struct { - ID string `gorm:"primaryKey"` - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` - Content CampaignContent `json:"content"` - TotalVolume int `json:"totalVolume"` - Winner string `json:"winner"` + ID string `gorm:"primaryKey"` + CreatedAt time.Time `gorm:"autoCreateTime"` + UpdatedAt time.Time `gorm:"autoUpdateTime"` + Content CampaignContent `json:"content"` + TotalVolume int `json:"totalVolume"` + Winner string `json:"winner"` + InvestmentAmounts InvestmentAmountsList `json:"investmentAmounts" gorm:"type:jsonb"` } InvestmentAmounts struct { @@ -22,6 +23,8 @@ type ( Amount int `json:"amount"` } + InvestmentAmountsList []*InvestmentAmounts + Outcome struct { // Name of this campaign. Name string `json:"name"` @@ -90,9 +93,6 @@ type ( // Web url Web *string `json:"web"` - - // Represents current investment amounts. - InvestmentAmounts []InvestmentAmounts `json:"investmentAmounts"` } // Wallet of the creator of a campaign. @@ -167,6 +167,22 @@ func (content *CampaignContent) Scan(value interface{}) error { return JSONUnmarshal(value, content) } +func (ai InvestmentAmounts) Value() (driver.Value, error) { + return JSONMarshal(ai) +} + +func (ai InvestmentAmounts) Scan(value interface{}) error { + return JSONUnmarshal(value, ai) +} + +func (ai InvestmentAmountsList) Value() (driver.Value, error) { + return JSONMarshal(ai) +} + +func (ai *InvestmentAmountsList) Scan(value interface{}) error { + return JSONUnmarshal(value, ai) +} + type Frontpage struct { Campaigns []Campaign `json:"campaigns"` }