Skip to content

Commit

Permalink
feat: Add cid support for allCommits (sourcenetwork#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley authored Sep 23, 2022
1 parent 8b23d8c commit 31abc4a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
13 changes: 12 additions & 1 deletion query/graphql/planner/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ func (p *Planner) commitSelectBlock(parsed *mapper.CommitSelect) (*commitSelectN
func (p *Planner) commitSelectAll(parsed *mapper.CommitSelect) (*commitSelectNode, error) {
dag := p.DAGScan(parsed)
headset := p.HeadScan(parsed)

if parsed.Cid != "" {
c, err := cid.Decode(parsed.Cid)
if err != nil {
return nil, err
}
dag.cid = &c
} else {
// only set this if a cid has not been provided
dag.depthLimit = math.MaxUint32 // infinite depth
}

// @todo: Get Collection field ID
if parsed.FieldName == "" {
parsed.FieldName = core.COMPOSITE_NAMESPACE
Expand All @@ -183,7 +195,6 @@ func (p *Planner) commitSelectAll(parsed *mapper.CommitSelect) (*commitSelectNod
headset.key = key
}
dag.headset = headset
dag.depthLimit = math.MaxUint32 // infinite depth
// dag.key = &key
commit := &commitSelectNode{
p: p,
Expand Down
2 changes: 1 addition & 1 deletion query/graphql/planner/dagscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (n *dagScanNode) Next() (bool, error) {
}
n.queuedCids.Remove(c)
n.cid = &cid
} else if n.headset != nil {
} else if n.cid == nil && n.headset != nil {
if next, err := n.headset.Next(); !next {
return false, err
}
Expand Down
1 change: 1 addition & 0 deletions query/graphql/schema/types/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ var (
"dockey": NewArgConfig(gql.NewNonNull(gql.ID)),
"field": NewArgConfig(gql.String),
"order": NewArgConfig(AllCommitsOrderArg),
"cid": NewArgConfig(gql.ID),
parserTypes.LimitClause: NewArgConfig(gql.Int),
parserTypes.OffsetClause: NewArgConfig(gql.Int),
},
Expand Down
55 changes: 55 additions & 0 deletions tests/integration/query/all_commits/with_dockey_cid_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2022 Democratized Data Foundation
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package all_commits

import (
"testing"

testUtils "github.com/sourcenetwork/defradb/tests/integration"
)

func TestQueryAllCommitsWithDockeyAndCid(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Simple all commits query with dockey, order height desc",
Query: `query {
allCommits(
dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f",
cid: "bafybeibrbfg35mwggcj4vnskak4qn45hp7fy5a4zp2n34sbq5vt5utr6pq"
) {
cid
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Updates: map[int]map[int][]string{
0: {
0: {
`{
"Age": 22
}`,
},
},
},
Results: []map[string]any{
{
"cid": "bafybeibrbfg35mwggcj4vnskak4qn45hp7fy5a4zp2n34sbq5vt5utr6pq",
},
},
}

executeTestCase(t, test)
}

0 comments on commit 31abc4a

Please sign in to comment.