Configure pagination in getRecords GQL query

This commit is contained in:
IshaVenikar 2024-08-29 15:47:36 +05:30 committed by Prathamesh Musale
parent debfb82205
commit ad2f43f027
3 changed files with 35 additions and 5 deletions

View File

@ -246,6 +246,8 @@ type Query {
# Whether to query all records, not just named ones (false by default). # Whether to query all records, not just named ones (false by default).
all: Boolean all: Boolean
limit: Int
offset: Int
): [Record] ): [Record]
# #

View File

@ -185,7 +185,7 @@ type ComplexityRoot struct {
LookupNames func(childComplexity int, names []string) int LookupNames func(childComplexity int, names []string) int
QueryBonds func(childComplexity int, attributes []*KeyValueInput) int QueryBonds func(childComplexity int, attributes []*KeyValueInput) int
QueryBondsByOwner func(childComplexity int, ownerAddresses []string) int QueryBondsByOwner func(childComplexity int, ownerAddresses []string) int
QueryRecords func(childComplexity int, attributes []*KeyValueInput, all *bool) int QueryRecords func(childComplexity int, attributes []*KeyValueInput, all *bool, limit *int, offset *int) int
ResolveNames func(childComplexity int, names []string) int ResolveNames func(childComplexity int, names []string) int
} }
@ -236,7 +236,7 @@ type QueryResolver interface {
QueryBonds(ctx context.Context, attributes []*KeyValueInput) ([]*Bond, error) QueryBonds(ctx context.Context, attributes []*KeyValueInput) ([]*Bond, error)
QueryBondsByOwner(ctx context.Context, ownerAddresses []string) ([]*OwnerBonds, error) QueryBondsByOwner(ctx context.Context, ownerAddresses []string) ([]*OwnerBonds, error)
GetRecordsByIds(ctx context.Context, ids []string) ([]*Record, error) GetRecordsByIds(ctx context.Context, ids []string) ([]*Record, error)
QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool) ([]*Record, error) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error)
GetAuthorities(ctx context.Context, owner *string) ([]*Authority, error) GetAuthorities(ctx context.Context, owner *string) ([]*Authority, error)
LookupAuthorities(ctx context.Context, names []string) ([]*AuthorityRecord, error) LookupAuthorities(ctx context.Context, names []string) ([]*AuthorityRecord, error)
LookupNames(ctx context.Context, names []string) ([]*NameRecord, error) LookupNames(ctx context.Context, names []string) ([]*NameRecord, error)
@ -873,7 +873,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return 0, false return 0, false
} }
return e.complexity.Query.QueryRecords(childComplexity, args["attributes"].([]*KeyValueInput), args["all"].(*bool)), true return e.complexity.Query.QueryRecords(childComplexity, args["attributes"].([]*KeyValueInput), args["all"].(*bool), args["limit"].(*int), args["offset"].(*int)), true
case "Query.resolveNames": case "Query.resolveNames":
if e.complexity.Query.ResolveNames == nil { if e.complexity.Query.ResolveNames == nil {
@ -1330,6 +1330,24 @@ func (ec *executionContext) field_Query_queryRecords_args(ctx context.Context, r
} }
} }
args["all"] = arg1 args["all"] = arg1
var arg2 *int
if tmp, ok := rawArgs["limit"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("limit"))
arg2, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["limit"] = arg2
var arg3 *int
if tmp, ok := rawArgs["offset"]; ok {
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("offset"))
arg3, err = ec.unmarshalOInt2ᚖint(ctx, tmp)
if err != nil {
return nil, err
}
}
args["offset"] = arg3
return args, nil return args, nil
} }
@ -4766,7 +4784,7 @@ func (ec *executionContext) _Query_queryRecords(ctx context.Context, field graph
}() }()
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children ctx = rctx // use context from middleware stack in children
return ec.resolvers.Query().QueryRecords(rctx, fc.Args["attributes"].([]*KeyValueInput), fc.Args["all"].(*bool)) return ec.resolvers.Query().QueryRecords(rctx, fc.Args["attributes"].([]*KeyValueInput), fc.Args["all"].(*bool), fc.Args["limit"].(*int), fc.Args["offset"].(*int))
}) })
if err != nil { if err != nil {
ec.Error(ctx, err) ec.Error(ctx, err)

View File

@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
@ -136,14 +137,23 @@ func (q queryResolver) LookupNames(ctx context.Context, names []string) ([]*Name
return gqlResponse, nil return gqlResponse, nil
} }
func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool) ([]*Record, error) { func (q queryResolver) QueryRecords(ctx context.Context, attributes []*KeyValueInput, all *bool, limit *int, offset *int) ([]*Record, error) {
nsQueryClient := registrytypes.NewQueryClient(q.ctx) nsQueryClient := registrytypes.NewQueryClient(q.ctx)
pagination := &query.PageRequest{}
if limit != nil {
pagination.Limit = uint64(*limit)
}
if offset != nil {
pagination.Offset = uint64(*offset)
}
res, err := nsQueryClient.Records( res, err := nsQueryClient.Records(
context.Background(), context.Background(),
&registrytypes.QueryRecordsRequest{ &registrytypes.QueryRecordsRequest{
Attributes: toRPCAttributes(attributes), Attributes: toRPCAttributes(attributes),
All: (all != nil && *all), All: (all != nil && *all),
Pagination: pagination,
}, },
) )
if err != nil { if err != nil {