Skip to content

Commit

Permalink
Add support for grouping commits by fieldId
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed May 4, 2023
1 parent 9b9e688 commit 13ff861
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
4 changes: 4 additions & 0 deletions request/graphql/schema/types/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ var (
Value: "fieldName",
Description: commitFieldNameFieldDescription,
},
"fieldId": &gql.EnumValueConfig{
Value: "fieldId",
Description: commitFieldIDFieldDescription,
},
},
},
)
Expand Down
110 changes: 110 additions & 0 deletions tests/integration/query/commits/with_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,113 @@ func TestQueryCommitsWithGroupByFieldNameWithChild(t *testing.T) {

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

func TestQueryCommitsWithGroupByFieldID(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple all commits query, group by fieldId",
Actions: []any{
updateUserCollectionSchema(),
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"age": 21
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"age": 22
}`,
},
testUtils.Request{
Request: ` {
commits(groupBy: [fieldId]) {
fieldId
}
}`,
Results: []map[string]any{
{
"fieldId": "1",
},
{
"fieldId": "2",
},
{
"fieldId": "C",
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

func TestQueryCommitsWithGroupByFieldIDWithChild(t *testing.T) {
test := testUtils.TestCase{
Description: "Simple all commits query, group by fieldId",
Actions: []any{
updateUserCollectionSchema(),
testUtils.CreateDoc{
CollectionID: 0,
Doc: `{
"name": "John",
"age": 21
}`,
},
testUtils.UpdateDoc{
CollectionID: 0,
DocID: 0,
Doc: `{
"age": 22
}`,
},
testUtils.Request{
Request: ` {
commits(groupBy: [fieldId]) {
fieldId
_group {
height
}
}
}`,
Results: []map[string]any{
{
"fieldId": "1",
"_group": []map[string]any{
{
"height": int64(2),
},
{
"height": int64(1),
},
},
},
{
"fieldId": "2",
"_group": []map[string]any{
{
"height": int64(1),
},
},
},
{
"fieldId": "C",
"_group": []map[string]any{
{
"height": int64(2),
},
{
"height": int64(1),
},
},
},
},
},
},
}

testUtils.ExecuteTestCase(t, []string{"Users"}, test)
}

0 comments on commit 13ff861

Please sign in to comment.