feat: add cursor for pagination

This commit is contained in:
Lakhan Samani 2022-09-26 23:50:24 +05:30
parent 19e2153379
commit 25cb9a831b
3 changed files with 732 additions and 676 deletions

View File

@ -184,6 +184,7 @@ type ComplexityRoot struct {
} }
Pagination struct { Pagination struct {
Cursor func(childComplexity int) int
Limit func(childComplexity int) int Limit func(childComplexity int) int
Offset func(childComplexity int) int Offset func(childComplexity int) int
Page func(childComplexity int) int Page func(childComplexity int) int
@ -1301,6 +1302,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Mutation.VerifyOtp(childComplexity, args["params"].(model.VerifyOTPRequest)), true return e.complexity.Mutation.VerifyOtp(childComplexity, args["params"].(model.VerifyOTPRequest)), true
case "Pagination.cursor":
if e.complexity.Pagination.Cursor == nil {
break
}
return e.complexity.Pagination.Cursor(childComplexity), true
case "Pagination.limit": case "Pagination.limit":
if e.complexity.Pagination.Limit == nil { if e.complexity.Pagination.Limit == nil {
break break
@ -1905,6 +1913,7 @@ scalar Any
type Pagination { type Pagination {
limit: Int64! limit: Int64!
page: Int64! page: Int64!
cursor: String
offset: Int64! offset: Int64!
total: Int64! total: Int64!
} }
@ -2257,6 +2266,7 @@ input SessionQueryInput {
input PaginationInput { input PaginationInput {
limit: Int64 limit: Int64
page: Int64 page: Int64
cursor: String
} }
input PaginatedInput { input PaginatedInput {
@ -7141,6 +7151,38 @@ func (ec *executionContext) _Pagination_page(ctx context.Context, field graphql.
return ec.marshalNInt642int64(ctx, field.Selections, res) return ec.marshalNInt642int64(ctx, field.Selections, res)
} }
func (ec *executionContext) _Pagination_cursor(ctx context.Context, field graphql.CollectedField, obj *model.Pagination) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
fc := &graphql.FieldContext{
Object: "Pagination",
Field: field,
Args: nil,
IsMethod: false,
IsResolver: false,
}
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.Cursor, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.(*string)
fc.Result = res
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
}
func (ec *executionContext) _Pagination_offset(ctx context.Context, field graphql.CollectedField, obj *model.Pagination) (ret graphql.Marshaler) { func (ec *executionContext) _Pagination_offset(ctx context.Context, field graphql.CollectedField, obj *model.Pagination) (ret graphql.Marshaler) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@ -11145,6 +11187,14 @@ func (ec *executionContext) unmarshalInputPaginationInput(ctx context.Context, o
if err != nil { if err != nil {
return it, err return it, err
} }
case "cursor":
var err error
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("cursor"))
it.Cursor, err = ec.unmarshalOString2ᚖstring(ctx, v)
if err != nil {
return it, err
}
} }
} }
@ -12928,6 +12978,8 @@ func (ec *executionContext) _Pagination(ctx context.Context, sel ast.SelectionSe
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
invalids++ invalids++
} }
case "cursor":
out.Values[i] = ec._Pagination_cursor(ctx, field, obj)
case "offset": case "offset":
out.Values[i] = ec._Pagination_offset(ctx, field, obj) out.Values[i] = ec._Pagination_offset(ctx, field, obj)
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {

View File

@ -186,6 +186,7 @@ type PaginatedInput struct {
type Pagination struct { type Pagination struct {
Limit int64 `json:"limit"` Limit int64 `json:"limit"`
Page int64 `json:"page"` Page int64 `json:"page"`
Cursor *string `json:"cursor"`
Offset int64 `json:"offset"` Offset int64 `json:"offset"`
Total int64 `json:"total"` Total int64 `json:"total"`
} }
@ -193,6 +194,7 @@ type Pagination struct {
type PaginationInput struct { type PaginationInput struct {
Limit *int64 `json:"limit"` Limit *int64 `json:"limit"`
Page *int64 `json:"page"` Page *int64 `json:"page"`
Cursor *string `json:"cursor"`
} }
type ResendOTPRequest struct { type ResendOTPRequest struct {

View File

@ -8,6 +8,7 @@ scalar Any
type Pagination { type Pagination {
limit: Int64! limit: Int64!
page: Int64! page: Int64!
cursor: String
offset: Int64! offset: Int64!
total: Int64! total: Int64!
} }
@ -360,6 +361,7 @@ input SessionQueryInput {
input PaginationInput { input PaginationInput {
limit: Int64 limit: Int64
page: Int64 page: Int64
cursor: String
} }
input PaginatedInput { input PaginatedInput {