diff --git a/gql/cerc-io/laconicd/schema.graphql b/gql/cerc-io/laconicd/schema.graphql index c3fac8f6..8d0498a4 100644 --- a/gql/cerc-io/laconicd/schema.graphql +++ b/gql/cerc-io/laconicd/schema.graphql @@ -246,6 +246,8 @@ type Query { # Whether to query all records, not just named ones (false by default). all: Boolean + limit: Int + offset: Int ): [Record] # diff --git a/gql/generated.go b/gql/generated.go index a243f6df..8b3da296 100644 --- a/gql/generated.go +++ b/gql/generated.go @@ -185,7 +185,7 @@ type ComplexityRoot struct { LookupNames func(childComplexity int, names []string) int QueryBonds func(childComplexity int, attributes []*KeyValueInput) 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 } @@ -236,7 +236,7 @@ type QueryResolver interface { QueryBonds(ctx context.Context, attributes []*KeyValueInput) ([]*Bond, error) QueryBondsByOwner(ctx context.Context, ownerAddresses []string) ([]*OwnerBonds, 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) LookupAuthorities(ctx context.Context, names []string) ([]*AuthorityRecord, 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 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": if e.complexity.Query.ResolveNames == nil { @@ -1330,6 +1330,24 @@ func (ec *executionContext) field_Query_queryRecords_args(ctx context.Context, r } } 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 } @@ -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) { 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 { ec.Error(ctx, err) diff --git a/gql/resolver.go b/gql/resolver.go index 5a7cb106..4216470b 100644 --- a/gql/resolver.go +++ b/gql/resolver.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" types "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/query" authtypes "github.com/cosmos/cosmos-sdk/x/auth/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 } -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) + pagination := &query.PageRequest{} + if limit != nil { + pagination.Limit = uint64(*limit) + } + if offset != nil { + pagination.Offset = uint64(*offset) + } + res, err := nsQueryClient.Records( context.Background(), ®istrytypes.QueryRecordsRequest{ Attributes: toRPCAttributes(attributes), All: (all != nil && *all), + Pagination: pagination, }, ) if err != nil {