Skip to content

Commit

Permalink
Return error if field to count is not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jan 25, 2022
1 parent d7aea48 commit 26c6861
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
11 changes: 1 addition & 10 deletions db/tests/query/simple/with_group_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,7 @@ func TestQuerySimpleWithGroupByNumberWithUndefinedField(t *testing.T) {
"Age": 19
}`)},
},
Results: []map[string]interface{}{
{
"Age": uint64(32),
"_count": 0,
},
{
"Age": uint64(19),
"_count": 0,
},
},
ExpectedError: "Count must be provided with a property to count.",
}

executeTestCase(t, test)
Expand Down
5 changes: 5 additions & 0 deletions query/graphql/planner/count.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ package planner
// aggregates in.

import (
"fmt"
"reflect"

"github.com/sourcenetwork/defradb/core"
Expand All @@ -29,6 +30,10 @@ type countNode struct {
}

func (p *Planner) Count(c *parser.Count, virtualFieldId string) (*countNode, error) {
if c.Field == "" {
return nil, fmt.Errorf("Count must be provided with a property to count.")
}

return &countNode{
p: p,
sourceProperty: c.Field,
Expand Down

0 comments on commit 26c6861

Please sign in to comment.