Skip to content
This repository has been archived by the owner on Feb 15, 2023. It is now read-only.

Commit

Permalink
added tests for batched and fallback sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeBrew28 committed Jul 29, 2019
1 parent 465792a commit 3da7303
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions graphql/schemabuilder/types.go
Expand Up @@ -101,8 +101,11 @@ func BatchFilterFieldWithFallback(name string, batchFilter interface{}, filter i
return fieldFuncTextFilterFields
}

func SortField(name string, sort interface{}) FieldFuncOption {
func SortField(name string, sort interface{}, options ...FieldFuncOption) FieldFuncOption {
sortMethod := &method{Fn: sort, Batch: false, MarkedNonNullable: true}
for _, opt := range options {
opt.apply(sortMethod)
}
var fieldFuncSortFields fieldFuncOptionFunc = func(m *method) {
if m.SortMethods == nil {
m.SortMethods = map[string]*method{}
Expand All @@ -115,8 +118,11 @@ func SortField(name string, sort interface{}) FieldFuncOption {
return fieldFuncSortFields
}

func BatchSortField(name string, batchSort interface{}) FieldFuncOption {
func BatchSortField(name string, batchSort interface{}, options ...FieldFuncOption) FieldFuncOption {
sortMethod := &method{Fn: batchSort, Batch: true, MarkedNonNullable: true}
for _, opt := range options {
opt.apply(sortMethod)
}
var fieldFuncSortFields fieldFuncOptionFunc = func(m *method) {
if m.SortMethods == nil {
m.SortMethods = map[string]*method{}
Expand All @@ -129,15 +135,17 @@ func BatchSortField(name string, batchSort interface{}) FieldFuncOption {
return fieldFuncSortFields
}

func BatchSortFieldWithFallback(name string, batchSort interface{}, sort interface{}, flag func(context.Context) bool) FieldFuncOption {
func BatchSortFieldWithFallback(name string, batchSort interface{}, sort interface{}, flag func(context.Context) bool, options ...FieldFuncOption) FieldFuncOption {
sortMethod := &method{
Fn: batchSort,
BatchArgs: batchArgs{
FallbackFunc: sort,
ShouldUseFallbackFunc: flag,
}, Batch: true,
MarkedNonNullable: true}

for _, opt := range options {
opt.apply(sortMethod)
}
var fieldFuncSortFields fieldFuncOptionFunc = func(m *method) {
if m.SortMethods == nil {
m.SortMethods = map[string]*method{}
Expand Down

0 comments on commit 3da7303

Please sign in to comment.