Skip to content

Commit

Permalink
Add SchemaVersionId to commit query
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Jan 30, 2023
1 parent ce5ad6d commit 6b75761
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 5 deletions.
12 changes: 7 additions & 5 deletions client/request/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ const (
LatestCommitsName = "latestCommits"
CommitsName = "commits"

CommitTypeName = "Commit"
LinksFieldName = "links"
HeightFieldName = "height"
CidFieldName = "cid"
DeltaFieldName = "delta"
CommitTypeName = "Commit"
LinksFieldName = "links"
HeightFieldName = "height"
CidFieldName = "cid"
SchemaVersionIDFieldName = "schemaVersionId"
DeltaFieldName = "delta"

LinksNameFieldName = "name"
LinksCidFieldName = "cid"
Expand Down Expand Up @@ -85,6 +86,7 @@ var (
VersionFields = []string{
HeightFieldName,
CidFieldName,
SchemaVersionIDFieldName,
DeltaFieldName,
}

Expand Down
5 changes: 5 additions & 0 deletions planner/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,11 @@ func (n *dagScanNode) dagBlockToNodeDoc(block blocks.Block) (core.Doc, []*ipld.L
return core.Doc{}, nil, ErrDeltaMissingPriority
}

schemaVersionId, ok := delta["SchemaVersionID"].(string)
if ok {
n.parsed.DocumentMapping.SetFirstOfName(&commit, "schemaVersionId", schemaVersionId)
}

n.parsed.DocumentMapping.SetFirstOfName(&commit, "height", int64(prio))
n.parsed.DocumentMapping.SetFirstOfName(&commit, "delta", delta["Data"])

Expand Down
3 changes: 3 additions & 0 deletions planner/mapper/commitSelect.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type CommitSelect struct {

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

// The SchemaVersionID at the time of commit.
SchemaVersionID immutable.Option[string]
}

func (s *CommitSelect) CloneTo(index int) Requestable {
Expand Down
4 changes: 4 additions & 0 deletions request/graphql/schema/types/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
// type Commit {
// Height: Int
// CID: String
// SchemaVersionID: String
// Delta: String
// Previous: [Commit]
// Links: [Commit]
Expand All @@ -45,6 +46,9 @@ var (
"cid": &gql.Field{
Type: gql.String,
},
"schemaVersionId": &gql.Field{
Type: gql.String,
},
"delta": &gql.Field{
Type: gql.String,
},
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/query/commits/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,39 @@ func TestQueryCommitsMultipleDocs(t *testing.T) {

executeTestCase(t, test)
}

func TestQueryCommitsWithSchemaVersionIdField(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Simple commits query yielding schemaVersionId",
Request: `query {
commits {
cid
schemaVersionId
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]any{
{
"cid": "bafybeigju7dgicfq3fxvtlxtjao7won4xc7kusykkvumngjfx5i2c7ibny",
"schemaVersionId": "bafkreihaqmvbjvm2q4iwkjnuafavvsakiaztlqnridiybxystfm27uwlde",
},
{
"cid": "bafybeiaqarrcayyoly2gdiam6mhh72ls4azwa7brozxxc3q2srnggkkqkq",
"schemaVersionId": "bafkreihaqmvbjvm2q4iwkjnuafavvsakiaztlqnridiybxystfm27uwlde",
},
{
"cid": "bafybeid5l577igkgcn6wjqjeqxlta4dcc3a3iykwkborf4fklaenjuctoq",
"schemaVersionId": "bafkreihaqmvbjvm2q4iwkjnuafavvsakiaztlqnridiybxystfm27uwlde",
},
},
}

executeTestCase(t, test)
}
30 changes: 30 additions & 0 deletions tests/integration/query/commits/with_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,33 @@ func TestQueryCommitsWithCompositeFieldId(t *testing.T) {

executeTestCase(t, test)
}

// This test is for documentation reasons only. This is not
// desired behaviour (users should not be specifying field ids).
func TestQueryCommitsWithCompositeFieldIdWithReturnedSchemaVersionId(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Simple all commits query with dockey and field id",
Request: `query {
commits(field: "C") {
cid
schemaVersionId
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]any{
{
"cid": "bafybeid5l577igkgcn6wjqjeqxlta4dcc3a3iykwkborf4fklaenjuctoq",
"schemaVersionId": "bafkreihaqmvbjvm2q4iwkjnuafavvsakiaztlqnridiybxystfm27uwlde",
},
},
}

executeTestCase(t, test)
}
28 changes: 28 additions & 0 deletions tests/integration/query/latest_commits/with_dockey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,31 @@ func TestQueryLatestCommitsWithDocKey(t *testing.T) {

executeTestCase(t, test)
}

func TestQueryLatestCommitsWithDocKeyWithSchemaVersionIdField(t *testing.T) {
test := testUtils.RequestTestCase{
Description: "Simple latest commits query with dockey and schema versiion id field",
Request: `query {
latestCommits(dockey: "bae-52b9170d-b77a-5887-b877-cbdbb99b009f") {
cid
schemaVersionId
}
}`,
Docs: map[int][]string{
0: {
`{
"Name": "John",
"Age": 21
}`,
},
},
Results: []map[string]any{
{
"cid": "bafybeid5l577igkgcn6wjqjeqxlta4dcc3a3iykwkborf4fklaenjuctoq",
"schemaVersionId": "bafkreihaqmvbjvm2q4iwkjnuafavvsakiaztlqnridiybxystfm27uwlde",
},
},
}

executeTestCase(t, test)
}

0 comments on commit 6b75761

Please sign in to comment.