-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiple relationships between same collections
- Loading branch information
1 parent
914d386
commit 6932fd2
Showing
8 changed files
with
684 additions
and
24 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2020 Source Inc. | ||
// | ||
// 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 one_to_two_many | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/db/tests" | ||
) | ||
|
||
var bookAuthorGQLSchema = (` | ||
type book { | ||
name: String | ||
rating: Float | ||
price: price | ||
author: author @relation(name: "written_books") | ||
reviewedBy: author @relation(name: "reviewed_books") | ||
} | ||
type author { | ||
name: String | ||
age: Int | ||
verified: Boolean | ||
written: [book] @relation(name: "written_books") | ||
reviewed: [book] @relation(name: "reviewed_books") | ||
} | ||
type price { | ||
currency: String | ||
value: Float | ||
books: [book] | ||
} | ||
`) | ||
|
||
func executeTestCase(t *testing.T, test testUtils.QueryTestCase) { | ||
testUtils.ExecuteQueryTestCase(t, bookAuthorGQLSchema, []string{"book", "author", "price"}, test) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright 2020 Source Inc. | ||
// | ||
// 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 one_to_two_many | ||
|
||
import ( | ||
"testing" | ||
|
||
testUtils "github.com/sourcenetwork/defradb/db/tests" | ||
) | ||
|
||
func TestQueryOneToTwoManyWithSort(t *testing.T) { | ||
tests := []testUtils.QueryTestCase{ | ||
{ | ||
Description: "One-to-many relation query from one side, sort in opposite directions on children", | ||
Query: `query { | ||
author { | ||
name | ||
written (order: {rating: ASC}) { | ||
name | ||
} | ||
reviewed (order: {rating: DESC}){ | ||
name | ||
rating | ||
} | ||
} | ||
}`, | ||
Docs: map[int][]string{ | ||
//books | ||
0: { | ||
(`{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", | ||
"reviewedBy_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04" | ||
}`), | ||
(`{ | ||
"name": "A Time for Mercy", | ||
"rating": 4.5, | ||
"author_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3", | ||
"reviewedBy_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`), | ||
(`{ | ||
"name": "Theif Lord", | ||
"rating": 4.8, | ||
"author_id": "bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04", | ||
"reviewedBy_id": "bae-41598f0c-19bc-5da6-813b-e80f14a10df3" | ||
}`), | ||
}, | ||
//authors | ||
1: { | ||
// bae-41598f0c-19bc-5da6-813b-e80f14a10df3 | ||
(`{ | ||
"name": "John Grisham", | ||
"age": 65, | ||
"verified": true | ||
}`), | ||
// bae-b769708d-f552-5c3d-a402-ccfd7ac7fb04 | ||
(`{ | ||
"name": "Cornelia Funke", | ||
"age": 62, | ||
"verified": false | ||
}`), | ||
}, | ||
}, | ||
Results: []map[string]interface{}{ | ||
{ | ||
"name": "John Grisham", | ||
"reviewed": []map[string]interface{}{ | ||
{ | ||
"name": "Theif Lord", | ||
"rating": 4.8, | ||
}, | ||
{ | ||
"name": "A Time for Mercy", | ||
"rating": 4.5, | ||
}, | ||
}, | ||
"written": []map[string]interface{}{ | ||
{ | ||
"name": "A Time for Mercy", | ||
}, | ||
{ | ||
"name": "Painted House", | ||
}, | ||
}, | ||
}, | ||
{ | ||
"name": "Cornelia Funke", | ||
"reviewed": []map[string]interface{}{ | ||
{ | ||
"name": "Painted House", | ||
"rating": 4.9, | ||
}, | ||
}, | ||
"written": []map[string]interface{}{ | ||
{ | ||
"name": "Theif Lord", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
executeTestCase(t, test) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters