Skip to content

Commit

Permalink
refactor: Refactor commit nodes (#892)
Browse files Browse the repository at this point in the history
* Remove headsetScanNode

Node no longer really does anything and only serves to misdirect and confuse

* Make cid an option-type

As well as being clearer IMO in it's own right, this will make life easier shortly

* Use parsed.Cid over duplicate prop

* Dont store iteration state

Is much easier if currentCid stays local.  Had to add a couple of checks for when cid is provided as otherwise it starts to take a different (and incorrect) code-path, will likely be removed/optimized shortly.

* Remove legacy comment

* Use parsed.Depth over duplicate prop

* Use parsed.DocKey over duplicate prop

* Use parsed.Field over duplicate prop

Also fixes an explain bug where it was incorrectly reporting field as 'C'

* Simplify commit node constructor

* Set currentValue only when valid

A bit of a nitpick, but it is also now located next to where it is used/returned

* Replace legacy comment with correct comment

* Add cid related comment

* Remove type-unsafe list with slice magic

* Remove odd comment

* Remove commitSelectNode

Doesnt actually do anything anymore

* Remove commitSelectTopNode

It no longer served a purpose
  • Loading branch information
AndrewSisley authored Oct 14, 2022
1 parent 2ee445e commit 4202950
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 579 deletions.
2 changes: 1 addition & 1 deletion query/graphql/mapper/commitSelect.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type CommitSelect struct {
Depth client.Option[uint64]

// The parent Cid for which commit information has been requested.
Cid string
Cid client.Option[string]
}

func (s *CommitSelect) CloneTo(index int) Requestable {
Expand Down
7 changes: 5 additions & 2 deletions query/graphql/mapper/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

package mapper

import "github.com/sourcenetwork/defradb/core"
import (
"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/core"
)

// Select represents a request to return data from Defra.
//
Expand All @@ -24,7 +27,7 @@ type Select struct {
core.DocumentMapping

// A commit identifier that can be specified to request data at a given time.
Cid string
Cid client.Option[string]

// The name of the collection that this Select selects data from.
CollectionName string
Expand Down
4 changes: 2 additions & 2 deletions query/graphql/parser/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type CommitSelect struct {

DocKey string
FieldName client.Option[string]
Cid string
Cid client.Option[string]
Depth client.Option[uint64]

Limit *parserTypes.Limit
Expand Down Expand Up @@ -68,7 +68,7 @@ func parseCommitSelect(field *ast.Field) (*CommitSelect, error) {
commit.DocKey = raw.Value
} else if prop == parserTypes.Cid {
raw := argument.Value.(*ast.StringValue)
commit.Cid = raw.Value
commit.Cid = client.Some(raw.Value)
} else if prop == parserTypes.Field {
raw := argument.Value.(*ast.StringValue)
commit.FieldName = client.Some(raw.Value)
Expand Down
7 changes: 4 additions & 3 deletions query/graphql/parser/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/graphql-go/graphql/language/ast"

"github.com/sourcenetwork/defradb/client"
"github.com/sourcenetwork/defradb/errors"
parserTypes "github.com/sourcenetwork/defradb/query/graphql/parser/types"
)
Expand Down Expand Up @@ -57,7 +58,7 @@ type Select struct {
Alias string

DocKeys parserTypes.OptionalDocKeys
CID string
CID client.Option[string]

// QueryType indicates what kind of query this is
// Currently supports: ScanQuery, VersionedScanQuery
Expand Down Expand Up @@ -238,7 +239,7 @@ func parseSelect(rootType parserTypes.SelectionType, field *ast.Field, index int
}
} else if prop == parserTypes.Cid { // parse single CID query field
val := astValue.(*ast.StringValue)
slct.CID = val.Value
slct.CID = client.Some(val.Value)
} else if prop == parserTypes.LimitClause { // parse limit/offset
val := astValue.(*ast.IntValue)
i, err := strconv.ParseInt(val.Value, 10, 64)
Expand Down Expand Up @@ -281,7 +282,7 @@ func parseSelect(rootType parserTypes.SelectionType, field *ast.Field, index int
}
}

if len(slct.DocKeys.Value) != 0 && len(slct.CID) != 0 {
if len(slct.DocKeys.Value) != 0 && slct.CID.HasValue() {
slct.QueryType = parserTypes.VersionedScanQuery
} else {
slct.QueryType = parserTypes.ScanQuery
Expand Down
Loading

0 comments on commit 4202950

Please sign in to comment.