Skip to content

Commit

Permalink
feat: Make topLevelNode explainable (#737)
Browse files Browse the repository at this point in the history
- Resolves #736

- Description: makes `topLevelNode` explainable without changing the `Source()` function to fetch child graphs.
 #626 will be done in a separate PR once `topLevelNode.Source()` is updated.
  • Loading branch information
shahzadlone authored Aug 15, 2022
1 parent e00ca5a commit e18c872
Show file tree
Hide file tree
Showing 4 changed files with 319 additions and 0 deletions.
4 changes: 4 additions & 0 deletions query/graphql/planner/top.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func (n *topLevelNode) Source() planNode {
return nil
}

func (n *topLevelNode) Explain() (map[string]any, error) {
return map[string]any{}, nil
}

func (n *topLevelNode) Next() (bool, error) {
if n.isdone {
return false, nil
Expand Down
106 changes: 106 additions & 0 deletions tests/integration/query/explain/top_with_average_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// 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 test_explain

import (
"testing"

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

func TestExplainTopLevelAverageQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level average query.",

Query: `query @explain {
_avg(
author: {
field: age
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 28
}`,
`{
"name": "Bob",
"verified": true,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelAverageQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level average query with filter.",
Query: `query @explain {
_avg(
author: {
field: age,
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": false,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}
102 changes: 102 additions & 0 deletions tests/integration/query/explain/top_with_count_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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 test_explain

import (
"testing"

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

func TestExplainTopLevelCountQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level count query.",

Query: `query @explain {
_count(author: {})
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": true,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelCountQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level count query with filter.",

Query: `query @explain {
_count(
author: {
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": true,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}
107 changes: 107 additions & 0 deletions tests/integration/query/explain/top_with_sum_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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 test_explain

import (
"testing"

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

func TestExplainTopLevelSumQuery(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level sum query.",

Query: `query @explain {
_sum(
author: {
field: age
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": true,
"age": 21
}`,
`{
"name": "Bob",
"verified": true,
"age": 30
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

func TestExplainTopLevelSumQueryWithFilter(t *testing.T) {
test := testUtils.QueryTestCase{
Description: "Explain top-level sum query with filter.",

Query: `query @explain {
_sum(
author: {
field: age,
filter: {
age: {
_gt: 26
}
}
}
)
}`,

Docs: map[int][]string{
//authors
2: {
`{
"name": "John",
"verified": false,
"age": 21
}`,
`{
"name": "Bob",
"verified": false,
"age": 30
}`,
`{
"name": "Alice",
"verified": true,
"age": 32
}`,
},
},

Results: []dataMap{
{
"explain": dataMap{
"topLevelNode": dataMap{},
},
},
},
}

executeTestCase(t, test)
}

0 comments on commit e18c872

Please sign in to comment.